android – onUtteranceCompleted不会被调用?

前端之家收集整理的这篇文章主要介绍了android – onUtteranceCompleted不会被调用?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
即使我设置正确:
HashMap<String,String> myHashRender = new HashMap<String,String>();
myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"utid");
mTts.speak("Speak something",TextToSpeech.QUEUE_ADD,myHashRender);

mTts.setOnUtteranceCompletedListener(this);

在onInit函数中返回成功.
仍然没有调用onUtteranceCompleted.虽然有重复的问题,但没有哪里可以找到答案.

我的活动也实现了OnUtteranceCompletedListener.

请帮忙.

解决方法

调用tts对象的onInit函数中的setOnUtteranceCompletedListener.

如果要在onUtteranceCompleted函数调用上对UI进行任何更改,请在runOnUIThread方法添加代码.

并记住在调用speak()函数添加Hashmap参数值

示例:

TextToSpeech tts= new TextToSpeech(context,new OnInitListener() {

 @Override
 public void onInit(int status) {

    mTts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() {

        @Override
        public void onUtteranceCompleted(String utteranceId) {

            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                //UI changes
                }
            });
        }
    });

 }
});


HashMap<String,String> params = new HashMap<String,String>();

params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"stringId");

tts.speak("Text to Speak",TextToSpeech.QUEUE_FLUSH,params);

猜你在找的Android相关文章