我可以像这样迭代获取当前设备支持的语言环境列表:
for (Locale each : Locale.getAvailableLocales())
if(1 <= myTTS.isLanguageAvailable(each))
supportedLocales.add(each);
但是我的问题是,方法isLanguageAvailable()
总是记录以下不支持的语言环境的警告消息:
08-15 20:10:08.163 5056 5672 W TTS Local voice not installed, we will not be able to do local fallback
08-15 20:10:08.527 5056 5067 W TTS No local or network voice found, failing dispatch
08-15 20:10:08.527 5056 5067 W TTS Could not find voice for lkt_US
08-15 20:10:08.606 24353 24382 W TextToSpeech Couldn't retrieve ISO 3166 country code for locale: es_EA
08-15 20:10:08.606 24353 24382 W TextToSpeech java.util.MissingResourceException: Couldn't find 3-letter country code for EA
08-15 20:10:08.606 24353 24382 W TextToSpeech at java.util.Locale.getISO3Country(Locale.java:1720)
08-15 20:10:08.606 24353 24382 W TextToSpeech at android.speech.tts.TextToSpeech$16.run(TextToSpeech.java:1789)
08-15 20:10:08.606 24353 24382 W TextToSpeech at android.speech.tts.TextToSpeech$16.run(TextToSpeech.java:1777)
08-15 20:10:08.606 24353 24382 W TextToSpeech at android.speech.tts.TextToSpeech$Connection.runAction(TextToSpeech.java:2301)
08-15 20:10:08.606 24353 24382 W TextToSpeech at android.speech.tts.TextToSpeech.runAction(TextToSpeech.java:752)
08-15 20:10:08.606 24353 24382 W TextToSpeech at android.speech.tts.TextToSpeech.runAction(TextToSpeech.java:742)
08-15 20:10:08.606 24353 24382 W TextToSpeech at android.speech.tts.TextToSpeech.isLanguageAvailable(TextToSpeech.java:1776)
08-15 20:10:08.606 24353 24382 W TextToSpeech at com.jyplugin.ttsforandroid.TTSEngine.getAvailableLanguageNames(TTSEngine.java:155)
08-15 20:10:08.606 24353 24382 W TextToSpeech at com.jyplugin.ttsforandroid.TTSEngine.getAvailableDisplayNames(TTSEngine.java:190)
08-15 20:10:08.606 24353 24382 W TextToSpeech at com.jyplugin.ttsforandroid.MainActivity$1.run(MainActivity.java:45)
08-15 20:10:08.606 24353 24382 W TextToSpeech at java.lang.Thread.run(Thread.java:764)
每当我启动TTS应用程序时,我都会得到很多,而我真的不想要这个。
如何在我的发行版本中禁止显示这些不必要的警告消息?
答案 0 :(得分:2)
一种解决方法是将logcat筛选器设置为除TextToSpeech之外的所有内容(您需要启用正则表达式):^((?! TextToSpeech).)*$
我认为您不能对来自核心api的日志做任何事情。当您从某些电话进行调试并始终获取蓝牙或连接日志时,会出现相同的问题。
答案 1 :(得分:1)
从API 21开始,您可以调用[您的tts实例] .getAvailableLanguages(),它将返回一组支持的语言环境,而不是迭代您的工作方式。
但是要注意的一件事是,不能保证getAvailableLanguages()方法提供正确格式的语言环境...例如,在API 23上运行的Samsung TTS版本201503021将返回三个字母的语言和国家/地区代码。德尔普。
这意味着您不必继续使用这些相同的Locale对象来执行setLanguage()或isLanguageAvailable()...,因为TTS对象 do 依赖于您的语言环境耗材已正确格式化。 :(
尽管如此,但Google引擎似乎提供了正确的语言环境...并且,如果您有从系统获取的一组语言环境,例如:
// Get all locales from user's preferred list (API 24+) or the single preferred locale (API<24)
LocaleListCompat systemLocaleList = ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration());
...然后,您可以像执行操作一样循环执行isLanguageAvailable()。