diff options
| author | 2009-07-16 17:54:13 -0700 | |
|---|---|---|
| committer | 2009-07-16 17:54:13 -0700 | |
| commit | db9acb74ab0f1ea8aa2156527aead496ad9a0141 (patch) | |
| tree | 5706501447d30e414b2927f769c7905977d2ec17 | |
| parent | fff0fd748c412324b891913a84036e373d345175 (diff) | |
| parent | 65d99c3cbf149776c7ec4ea1f3cb1f4470d2be83 (diff) | |
am 65d99c3c: Merge change 7537 into donut
Merge commit '65d99c3cbf149776c7ec4ea1f3cb1f4470d2be83'
* commit '65d99c3cbf149776c7ec4ea1f3cb1f4470d2be83':
Fixing a race condition that causes synthesis to not be aborted
| -rwxr-xr-x | packages/TtsService/src/android/tts/TtsService.java | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/packages/TtsService/src/android/tts/TtsService.java b/packages/TtsService/src/android/tts/TtsService.java index 7c4996e6b2f9..b3b580c55e4a 100755 --- a/packages/TtsService/src/android/tts/TtsService.java +++ b/packages/TtsService/src/android/tts/TtsService.java @@ -130,6 +130,8 @@ public class TtsService extends Service implements OnCompletionListener { private HashMap<String, SoundResource> mUtterances; private MediaPlayer mPlayer; private SpeechItem mCurrentSpeechItem; + private HashMap<SpeechItem, Boolean> mKillList; // Used to ensure that in-flight synth calls + // are killed when stop is used. private TtsService mSelf; private ContentResolver mResolver; @@ -158,6 +160,7 @@ public class TtsService extends Service implements OnCompletionListener { mSpeechQueue = new ArrayList<SpeechItem>(); mPlayer = null; mCurrentSpeechItem = null; + mKillList = new HashMap<SpeechItem, Boolean>(); setDefaultSettings(); } @@ -396,6 +399,7 @@ public class TtsService extends Service implements OnCompletionListener { if ((mCurrentSpeechItem != null) && mCurrentSpeechItem.mCallingApp.equals(callingApp)) { result = nativeSynth.stop(); + mKillList.put(mCurrentSpeechItem, true); if (mPlayer != null) { try { mPlayer.stop(); @@ -445,6 +449,7 @@ public class TtsService extends Service implements OnCompletionListener { ((mCurrentSpeechItem.mType != SpeechItem.TEXT_TO_FILE) || mCurrentSpeechItem.mCallingApp.equals(callingApp))) { result = nativeSynth.stop(); + mKillList.put(mCurrentSpeechItem, true); if (mPlayer != null) { try { mPlayer.stop(); @@ -578,7 +583,10 @@ public class TtsService extends Service implements OnCompletionListener { setLanguage("", language, country, variant); } } - nativeSynth.speak(speechItem.mText, streamType); + // Only do the synthesis if it has not been killed by a subsequent utterance. + if (mKillList.get(speechItem) == null){ + nativeSynth.speak(speechItem.mText, streamType); + } } catch (InterruptedException e) { Log.e("TTS speakInternalOnly", "tryLock interrupted"); e.printStackTrace(); @@ -641,7 +649,10 @@ public class TtsService extends Service implements OnCompletionListener { setLanguage("", language, country, variant); } } - nativeSynth.synthesizeToFile(speechItem.mText, speechItem.mFilename); + // Only do the synthesis if it has not been killed by a subsequent utterance. + if (mKillList.get(speechItem) == null){ + nativeSynth.synthesizeToFile(speechItem.mText, speechItem.mFilename); + } } catch (InterruptedException e) { Log.e("TTS synthToFileInternalOnly", "tryLock interrupted"); e.printStackTrace(); |