1
0
forked from GitHub/gf-core

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