1
0
forked from GitHub/gf-core

now the TTS is used only if there is actually a language model. this is better than using English for speaking Swedish

This commit is contained in:
kr.angelov
2013-11-28 19:59:03 +00:00
parent 2bc2dc750f
commit 123d2098dd
2 changed files with 13 additions and 23 deletions

View File

@@ -20,30 +20,20 @@ public class TTS {
mAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); mAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
} }
public void setLanguage(String language) {
Locale locale = LocaleUtils.parseJavaLocale(language.replace('-', '_'),
Locale.getDefault());
int result = mTts.setLanguage(locale);
if (result == TextToSpeech.LANG_MISSING_DATA ||
result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e(TAG, "Language is not available");
} else {
// TODO: the language may be available for the locale,
// but not for the specified country and variant.
}
}
// TODO: handle speak() calls before service connects // TODO: handle speak() calls before service connects
public void speak(String text) { public void speak(String language, String text) {
if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) { if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
HashMap<String,String> params = new HashMap<String,String>(); Locale locale = LocaleUtils.parseJavaLocale(language.replace('-', '_'),
// TODO: how can I get network / embedded fallback? Locale.getDefault());
// Using both crashes the TTS engine if the offline data is not installed
// Using only one doesn't allow the other int result = mTts.setLanguage(locale);
// params.put(TextToSpeech.Engine.KEY_FEATURE_NETWORK_SYNTHESIS, "true"); if (result == TextToSpeech.LANG_MISSING_DATA ||
// params.put(TextToSpeech.Engine.KEY_FEATURE_EMBEDDED_SYNTHESIS, "true"); result == TextToSpeech.LANG_NOT_SUPPORTED) {
mTts.speak(text, TextToSpeech.QUEUE_FLUSH, params); Log.e(TAG, "Language is not available");
} else {
HashMap<String,String> params = new HashMap<String,String>();
mTts.speak(text, TextToSpeech.QUEUE_FLUSH, params);
}
} }
} }

View File

@@ -33,7 +33,7 @@ public class Translator {
/* /*
new Language("en-US", "English", "TranslateEng", R.xml.inflection_en), // AR new Language("en-US", "English", "TranslateEng", R.xml.inflection_en), // AR
new Language("cmn-Hans-CN", "Chinese", "TranslateChi", R.xml.inflection_cmn), new Language("cmn-Hans-CN", "Chinese", "TranslateChi", R.xml.inflection_cmn),
new Language("fi-FI", "Finnish", "TranslateFin", 0), new Language("fi-FI", "Finnish", "TranslateFin", R.xml.inflection_fi, R.xml.qwerty),
new Language("sv-SE", "Swedish", "TranslateSwe", R.xml.inflection_sv), new Language("sv-SE", "Swedish", "TranslateSwe", R.xml.inflection_sv),
*/ */
new Language("en-US", "English", "ParseEng", R.xml.inflection_en, R.xml.qwerty), new Language("en-US", "English", "ParseEng", R.xml.inflection_en, R.xml.qwerty),