我可以像下面这样获得当前设备支持的语言环境列表:
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应用程序时,我都会收到很多这样的东西,但我真的不想这么做。
对于我的发行版,如何抑制这些不必要的警告消息?
最佳答案
一种解决方法是将logcat筛选器设置为除TextToSpeech之外的所有内容(您需要启用正则表达式):^((?! TextToSpeech).)*$
我认为您无法对来自核心api的日志做任何事情。当您从某些电话进行调试并始终获取蓝牙或连接日志时,也会出现相同的问题。