美文网首页
UtteranceProgressListener回调未触发

UtteranceProgressListener回调未触发

作者: 静水红阳 | 来源:发表于2021-09-06 13:49 被阅读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,在修改之后发现回调已经可以被正常触发了。

    相关文章

      网友评论

          本文标题:UtteranceProgressListener回调未触发

          本文链接:https://www.haomeiwen.com/subject/qvxswltx.html