diff options
author | Jack Yu <jackyu@google.com> | 2015-10-16 21:19:52 -0700 |
---|---|---|
committer | Jack Yu <jackyu@google.com> | 2015-10-16 21:19:52 -0700 |
commit | 3d91c54e6649ec46ddd728079702aba2f0ae96b8 (patch) | |
tree | 29c62de1a663696ed2b302ddaa6641dd78ce7546 | |
parent | 170b39b30ef6340a99fde0e1e6a46cf935e4cde6 (diff) | |
download | CellBroadcastReceiver-3d91c54e6649ec46ddd728079702aba2f0ae96b8.tar.gz |
DO NOT MERGE. Fixed emergency alert TTS not playing on bluetooth speaker.android-6.0.1_r9android-6.0.1_r81android-6.0.1_r80android-6.0.1_r8android-6.0.1_r79android-6.0.1_r78android-6.0.1_r77android-6.0.1_r74android-6.0.1_r73android-6.0.1_r72android-6.0.1_r70android-6.0.1_r7android-6.0.1_r69android-6.0.1_r66android-6.0.1_r65android-6.0.1_r61android-6.0.1_r60android-6.0.1_r59android-6.0.1_r58android-6.0.1_r57android-6.0.1_r56android-6.0.1_r52android-6.0.1_r51android-6.0.1_r50android-6.0.1_r49android-6.0.1_r48android-6.0.1_r47android-6.0.1_r46android-6.0.1_r43android-6.0.1_r42android-6.0.1_r41android-6.0.1_r40android-6.0.1_r30android-6.0.1_r3android-6.0.1_r28android-6.0.1_r27android-6.0.1_r26android-6.0.1_r20android-6.0.1_r17android-6.0.1_r13android-6.0.1_r12android-6.0.1_r11android-6.0.1_r10android-6.0.1_r1android-6.0.0_r41marshmallow-mr3-releasemarshmallow-mr2-releasemarshmallow-mr1-releasemarshmallow-mr1-dev
Added an extra param so TTS engine knows where to route the audio.
Also release the audio focus at the time after tone + TTS are played,
not just tone so TTS won't mix with other audio stream (e.g. music)
bug: 24366038
Change-Id: I8f045f9264ea49d00125a53f3180c9924b02b08c
-rw-r--r-- | src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java index 6a70079ca..2381689f6 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java @@ -122,6 +122,9 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI PAUSE_DURATION_BEFORE_SPEAKING_MSEC); mState = STATE_PAUSING; } else { + if (DBG) log("MessageEmpty = " + (mMessageBody == null) + + ", mTtsEngineReady = " + mTtsEngineReady + + ", mTtsLanguageSupported = " + mTtsLanguageSupported); stopSelf(); mState = STATE_IDLE; } @@ -135,6 +138,10 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI HashMap<String, String> ttsHashMap = new HashMap<String, String>(); ttsHashMap.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, TTS_UTTERANCE_ID); + // Play TTS on notification stream. + ttsHashMap.put(TextToSpeech.Engine.KEY_PARAM_STREAM, + Integer.toString(AudioManager.STREAM_NOTIFICATION)); + res = mTts.speak(mMessageBody, TextToSpeech.QUEUE_FLUSH, ttsHashMap); mState = STATE_SPEAKING; } @@ -206,7 +213,11 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI @Override public void onUtteranceCompleted(String utteranceId) { if (utteranceId.equals(TTS_UTTERANCE_ID)) { - stopSelf(); + // When we reach here, it could be TTS completed or TTS was cut due to another + // new alert started playing. We don't want to stop the service in the later case. + if (mState == STATE_SPEAKING) { + stopSelf(); + } } } @@ -236,6 +247,14 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI loge("exception trying to shutdown text-to-speech"); } } + + if (mEnableAudio) { + // Release the audio focus so other audio (e.g. music) can resume. + // Do not do this in stop() because stop() is also called when we stop the tone (before + // TTS is playing). We only want to release the focus when tone and TTS are played. + mAudioManager.abandonAudioFocus(null); + } + // release CPU wake lock acquired by CellBroadcastAlertService CellBroadcastAlertWakeLock.releaseCpuLock(); } @@ -435,7 +454,7 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI loge("exception trying to stop text-to-speech"); } } - mAudioManager.abandonAudioFocus(null); + mState = STATE_IDLE; } |