我的应用程序使用TTS。我试过的所有设备都没问题。只有魅族6 Pro Plus在几分钟后,TTS才会停止工作。我不明白为什么。如果我在代码中的某个地方再次设置TTS (相同的代码在onCreate中),它就会恢复工作:
myTTS = new TextToSpeech(this, this);对于init
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引擎有人知道是什么导致了这种奇怪的行为吗?谢谢。
发布于 2018-09-24 20:47:10
您只能在调用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();
}https://stackoverflow.com/questions/52476146
复制相似问题