我在我的Android应用程序中使用文本到语音。它与谷歌TT和espeak工作正常,但当我使用三星TTS时,它给出以下例外。
java.lang.IllegalArgumentException: Invalid int: "OS"
at android.os.Parcel.readException(Parcel.java:1429)
at android.os.Parcel.readException(Parcel.java:1379)
at android.speech.tts.ITextToSpeechService$Stub$Proxy.isLanguageAvailable(ITextToSpeechService.java:482)
at android.speech.tts.TextToSpeech$10.run(TextToSpeech.java:1084)
at android.speech.tts.TextToSpeech$10.run(TextToSpeech.java:1081)
at android.speech.tts.TextToSpeech$Connection.runAction(TextToSpeech.java:1329)
at android.speech.tts.TextToSpeech.runAction(TextToSpeech.java:570)
at android.speech.tts.TextToSpeech.runAction(TextToSpeech.java:561)
at android.speech.tts.TextToSpeech.isLanguageAvailable(TextToSpeech.java:1081)
答案 0 :(得分:4)
我发现当我尝试执行TextToSpeech.getDefaultVoice
,TextToSpeech.getVoices()
或TextToSpeech.getVoice()
之类的操作时,我也会遇到此异常。我通过不调用它来解决这个问题,而是使用默认的Locale来获取我试图通过Voices对象获得的内容。
所以在我的情况下我想知道Locale所以我可以选择一种语言,所以我做了以下
Locale lTest = Locale.getDefault();
res = mTTS.isLanguageAvailable(lTest);
答案 1 :(得分:0)
我用它来避免引发异常。
int result = mTts.isLanguageAvailable(Locale.US);
if(result >= 0)
result = mTts.setLanguage(Locale.US);
else {
Locale def = Locale.getDefault();
result = mTts.isLanguageAvailable(def);
if(result >=0 )
result = mTts.setLanguage(def);
}