gpt4 book ai didi

android - 嗯?为什么 playEarcon() 不产生 onUtteranceCompleted()?

转载 作者:行者123 更新时间:2023-11-29 02:05:47 24 4
gpt4 key购买 nike

我有一本 Android 书籍指出,使用 TextToSpeech.playEarcon() 比播放音频文件(使用 MediaPlayer)更可取,因为:

Instead of having to determine the opportune moment to play an audible cue and relying on callbacks to get the timing right, we can instead queue up our earcons among the text we send to the TTS engine. We then know that our earcons will be played at the appropriate time, and we can use the same pathway to get our sounds to the user, including the onUtteranceCompleted() callbacks to let us know where we are.

但我的简短实验表明这不是情况:

String utteranceId = String.valueOf(utteranceNum++);
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, utteranceId);
params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_MUSIC));
tts.speak("FIRST part of sentence", TextToSpeech.QUEUE_ADD, params);

utteranceId = String.valueOf(utteranceNum++);
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, utteranceId);
params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_MUSIC));
tts.playEarcon("[fancyring]", TextToSpeech.QUEUE_ADD, params);

utteranceId = String.valueOf(utteranceNum++);
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, utteranceId);
params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_MUSIC));
tts.speak("SECOND part of sentence", TextToSpeech.QUEUE_ADD, params);

当我检查来自 onUtteranceCompleted() 的日志时我只看到 tts.speak() 播放的 utteranceIds,而不是 tts.playEarcon() 播放的。

为什么会出现这种差异?有解决办法吗?

P.S. 冒着陈述显而易见的风险:所有三个话语都以正确的顺序播放得很好。它只是 onUtteranceCompleted()由于某些原因 tts.playEarcon() 没有调用它。

最佳答案

回答我自己。关于 TextToSpeech.OnUtteranceCompletedListener 的令人难以置信的冗长且非常详细的文档阅读(重点是我的):

Called when an utterance has been synthesized.

耳标从不是综合的结果,所以当然onUtteranceCompleted() 永远 不会被调用。这是设计使然。

这让我们回到了一个新问题:如果 earcons 与播放 .mp3 文件(使用 MediaPlayer)相比没有优势,为什么还要使用 earcons?

关于android - 嗯?为什么 playEarcon() 不产生 onUtteranceCompleted()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10134646/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com