即使我设置正确:
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方法中添加代码.
示例:
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);