我的应用程序使用 TTS。 我尝试过的所有设备都一切正常。 几分钟后,只有魅族 6 Pro Plus 才会停止工作。 我不明白为什么。如果在代码中的某个地方我再次设置 TTS(相同的代码在 onCreate( 中,它会恢复工作:
myTTS = new TextToSpeech(this, this);
对于初始化
public void onInit(int initStatus) {
//check for successful instantiation
if (initStatus == TextToSpeech.SUCCESS) myTTS.setLanguage(Locale.getDefault());
else if (initStatus == TextToSpeech.ERROR) Toast.makeText(this, getString(R.string.errorspeech), Toast.LENGTH_LONG).show();
}
和说话
public static void speakWords(String speech) {
myTTS.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
}
我在日志中收到此消息: 说话失败:未绑定到 TTS 引擎 有人知道这种奇怪行为的原因是什么?谢谢。
你只能在调用 onInit(( 之后调用 speak((,试试这样:
public void onInit(int initStatus) {
//check for successful instantiation
if (initStatus == TextToSpeech.SUCCESS){
myTTS.setLanguage(Locale.getDefault());
myTTS.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
}
else if (initStatus == TextToSpeech.ERROR) Toast.makeText(this, getString(R.string.errorspeech), Toast.LENGTH_LONG).show();
}