From 1a2712ce2a18eba6809d984d2f7443fbdccaa7ed Mon Sep 17 00:00:00 2001 From: Charles Chen Date: Thu, 1 Apr 2010 17:16:28 -0700 Subject: Fix for bug 2564771 - pitch setting between apps can interfere with one another. Root cause was not caching all the params that were needed. This change fixes that bug as well as related bugs for remembering the default engine and for making sure that the right engine is loaded when checking for language availability. Change-Id: I2a76da8faec8112036e68d27539db444c53a1509 --- .../TtsService/src/android/tts/TtsService.java | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/TtsService/src/android/tts/TtsService.java b/packages/TtsService/src/android/tts/TtsService.java index 530ca57..c977ba3 100755 --- a/packages/TtsService/src/android/tts/TtsService.java +++ b/packages/TtsService/src/android/tts/TtsService.java @@ -321,6 +321,10 @@ public class TtsService extends Service implements OnCompletionListener { TextToSpeech.Engine.DEFAULT_RATE); } + private int getDefaultPitch() { + // Pitch is not user settable; the default pitch is always 100. + return 100; + } private String getDefaultLanguage() { String defaultLang = android.provider.Settings.Secure.getString(mResolver, @@ -786,6 +790,7 @@ public class TtsService extends Service implements OnCompletionListener { String variant = ""; String speechRate = ""; String engine = ""; + String pitch = ""; if (speechItem.mParams != null){ for (int i = 0; i < speechItem.mParams.size() - 1; i = i + 2){ String param = speechItem.mParams.get(i); @@ -809,6 +814,8 @@ public class TtsService extends Service implements OnCompletionListener { } } else if (param.equals(TextToSpeech.Engine.KEY_PARAM_ENGINE)) { engine = speechItem.mParams.get(i + 1); + } else if (param.equals(TextToSpeech.Engine.KEY_PARAM_PITCH)) { + pitch = speechItem.mParams.get(i + 1); } } } @@ -831,6 +838,11 @@ public class TtsService extends Service implements OnCompletionListener { } else { setSpeechRate("", getDefaultRate()); } + if (pitch.length() > 0){ + setPitch("", Integer.parseInt(pitch)); + } else { + setPitch("", getDefaultPitch()); + } try { sNativeSynth.speak(speechItem.mText, streamType); } catch (NullPointerException e) { @@ -885,6 +897,7 @@ public class TtsService extends Service implements OnCompletionListener { String variant = ""; String speechRate = ""; String engine = ""; + String pitch = ""; if (speechItem.mParams != null){ for (int i = 0; i < speechItem.mParams.size() - 1; i = i + 2){ String param = speechItem.mParams.get(i); @@ -901,6 +914,8 @@ public class TtsService extends Service implements OnCompletionListener { utteranceId = speechItem.mParams.get(i+1); } else if (param.equals(TextToSpeech.Engine.KEY_PARAM_ENGINE)) { engine = speechItem.mParams.get(i + 1); + } else if (param.equals(TextToSpeech.Engine.KEY_PARAM_PITCH)) { + pitch = speechItem.mParams.get(i + 1); } } } @@ -923,6 +938,11 @@ public class TtsService extends Service implements OnCompletionListener { } else { setSpeechRate("", getDefaultRate()); } + if (pitch.length() > 0){ + setPitch("", Integer.parseInt(pitch)); + } else { + setPitch("", getDefaultPitch()); + } try { sNativeSynth.synthesizeToFile(speechItem.mText, speechItem.mFilename); } catch (NullPointerException e) { @@ -1377,7 +1397,17 @@ public class TtsService extends Service implements OnCompletionListener { * TTS_LANG_COUNTRY_AVAILABLE, TTS_LANG_COUNTRY_VAR_AVAILABLE as defined in * android.speech.tts.TextToSpeech. */ - public int isLanguageAvailable(String lang, String country, String variant) { + public int isLanguageAvailable(String lang, String country, String variant, + String[] params) { + for (int i = 0; i < params.length - 1; i = i + 2){ + String param = params[i]; + if (param != null) { + if (param.equals(TextToSpeech.Engine.KEY_PARAM_ENGINE)) { + mSelf.setEngine(params[i + 1]); + break; + } + } + } return mSelf.isLanguageAvailable(lang, country, variant); } -- cgit v1.1