diff options
author | Charles Chen <clchen@google.com> | 2010-04-01 17:56:47 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-04-01 17:56:47 -0700 |
commit | ddc2eb8ee3c422b9f57bf55c50a76c7afb4ced76 (patch) | |
tree | a70e793f8270ca68d86356296a88823b3c6cfe87 /core/java/android | |
parent | e11bafec8d6c887c6ae95fa3d39c202859e86d48 (diff) | |
parent | 1a2712ce2a18eba6809d984d2f7443fbdccaa7ed (diff) | |
download | frameworks_base-ddc2eb8ee3c422b9f57bf55c50a76c7afb4ced76.zip frameworks_base-ddc2eb8ee3c422b9f57bf55c50a76c7afb4ced76.tar.gz frameworks_base-ddc2eb8ee3c422b9f57bf55c50a76c7afb4ced76.tar.bz2 |
Merge "Fix for bug 2564771 - pitch setting between apps can interfere with one another." into froyo
Diffstat (limited to 'core/java/android')
-rwxr-xr-x | core/java/android/speech/tts/ITts.aidl | 2 | ||||
-rwxr-xr-x | core/java/android/speech/tts/TextToSpeech.java | 80 |
2 files changed, 56 insertions, 26 deletions
diff --git a/core/java/android/speech/tts/ITts.aidl b/core/java/android/speech/tts/ITts.aidl index 2fd3672..c1051c4 100755 --- a/core/java/android/speech/tts/ITts.aidl +++ b/core/java/android/speech/tts/ITts.aidl @@ -43,7 +43,7 @@ interface ITts { String[] getLanguage();
- int isLanguageAvailable(in String language, in String country, in String variant);
+ int isLanguageAvailable(in String language, in String country, in String variant, in String[] params);
int setLanguage(in String callingApp, in String language, in String country, in String variant);
diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java index eeb42c42..e7c6432 100755 --- a/core/java/android/speech/tts/TextToSpeech.java +++ b/core/java/android/speech/tts/TextToSpeech.java @@ -315,6 +315,10 @@ public class TextToSpeech { */ public static final String KEY_PARAM_ENGINE = "engine"; /** + * {@hide} + */ + public static final String KEY_PARAM_PITCH = "pitch"; + /** * Parameter key to specify the audio stream type to be used when speaking text * or playing back a file. * @see TextToSpeech#speak(String, int, HashMap) @@ -365,7 +369,12 @@ public class TextToSpeech { /** * {@hide} */ - protected static final int NB_CACHED_PARAMS = 7; + protected static final int PARAM_POSITION_PITCH = 14; + + /** + * {@hide} + */ + protected static final int NB_CACHED_PARAMS = 8; } /** @@ -409,9 +418,10 @@ public class TextToSpeech { mCachedParams[Engine.PARAM_POSITION_STREAM] = Engine.KEY_PARAM_STREAM; mCachedParams[Engine.PARAM_POSITION_UTTERANCE_ID] = Engine.KEY_PARAM_UTTERANCE_ID; mCachedParams[Engine.PARAM_POSITION_ENGINE] = Engine.KEY_PARAM_ENGINE; + mCachedParams[Engine.PARAM_POSITION_PITCH] = Engine.KEY_PARAM_PITCH; - // Leave all defaults that are shown in Settings uninitialized so that - // the values set in Settings will take effect if the application does + // Leave all defaults that are shown in Settings uninitialized/at the default + // so that the values set in Settings will take effect if the application does // not try to change these settings itself. mCachedParams[Engine.PARAM_POSITION_RATE + 1] = ""; mCachedParams[Engine.PARAM_POSITION_LANGUAGE + 1] = ""; @@ -421,6 +431,7 @@ public class TextToSpeech { String.valueOf(Engine.DEFAULT_STREAM); mCachedParams[Engine.PARAM_POSITION_UTTERANCE_ID + 1] = ""; mCachedParams[Engine.PARAM_POSITION_ENGINE + 1] = ""; + mCachedParams[Engine.PARAM_POSITION_PITCH + 1] = "100"; initTts(); } @@ -435,6 +446,9 @@ public class TextToSpeech { synchronized(mStartLock) { mITts = ITts.Stub.asInterface(service); mStarted = true; + // Cache the default engine and current language + setEngineByPackageName(getDefaultEngine()); + setLanguage(getLanguage()); if (mInitListener != null) { // TODO manage failures and missing resources mInitListener.onInit(SUCCESS); @@ -1008,15 +1022,13 @@ public class TextToSpeech { return result; } try { + // the pitch is not set here, instead it is cached so it will be associated + // with all upcoming utterances. if (pitch > 0) { - result = mITts.setPitch(mPackageName, (int)(pitch*100)); + int p = (int)(pitch*100); + mCachedParams[Engine.PARAM_POSITION_PITCH + 1] = String.valueOf(p); + result = SUCCESS; } - } catch (RemoteException e) { - // TTS died; restart it. - Log.e("TextToSpeech.java - setPitch", "RemoteException"); - e.printStackTrace(); - mStarted = false; - initTts(); } catch (NullPointerException e) { // TTS died; restart it. Log.e("TextToSpeech.java - setPitch", "NullPointerException"); @@ -1057,16 +1069,27 @@ public class TextToSpeech { return result; } try { - mCachedParams[Engine.PARAM_POSITION_LANGUAGE + 1] = loc.getISO3Language(); - mCachedParams[Engine.PARAM_POSITION_COUNTRY + 1] = loc.getISO3Country(); - mCachedParams[Engine.PARAM_POSITION_VARIANT + 1] = loc.getVariant(); - // the language is not set here, instead it is cached so it will be associated - // with all upcoming utterances. But we still need to report the language support, - // which is achieved by calling isLanguageAvailable() - result = mITts.isLanguageAvailable( - mCachedParams[Engine.PARAM_POSITION_LANGUAGE + 1], - mCachedParams[Engine.PARAM_POSITION_COUNTRY + 1], - mCachedParams[Engine.PARAM_POSITION_VARIANT + 1] ); + String language = loc.getISO3Language(); + String country = loc.getISO3Country(); + String variant = loc.getVariant(); + // Check if the language, country, variant are available, and cache + // the available parts. + // Note that the language is not actually set here, instead it is cached so it + // will be associated with all upcoming utterances. + result = mITts.isLanguageAvailable(language, country, variant, mCachedParams); + if (result >= LANG_AVAILABLE){ + mCachedParams[Engine.PARAM_POSITION_LANGUAGE + 1] = language; + if (result >= LANG_COUNTRY_AVAILABLE){ + mCachedParams[Engine.PARAM_POSITION_COUNTRY + 1] = country; + } else { + mCachedParams[Engine.PARAM_POSITION_COUNTRY + 1] = ""; + } + if (result >= LANG_COUNTRY_VAR_AVAILABLE){ + mCachedParams[Engine.PARAM_POSITION_VARIANT + 1] = variant; + } else { + mCachedParams[Engine.PARAM_POSITION_VARIANT + 1] = ""; + } + } } catch (RemoteException e) { // TTS died; restart it. Log.e("TextToSpeech.java - setLanguage", "RemoteException"); @@ -1104,11 +1127,18 @@ public class TextToSpeech { return null; } try { - String[] locStrings = mITts.getLanguage(); - if ((locStrings != null) && (locStrings.length == 3)) { - return new Locale(locStrings[0], locStrings[1], locStrings[2]); + // Only do a call to the native synth if there is nothing in the cached params + if (mCachedParams[Engine.PARAM_POSITION_LANGUAGE + 1].length() < 1){ + String[] locStrings = mITts.getLanguage(); + if ((locStrings != null) && (locStrings.length == 3)) { + return new Locale(locStrings[0], locStrings[1], locStrings[2]); + } else { + return null; + } } else { - return null; + return new Locale(mCachedParams[Engine.PARAM_POSITION_LANGUAGE + 1], + mCachedParams[Engine.PARAM_POSITION_COUNTRY + 1], + mCachedParams[Engine.PARAM_POSITION_VARIANT + 1]); } } catch (RemoteException e) { // TTS died; restart it. @@ -1151,7 +1181,7 @@ public class TextToSpeech { } try { result = mITts.isLanguageAvailable(loc.getISO3Language(), - loc.getISO3Country(), loc.getVariant()); + loc.getISO3Country(), loc.getVariant(), mCachedParams); } catch (RemoteException e) { // TTS died; restart it. Log.e("TextToSpeech.java - isLanguageAvailable", "RemoteException"); |