Loading core/java/android/speech/tts/TextToSpeech.java +71 −49 Original line number Diff line number Diff line Loading @@ -285,6 +285,10 @@ public class TextToSpeech { * {@hide} */ 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. Loading Loading @@ -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; } /** Loading Loading @@ -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); Loading @@ -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(); } Loading Loading @@ -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) { Loading Loading @@ -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; Loading Loading @@ -1270,6 +1289,9 @@ public class TextToSpeech { } 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"); Loading packages/TtsService/src/android/tts/TtsService.java +12 −0 Original line number Diff line number Diff line Loading @@ -744,6 +744,7 @@ public class TtsService extends Service implements OnCompletionListener { String country = ""; String variant = ""; String speechRate = ""; String engine = ""; if (speechItem.mParams != null){ for (int i = 0; i < speechItem.mParams.size() - 1; i = i + 2){ String param = speechItem.mParams.get(i); Loading @@ -765,12 +766,17 @@ public class TtsService extends Service implements OnCompletionListener { } catch (NumberFormatException e) { streamType = DEFAULT_STREAM_TYPE; } } else if (param.equals(TextToSpeech.Engine.KEY_PARAM_ENGINE)) { engine = speechItem.mParams.get(i + 1); } } } } // Only do the synthesis if it has not been killed by a subsequent utterance. if (mKillList.get(speechItem) == null) { if (engine.length() > 0) { setEngine(engine); } if (language.length() > 0){ setLanguage("", language, country, variant); } Loading Loading @@ -825,6 +831,7 @@ public class TtsService extends Service implements OnCompletionListener { String country = ""; String variant = ""; String speechRate = ""; String engine = ""; if (speechItem.mParams != null){ for (int i = 0; i < speechItem.mParams.size() - 1; i = i + 2){ String param = speechItem.mParams.get(i); Loading @@ -839,12 +846,17 @@ public class TtsService extends Service implements OnCompletionListener { variant = speechItem.mParams.get(i+1); } else if (param.equals(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID)){ utteranceId = speechItem.mParams.get(i+1); } else if (param.equals(TextToSpeech.Engine.KEY_PARAM_ENGINE)) { engine = speechItem.mParams.get(i + 1); } } } } // Only do the synthesis if it has not been killed by a subsequent utterance. if (mKillList.get(speechItem) == null){ if (engine.length() > 0) { setEngine(engine); } if (language.length() > 0){ setLanguage("", language, country, variant); } Loading Loading
core/java/android/speech/tts/TextToSpeech.java +71 −49 Original line number Diff line number Diff line Loading @@ -285,6 +285,10 @@ public class TextToSpeech { * {@hide} */ 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. Loading Loading @@ -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; } /** Loading Loading @@ -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); Loading @@ -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(); } Loading Loading @@ -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) { Loading Loading @@ -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; Loading Loading @@ -1270,6 +1289,9 @@ public class TextToSpeech { } 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"); Loading
packages/TtsService/src/android/tts/TtsService.java +12 −0 Original line number Diff line number Diff line Loading @@ -744,6 +744,7 @@ public class TtsService extends Service implements OnCompletionListener { String country = ""; String variant = ""; String speechRate = ""; String engine = ""; if (speechItem.mParams != null){ for (int i = 0; i < speechItem.mParams.size() - 1; i = i + 2){ String param = speechItem.mParams.get(i); Loading @@ -765,12 +766,17 @@ public class TtsService extends Service implements OnCompletionListener { } catch (NumberFormatException e) { streamType = DEFAULT_STREAM_TYPE; } } else if (param.equals(TextToSpeech.Engine.KEY_PARAM_ENGINE)) { engine = speechItem.mParams.get(i + 1); } } } } // Only do the synthesis if it has not been killed by a subsequent utterance. if (mKillList.get(speechItem) == null) { if (engine.length() > 0) { setEngine(engine); } if (language.length() > 0){ setLanguage("", language, country, variant); } Loading Loading @@ -825,6 +831,7 @@ public class TtsService extends Service implements OnCompletionListener { String country = ""; String variant = ""; String speechRate = ""; String engine = ""; if (speechItem.mParams != null){ for (int i = 0; i < speechItem.mParams.size() - 1; i = i + 2){ String param = speechItem.mParams.get(i); Loading @@ -839,12 +846,17 @@ public class TtsService extends Service implements OnCompletionListener { variant = speechItem.mParams.get(i+1); } else if (param.equals(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID)){ utteranceId = speechItem.mParams.get(i+1); } else if (param.equals(TextToSpeech.Engine.KEY_PARAM_ENGINE)) { engine = speechItem.mParams.get(i + 1); } } } } // Only do the synthesis if it has not been killed by a subsequent utterance. if (mKillList.get(speechItem) == null){ if (engine.length() > 0) { setEngine(engine); } if (language.length() > 0){ setLanguage("", language, country, variant); } Loading