Loading packages/TtsService/src/android/tts/TtsService.java +42 −4 Original line number Diff line number Diff line Loading @@ -142,6 +142,8 @@ public class TtsService extends Service implements OnCompletionListener { private final ReentrantLock synthesizerLock = new ReentrantLock(); private static SynthProxy sNativeSynth = null; private static Boolean sIsKillingSynth = true; @Override public void onCreate() { super.onCreate(); Loading @@ -152,6 +154,7 @@ public class TtsService extends Service implements OnCompletionListener { String soLibPath = "/system/lib/libttspico.so"; if (sNativeSynth == null) { sNativeSynth = new SynthProxy(soLibPath); sIsKillingSynth = false; } mSelf = this; Loading @@ -172,6 +175,9 @@ public class TtsService extends Service implements OnCompletionListener { @Override public void onDestroy() { super.onDestroy(); sIsKillingSynth = true; Log.i("TtsService", "TtsService.onDestroy()"); // Don't hog the media player cleanUpPlayer(); Loading @@ -180,6 +186,7 @@ public class TtsService extends Service implements OnCompletionListener { // Unregister all callbacks. mCallbacks.kill(); //Log.i("TtsService", "TtsService.onDestroy() ended"); } Loading Loading @@ -243,6 +250,9 @@ public class TtsService extends Service implements OnCompletionListener { private int setSpeechRate(String callingApp, int rate) { if (sIsKillingSynth) { return TextToSpeech.ERROR; } if (isDefaultEnforced()) { return sNativeSynth.setSpeechRate(getDefaultRate()); } else { Loading @@ -252,23 +262,37 @@ public class TtsService extends Service implements OnCompletionListener { private int setPitch(String callingApp, int pitch) { if (sIsKillingSynth) { return TextToSpeech.ERROR; } return sNativeSynth.setPitch(pitch); } private int isLanguageAvailable(String lang, String country, String variant) { if (sIsKillingSynth) { return TextToSpeech.LANG_NOT_SUPPORTED; } //Log.v("TtsService", "TtsService.isLanguageAvailable(" + lang + ", " + country + ", " +variant+")"); return sNativeSynth.isLanguageAvailable(lang, country, variant); } private String[] getLanguage() { if (sIsKillingSynth) { Log.v("TtsService", "killing synth:: aborting getLanguage()"); return null; } return sNativeSynth.getLanguage(); } private int setLanguage(String callingApp, String lang, String country, String variant) { Log.v("TtsService", "TtsService.setLanguage(" + lang + ", " + country + ", " + variant + ")"); if (sIsKillingSynth) { Log.v("TtsService", "killing synth:: aborting setLanguage()"); return TextToSpeech.ERROR; } if (isDefaultEnforced()) { return sNativeSynth.setLanguage(getDefaultLanguage(), getDefaultCountry(), getDefaultLocVariant()); Loading Loading @@ -402,7 +426,12 @@ public class TtsService extends Service implements OnCompletionListener { } if ((mCurrentSpeechItem != null) && mCurrentSpeechItem.mCallingApp.equals(callingApp)) { if (sIsKillingSynth) { Log.v("TtsService", "killing synth:: aborting stop()"); result = TextToSpeech.ERROR; } else { result = sNativeSynth.stop(); } mKillList.put(mCurrentSpeechItem, true); if (mPlayer != null) { try { Loading Loading @@ -451,7 +480,12 @@ public class TtsService extends Service implements OnCompletionListener { if ((mCurrentSpeechItem != null) && ((mCurrentSpeechItem.mType != SpeechItem.TEXT_TO_FILE) || mCurrentSpeechItem.mCallingApp.equals(callingApp))) { if (sIsKillingSynth) { Log.v("TtsService", "killing synth:: aborting stop()"); result = TextToSpeech.ERROR; } else { result = sNativeSynth.stop(); } mKillList.put(mCurrentSpeechItem, true); if (mPlayer != null) { try { Loading Loading @@ -591,8 +625,10 @@ public class TtsService extends Service implements OnCompletionListener { if (speechRate.length() > 0){ setSpeechRate("", Integer.parseInt(speechRate)); } if (!sIsKillingSynth) { sNativeSynth.speak(speechItem.mText, streamType); } } } catch (InterruptedException e) { Log.e("TtsService", "TTS speakInternalOnly(): tryLock interrupted"); e.printStackTrace(); Loading Loading @@ -660,8 +696,10 @@ public class TtsService extends Service implements OnCompletionListener { if (speechRate.length() > 0){ setSpeechRate("", Integer.parseInt(speechRate)); } if (!sIsKillingSynth) { sNativeSynth.synthesizeToFile(speechItem.mText, speechItem.mFilename); } } } catch (InterruptedException e) { Log.e("TtsService", "TTS synthToFileInternalOnly(): tryLock interrupted"); e.printStackTrace(); Loading Loading
packages/TtsService/src/android/tts/TtsService.java +42 −4 Original line number Diff line number Diff line Loading @@ -142,6 +142,8 @@ public class TtsService extends Service implements OnCompletionListener { private final ReentrantLock synthesizerLock = new ReentrantLock(); private static SynthProxy sNativeSynth = null; private static Boolean sIsKillingSynth = true; @Override public void onCreate() { super.onCreate(); Loading @@ -152,6 +154,7 @@ public class TtsService extends Service implements OnCompletionListener { String soLibPath = "/system/lib/libttspico.so"; if (sNativeSynth == null) { sNativeSynth = new SynthProxy(soLibPath); sIsKillingSynth = false; } mSelf = this; Loading @@ -172,6 +175,9 @@ public class TtsService extends Service implements OnCompletionListener { @Override public void onDestroy() { super.onDestroy(); sIsKillingSynth = true; Log.i("TtsService", "TtsService.onDestroy()"); // Don't hog the media player cleanUpPlayer(); Loading @@ -180,6 +186,7 @@ public class TtsService extends Service implements OnCompletionListener { // Unregister all callbacks. mCallbacks.kill(); //Log.i("TtsService", "TtsService.onDestroy() ended"); } Loading Loading @@ -243,6 +250,9 @@ public class TtsService extends Service implements OnCompletionListener { private int setSpeechRate(String callingApp, int rate) { if (sIsKillingSynth) { return TextToSpeech.ERROR; } if (isDefaultEnforced()) { return sNativeSynth.setSpeechRate(getDefaultRate()); } else { Loading @@ -252,23 +262,37 @@ public class TtsService extends Service implements OnCompletionListener { private int setPitch(String callingApp, int pitch) { if (sIsKillingSynth) { return TextToSpeech.ERROR; } return sNativeSynth.setPitch(pitch); } private int isLanguageAvailable(String lang, String country, String variant) { if (sIsKillingSynth) { return TextToSpeech.LANG_NOT_SUPPORTED; } //Log.v("TtsService", "TtsService.isLanguageAvailable(" + lang + ", " + country + ", " +variant+")"); return sNativeSynth.isLanguageAvailable(lang, country, variant); } private String[] getLanguage() { if (sIsKillingSynth) { Log.v("TtsService", "killing synth:: aborting getLanguage()"); return null; } return sNativeSynth.getLanguage(); } private int setLanguage(String callingApp, String lang, String country, String variant) { Log.v("TtsService", "TtsService.setLanguage(" + lang + ", " + country + ", " + variant + ")"); if (sIsKillingSynth) { Log.v("TtsService", "killing synth:: aborting setLanguage()"); return TextToSpeech.ERROR; } if (isDefaultEnforced()) { return sNativeSynth.setLanguage(getDefaultLanguage(), getDefaultCountry(), getDefaultLocVariant()); Loading Loading @@ -402,7 +426,12 @@ public class TtsService extends Service implements OnCompletionListener { } if ((mCurrentSpeechItem != null) && mCurrentSpeechItem.mCallingApp.equals(callingApp)) { if (sIsKillingSynth) { Log.v("TtsService", "killing synth:: aborting stop()"); result = TextToSpeech.ERROR; } else { result = sNativeSynth.stop(); } mKillList.put(mCurrentSpeechItem, true); if (mPlayer != null) { try { Loading Loading @@ -451,7 +480,12 @@ public class TtsService extends Service implements OnCompletionListener { if ((mCurrentSpeechItem != null) && ((mCurrentSpeechItem.mType != SpeechItem.TEXT_TO_FILE) || mCurrentSpeechItem.mCallingApp.equals(callingApp))) { if (sIsKillingSynth) { Log.v("TtsService", "killing synth:: aborting stop()"); result = TextToSpeech.ERROR; } else { result = sNativeSynth.stop(); } mKillList.put(mCurrentSpeechItem, true); if (mPlayer != null) { try { Loading Loading @@ -591,8 +625,10 @@ public class TtsService extends Service implements OnCompletionListener { if (speechRate.length() > 0){ setSpeechRate("", Integer.parseInt(speechRate)); } if (!sIsKillingSynth) { sNativeSynth.speak(speechItem.mText, streamType); } } } catch (InterruptedException e) { Log.e("TtsService", "TTS speakInternalOnly(): tryLock interrupted"); e.printStackTrace(); Loading Loading @@ -660,8 +696,10 @@ public class TtsService extends Service implements OnCompletionListener { if (speechRate.length() > 0){ setSpeechRate("", Integer.parseInt(speechRate)); } if (!sIsKillingSynth) { sNativeSynth.synthesizeToFile(speechItem.mText, speechItem.mFilename); } } } catch (InterruptedException e) { Log.e("TtsService", "TTS synthToFileInternalOnly(): tryLock interrupted"); e.printStackTrace(); Loading