TTS工作一分钟后停止通话

时间:2018-09-24 09:20:58

标签: android text-to-speech

我的应用使用了TTS。 用我尝试过的所有设备都可以。 几分钟后,只有使用魅族6 Pro Plus,TTS才能停止工作。 我不明白为什么。如果我在代码中的某处再次设置了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引擎 有人知道这种奇怪行为的原因是什么?谢谢。

1 个答案:

答案 0 :(得分:0)

您只能在调用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();
     }
相关问题