UtteranceProgressListener回调未触发

2021-09-06  本文已影响0人  静水红阳

前言

日前在书写一个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,在修改之后发现回调已经可以被正常触发了。

上一篇 下一篇

猜你喜欢

热点阅读