when the phone is in silent mode the UI should not use the TTS

This commit is contained in:
kr.angelov
2013-10-31 13:38:39 +00:00
parent bd7b9b0168
commit f4aac34cf8

View File

@@ -1,6 +1,7 @@
package org.grammaticalframework.ui.android; package org.grammaticalframework.ui.android;
import android.content.Context; import android.content.Context;
import android.media.AudioManager;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
import android.util.Log; import android.util.Log;
@@ -12,9 +13,11 @@ public class TTS {
private static final String TAG = "TTS"; private static final String TAG = "TTS";
private TextToSpeech mTts; private TextToSpeech mTts;
private AudioManager mAudioManager;
public TTS(Context context) { public TTS(Context context) {
mTts = new TextToSpeech(context, new InitListener()); mTts = new TextToSpeech(context, new InitListener());
mAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
} }
public void setLanguage(String language) { public void setLanguage(String language) {
@@ -33,13 +36,16 @@ public class TTS {
// TODO: handle speak() calls before service connects // TODO: handle speak() calls before service connects
public void speak(String text) { public void speak(String text) {
HashMap<String,String> params = new HashMap<String,String>(); int mode = mAudioManager.getRingerMode();
// TODO: how can I get network / embedded fallback? if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
// Using both crashes the TTS engine if the offline data is not installed HashMap<String,String> params = new HashMap<String,String>();
// Using only one doesn't allow the other // TODO: how can I get network / embedded fallback?
// params.put(TextToSpeech.Engine.KEY_FEATURE_NETWORK_SYNTHESIS, "true"); // Using both crashes the TTS engine if the offline data is not installed
// params.put(TextToSpeech.Engine.KEY_FEATURE_EMBEDDED_SYNTHESIS, "true"); // Using only one doesn't allow the other
mTts.speak(text, TextToSpeech.QUEUE_FLUSH, params); // params.put(TextToSpeech.Engine.KEY_FEATURE_NETWORK_SYNTHESIS, "true");
// params.put(TextToSpeech.Engine.KEY_FEATURE_EMBEDDED_SYNTHESIS, "true");
mTts.speak(text, TextToSpeech.QUEUE_FLUSH, params);
}
} }
public void destroy() { public void destroy() {