diff options
author | Charles Chen <clchen@google.com> | 2010-01-07 18:56:24 -0800 |
---|---|---|
committer | Charles Chen <clchen@google.com> | 2010-01-08 15:06:57 -0800 |
commit | 60dd360640a400d9b4a602160733281d284aaee5 (patch) | |
tree | 97ebd5699d2f324fc8215c6714ddd3e5e6771997 /core/java/android/speech | |
parent | 6414970ac7dc629345942059f75362d894c2310e (diff) | |
download | frameworks_base-60dd360640a400d9b4a602160733281d284aaee5.zip frameworks_base-60dd360640a400d9b4a602160733281d284aaee5.tar.gz frameworks_base-60dd360640a400d9b4a602160733281d284aaee5.tar.bz2 |
Enabling multiple apps to use different speech synthesis engines and not
interfere with one another.
Diffstat (limited to 'core/java/android/speech')
-rwxr-xr-x | core/java/android/speech/tts/TextToSpeech.java | 120 |
1 files changed, 71 insertions, 49 deletions
diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java index bd19f9e..bbbeb3f 100755 --- a/core/java/android/speech/tts/TextToSpeech.java +++ b/core/java/android/speech/tts/TextToSpeech.java @@ -129,8 +129,8 @@ public class TextToSpeech { * {@link TextToSpeech#synthesizeToFile(String, HashMap, String)} with the * {@link TextToSpeech.Engine#KEY_PARAM_UTTERANCE_ID} key. * @param utteranceId the identifier of the utterance. - */
- public void onUtteranceCompleted(String utteranceId);
+ */ + public void onUtteranceCompleted(String utteranceId); } @@ -286,6 +286,10 @@ public class TextToSpeech { */ public static final String KEY_PARAM_VARIANT = "variant"; /** + * {@hide} + */ + public static final String KEY_PARAM_ENGINE = "engine"; + /** * 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) @@ -327,10 +331,16 @@ public class TextToSpeech { * {@hide} */ protected static final int PARAM_POSITION_UTTERANCE_ID = 10; + + /** + * {@hide} + */ + protected static final int PARAM_POSITION_ENGINE = 12; + /** * {@hide} */ - protected static final int NB_CACHED_PARAMS = 6; + protected static final int NB_CACHED_PARAMS = 7; } /** @@ -373,6 +383,7 @@ public class TextToSpeech { mCachedParams[Engine.PARAM_POSITION_VARIANT] = Engine.KEY_PARAM_VARIANT; 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_RATE + 1] = String.valueOf(Engine.DEFAULT_RATE); @@ -381,10 +392,10 @@ public class TextToSpeech { mCachedParams[Engine.PARAM_POSITION_LANGUAGE + 1] = defaultLoc.getISO3Language(); mCachedParams[Engine.PARAM_POSITION_COUNTRY + 1] = defaultLoc.getISO3Country(); mCachedParams[Engine.PARAM_POSITION_VARIANT + 1] = defaultLoc.getVariant(); - mCachedParams[Engine.PARAM_POSITION_STREAM + 1] = String.valueOf(Engine.DEFAULT_STREAM); mCachedParams[Engine.PARAM_POSITION_UTTERANCE_ID + 1] = ""; + mCachedParams[Engine.PARAM_POSITION_ENGINE + 1] = Engine.DEFAULT_SYNTH; initTts(); } @@ -684,6 +695,10 @@ public class TextToSpeech { if (extra != null) { mCachedParams[Engine.PARAM_POSITION_UTTERANCE_ID + 1] = extra; } + extra = params.get(Engine.KEY_PARAM_ENGINE); + if (extra != null) { + mCachedParams[Engine.PARAM_POSITION_ENGINE + 1] = extra; + } } result = mITts.speak(mPackageName, text, queueMode, mCachedParams); } catch (RemoteException e) { @@ -819,7 +834,7 @@ public class TextToSpeech { mStarted = false; initTts(); } finally { - return result; + return result; } } } @@ -894,7 +909,7 @@ public class TextToSpeech { mStarted = false; initTts(); } finally { - return result; + return result; } } } @@ -943,7 +958,7 @@ public class TextToSpeech { mStarted = false; initTts(); } finally { - return result; + return result; } } } @@ -990,7 +1005,7 @@ public class TextToSpeech { mStarted = false; initTts(); } finally { - return result; + return result; } } } @@ -1046,7 +1061,7 @@ public class TextToSpeech { mStarted = false; initTts(); } finally { - return result; + return result; } } } @@ -1064,7 +1079,7 @@ public class TextToSpeech { return null; } try { - String[] locStrings = mITts.getLanguage(); + String[] locStrings = mITts.getLanguage(); if ((locStrings != null) && (locStrings.length == 3)) { return new Locale(locStrings[0], locStrings[1], locStrings[2]); } else { @@ -1131,7 +1146,7 @@ public class TextToSpeech { mStarted = false; initTts(); } finally { - return result; + return result; } } } @@ -1166,6 +1181,10 @@ public class TextToSpeech { if (extra != null) { mCachedParams[Engine.PARAM_POSITION_UTTERANCE_ID + 1] = extra; } + extra = params.get(Engine.KEY_PARAM_ENGINE); + if (extra != null) { + mCachedParams[Engine.PARAM_POSITION_ENGINE + 1] = extra; + } } if (mITts.synthesizeToFile(mPackageName, text, mCachedParams, filename)){ result = SUCCESS; @@ -1214,19 +1233,19 @@ public class TextToSpeech { * * @return Code indicating success or failure. See {@link #ERROR} and {@link #SUCCESS}. */ - public int setOnUtteranceCompletedListener(
- final OnUtteranceCompletedListener listener) {
+ public int setOnUtteranceCompletedListener( + final OnUtteranceCompletedListener listener) { synchronized (mStartLock) { int result = ERROR; if (!mStarted) { return result; } mITtscallback = new ITtsCallback.Stub() { - public void utteranceCompleted(String utteranceId) throws RemoteException {
- if (listener != null) {
- listener.onUtteranceCompleted(utteranceId);
- }
- }
+ public void utteranceCompleted(String utteranceId) throws RemoteException { + if (listener != null) { + listener.onUtteranceCompleted(utteranceId); + } + } }; try { result = mITts.registerCallback(mPackageName, mITtscallback); @@ -1251,7 +1270,7 @@ public class TextToSpeech { } finally { return result; } - }
+ } } /** @@ -1262,36 +1281,39 @@ public class TextToSpeech { * * @return Code indicating success or failure. See {@link #ERROR} and {@link #SUCCESS}. */ - public int setEngineByPackageName(String enginePackageName) {
- synchronized (mStartLock) {
- int result = TextToSpeech.ERROR;
- if (!mStarted) {
- return result;
- }
- try {
- result = mITts.setEngineByPackageName(enginePackageName);
- } catch (RemoteException e) {
- // TTS died; restart it.
- Log.e("TextToSpeech.java - setEngineByPackageName", "RemoteException");
- e.printStackTrace();
- mStarted = false;
- initTts();
- } catch (NullPointerException e) {
- // TTS died; restart it.
- Log.e("TextToSpeech.java - setEngineByPackageName", "NullPointerException");
- e.printStackTrace();
- mStarted = false;
- initTts();
- } catch (IllegalStateException e) {
- // TTS died; restart it.
- Log.e("TextToSpeech.java - setEngineByPackageName", "IllegalStateException");
- e.printStackTrace();
- mStarted = false;
- initTts();
- } finally {
- return result;
- }
- }
+ public int setEngineByPackageName(String enginePackageName) { + synchronized (mStartLock) { + int result = TextToSpeech.ERROR; + if (!mStarted) { + return result; + } + try { + result = mITts.setEngineByPackageName(enginePackageName); + if (result == TextToSpeech.SUCCESS){ + mCachedParams[Engine.PARAM_POSITION_ENGINE + 1] = enginePackageName; + } + } catch (RemoteException e) { + // TTS died; restart it. + Log.e("TextToSpeech.java - setEngineByPackageName", "RemoteException"); + e.printStackTrace(); + mStarted = false; + initTts(); + } catch (NullPointerException e) { + // TTS died; restart it. + Log.e("TextToSpeech.java - setEngineByPackageName", "NullPointerException"); + e.printStackTrace(); + mStarted = false; + initTts(); + } catch (IllegalStateException e) { + // TTS died; restart it. + Log.e("TextToSpeech.java - setEngineByPackageName", "IllegalStateException"); + e.printStackTrace(); + mStarted = false; + initTts(); + } finally { + return result; + } + } } } |