diff options
author | Android (Google) Code Review <android-gerrit@google.com> | 2009-07-21 10:23:06 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2009-07-21 10:23:06 -0700 |
commit | 305d9ba85d06316097bea0d150aa1b83db8bc593 (patch) | |
tree | 66361f546155ef9af56e76111a4332589da79e38 /packages | |
parent | f24239355f4f50e1385ff46e598466757a3f02ec (diff) | |
parent | 69a841a1649390d68b32b3bcf0c429a60c400cfa (diff) | |
download | frameworks_base-305d9ba85d06316097bea0d150aa1b83db8bc593.zip frameworks_base-305d9ba85d06316097bea0d150aa1b83db8bc593.tar.gz frameworks_base-305d9ba85d06316097bea0d150aa1b83db8bc593.tar.bz2 |
am 69a841a1: Merge change 8026 into donut
Merge commit '69a841a1649390d68b32b3bcf0c429a60c400cfa'
* commit '69a841a1649390d68b32b3bcf0c429a60c400cfa':
Make sure the speech synthesizer proxy is a singleton in the TTS service.
Diffstat (limited to 'packages')
-rwxr-xr-x | packages/TtsService/src/android/tts/TtsService.java | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/packages/TtsService/src/android/tts/TtsService.java b/packages/TtsService/src/android/tts/TtsService.java index 9a4c97d..cfefcb7 100755 --- a/packages/TtsService/src/android/tts/TtsService.java +++ b/packages/TtsService/src/android/tts/TtsService.java @@ -139,16 +139,18 @@ public class TtsService extends Service implements OnCompletionListener { private final ReentrantLock speechQueueLock = new ReentrantLock(); private final ReentrantLock synthesizerLock = new ReentrantLock(); - private SynthProxy nativeSynth; + private static SynthProxy sNativeSynth = null; @Override public void onCreate() { super.onCreate(); - Log.i("TTS", "TTS starting"); + Log.i("TtsService", "TtsService.onCreate()"); mResolver = getContentResolver(); String soLibPath = "/system/lib/libttspico.so"; - nativeSynth = new SynthProxy(soLibPath); + if (sNativeSynth == null) { + sNativeSynth = new SynthProxy(soLibPath); + } mSelf = this; mIsSpeaking = false; @@ -171,7 +173,7 @@ public class TtsService extends Service implements OnCompletionListener { // Don't hog the media player cleanUpPlayer(); - nativeSynth.shutdown(); + sNativeSynth.shutdown(); // Unregister all callbacks. mCallbacks.kill(); @@ -239,36 +241,36 @@ public class TtsService extends Service implements OnCompletionListener { private int setSpeechRate(String callingApp, int rate) { if (isDefaultEnforced()) { - return nativeSynth.setSpeechRate(getDefaultRate()); + return sNativeSynth.setSpeechRate(getDefaultRate()); } else { - return nativeSynth.setSpeechRate(rate); + return sNativeSynth.setSpeechRate(rate); } } private int setPitch(String callingApp, int pitch) { - return nativeSynth.setPitch(pitch); + return sNativeSynth.setPitch(pitch); } private int isLanguageAvailable(String lang, String country, String variant) { - //Log.v("TTS", "TtsService.isLanguageAvailable(" + lang + ", " + country + ", " +variant+")"); - return nativeSynth.isLanguageAvailable(lang, country, variant); + //Log.v("TtsService", "TtsService.isLanguageAvailable(" + lang + ", " + country + ", " +variant+")"); + return sNativeSynth.isLanguageAvailable(lang, country, variant); } private String[] getLanguage() { - return nativeSynth.getLanguage(); + return sNativeSynth.getLanguage(); } private int setLanguage(String callingApp, String lang, String country, String variant) { - //Log.v("TTS", "TtsService.setLanguage(" + lang + ", " + country + ", " + variant + ")"); + Log.v("TtsService", "TtsService.setLanguage(" + lang + ", " + country + ", " + variant + ")"); if (isDefaultEnforced()) { - return nativeSynth.setLanguage(getDefaultLanguage(), getDefaultCountry(), + return sNativeSynth.setLanguage(getDefaultLanguage(), getDefaultCountry(), getDefaultLocVariant()); } else { - return nativeSynth.setLanguage(lang, country, variant); + return sNativeSynth.setLanguage(lang, country, variant); } } @@ -340,7 +342,7 @@ public class TtsService extends Service implements OnCompletionListener { * engines. */ private int speak(String callingApp, String text, int queueMode, ArrayList<String> params) { - Log.i("TTS service received", text); + Log.v("TtsService", "TTS service received " + text); if (queueMode == TextToSpeech.TTS_QUEUE_FLUSH) { stop(callingApp); } else if (queueMode == 2) { @@ -390,7 +392,7 @@ public class TtsService extends Service implements OnCompletionListener { // something has gone very wrong with processSpeechQueue. speechQueueAvailable = speechQueueLock.tryLock(1000, TimeUnit.MILLISECONDS); if (speechQueueAvailable) { - Log.i("TTS", "Stopping"); + Log.i("TtsService", "Stopping"); for (int i = mSpeechQueue.size() - 1; i > -1; i--){ if (mSpeechQueue.get(i).mCallingApp.equals(callingApp)){ mSpeechQueue.remove(i); @@ -398,7 +400,7 @@ public class TtsService extends Service implements OnCompletionListener { } if ((mCurrentSpeechItem != null) && mCurrentSpeechItem.mCallingApp.equals(callingApp)) { - result = nativeSynth.stop(); + result = sNativeSynth.stop(); mKillList.put(mCurrentSpeechItem, true); if (mPlayer != null) { try { @@ -412,10 +414,10 @@ public class TtsService extends Service implements OnCompletionListener { } else { result = TextToSpeech.TTS_SUCCESS; } - Log.i("TTS", "Stopped"); + Log.i("TtsService", "Stopped"); } } catch (InterruptedException e) { - Log.e("TTS stop", "tryLock interrupted"); + Log.e("TtsService", "TTS stop: tryLock interrupted"); e.printStackTrace(); } finally { // This check is needed because finally will always run; even if the @@ -448,7 +450,7 @@ public class TtsService extends Service implements OnCompletionListener { if ((mCurrentSpeechItem != null) && ((mCurrentSpeechItem.mType != SpeechItem.TEXT_TO_FILE) || mCurrentSpeechItem.mCallingApp.equals(callingApp))) { - result = nativeSynth.stop(); + result = sNativeSynth.stop(); mKillList.put(mCurrentSpeechItem, true); if (mPlayer != null) { try { @@ -462,10 +464,10 @@ public class TtsService extends Service implements OnCompletionListener { } else { result = TextToSpeech.TTS_SUCCESS; } - Log.i("TTS", "Stopped all"); + Log.i("TtsService", "Stopped all"); } } catch (InterruptedException e) { - Log.e("TTS stopAll", "tryLock interrupted"); + Log.e("TtsService", "TTS stopAll: tryLock interrupted"); e.printStackTrace(); } finally { // This check is needed because finally will always run; even if the @@ -588,10 +590,10 @@ public class TtsService extends Service implements OnCompletionListener { if (speechRate.length() > 0){ setSpeechRate("", Integer.parseInt(speechRate)); } - nativeSynth.speak(speechItem.mText, streamType); + sNativeSynth.speak(speechItem.mText, streamType); } } catch (InterruptedException e) { - Log.e("TTS speakInternalOnly", "tryLock interrupted"); + Log.e("TtsService", "TTS speakInternalOnly(): tryLock interrupted"); e.printStackTrace(); } finally { // This check is needed because finally will always run; @@ -617,7 +619,7 @@ public class TtsService extends Service implements OnCompletionListener { public void run() { boolean synthAvailable = false; String utteranceId = ""; - Log.i("TTS", "Synthesizing to " + speechItem.mFilename); + Log.i("TtsService", "Synthesizing to " + speechItem.mFilename); try { synthAvailable = synthesizerLock.tryLock(); if (!synthAvailable) { @@ -657,10 +659,10 @@ public class TtsService extends Service implements OnCompletionListener { if (speechRate.length() > 0){ setSpeechRate("", Integer.parseInt(speechRate)); } - nativeSynth.synthesizeToFile(speechItem.mText, speechItem.mFilename); + sNativeSynth.synthesizeToFile(speechItem.mText, speechItem.mFilename); } } catch (InterruptedException e) { - Log.e("TTS synthToFileInternalOnly", "tryLock interrupted"); + Log.e("TtsService", "TTS synthToFileInternalOnly(): tryLock interrupted"); e.printStackTrace(); } finally { // This check is needed because finally will always run; @@ -705,7 +707,7 @@ public class TtsService extends Service implements OnCompletionListener { if (cb == null){ return; } - Log.i("TTS callback", "dispatch started"); + Log.i("TtsService", "TTS callback: dispatch started"); // Broadcast to all clients the new value. final int N = mCallbacks.beginBroadcast(); try { @@ -715,7 +717,7 @@ public class TtsService extends Service implements OnCompletionListener { // the dead object for us. } mCallbacks.finishBroadcast(); - Log.i("TTS callback", "dispatch completed to " + N); + Log.i("TtsService", "TTS callback: dispatch completed to " + N); } private SpeechItem splitCurrentTextIfNeeded(SpeechItem currentSpeechItem){ @@ -764,7 +766,7 @@ public class TtsService extends Service implements OnCompletionListener { SoundResource sr = getSoundResource(mCurrentSpeechItem); // Synth speech as needed - synthesizer should call // processSpeechQueue to continue running the queue - Log.i("TTS processing: ", mCurrentSpeechItem.mText); + Log.i("TtsService", "TTS processing: " + mCurrentSpeechItem.mText); if (sr == null) { if (mCurrentSpeechItem.mType == SpeechItem.TEXT) { mCurrentSpeechItem = splitCurrentTextIfNeeded(mCurrentSpeechItem); |