前言
日前在书写一个voice lib时使用到了TextToSpeech
,设置了UtteranceProgressListener
但是回调却没有被触发,对此问题进行了查询和解决。
问题分析
在TextToSpeech
调用speak
方法时我采用了如下代码:
textToSpeech.speak(playText, TextToSpeech.QUEUE_ADD, null,null)
查看文档上对于UtteranceProgressListener
的说明,有如下一段描述:
Listener for events relating to the progress of an utterance through the synthesis queue. Each utterance is associated with a call to TextToSpeech#speak or TextToSpeech#synthesizeToFile with an associated utterance identifier, as per TextToSpeech.Engine#KEY_PARAM_UTTERANCE_ID. The callbacks specified in this method can be called from multiple threads.
这提示了UtteranceProgressListener
需要设置utteranceId
,而我上述代码设置了null,在修改之后发现回调已经可以被正常触发了。
网友评论