与isSpeaking问题()使用在Android文本到语音的时候 [英] Problem with isSpeaking() when using Text-to-Speech on Android

查看:289
本文介绍了与isSpeaking问题()使用在Android文本到语音的时候的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题, isSpeaking()方法。当传递 QUEUE_FLUSH 说话()方法, isSpeaking()工作正常。然而,当我排队多的话语(通过传递 QUEUE_ADD )的 isSpeaking()方法开始返回后,立即一个以上的话语一直在排队。

I'm having problem with isSpeaking() method. When passing QUEUE_FLUSH to the speak() method, isSpeaking() works fine. However, when I queue multiple utterances (by passing QUEUE_ADD), the isSpeaking() method starts returning false immediately after more than one utterance have been queued.

然后,我偶然发现<一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.3.4_r1/android/tts/TtsService.java#1310"相对=nofollow>的 TtsService 类源$ C ​​$ c和看到这个code:

Then I stumbled across the source code of the TtsService class and saw this code:

public boolean isSpeaking() {
  return (mSelf.mIsSpeaking && (mSpeechQueue.size() < 1));
}

有没有人有任何想法,为什么这种方法实施这样的方式?

Does anyone have any idea, why was this method implemented in such way?

推荐答案

我偶然发现了这一个了。

I stumbled upon this one, too.

它已经整整一年,因为你问到这个问题并没有答案是在天涯...

It has been exactly one year since you asked this question and no answer is in the horizon...

所以我只能猜测,谁写了这片code意欲它意味着

So I can only guess that whoever wrote this piece of code intended it to mean

只有讲的最后一个话语的。

这是否有道理?

唯一的问题是,无论在 QUEUE_ADD QUEUE_FLUSH 模式,经验观察表明,有严重的时序比赛条件包括:

The only problem is that, regardless of whether in QUEUE_ADD or QUEUE_FLUSH mode, empirical observations suggest that there are serious timing race conditions involved:

  1. isSpeaking()总是返回的错误如果叫 onUtteranceCompleted()
  2. isSpeaking()总是返回真正如果在第一 马上打电话TTS .speak()之后的 onUtteranceCompleted()
  3. isSpeaking()总是返回的错误如果一个 tts.speak后,立即叫()有至少一个或多个 tts.speak()是最后 onUtteranceCompleted()和自身之间分离
  1. isSpeaking() will always return false if called in onUtteranceCompleted().
  2. isSpeaking() will always return true if called immediately after the first tts.speak() after an onUtteranceCompleted().
  3. isSpeaking() will always return false if called immediately after a tts.speak() that has at least one more tts.speak()s separating between the last onUtteranceCompleted() and itself .

在某种程度上,它的行为完全相反的预期:

In a way, it behaves exactly the opposite of the "intended":

仅在讲第一话语的(后的 onUtteranceCompleted()的)

为什么会喜欢的行为,这是超越我,但是这​​至少是logcat的节目。

Why it behaves likes this is beyond me, but that's at least what LogCat shows.

另外请注意以下除<一个href="http://developer.android.com/reference/android/speech/tts/TextToSpeech.html#isSpeaking%28%29">official文档:

请注意,语音项被认为是完整的,一旦它的音频数据   已发送到音频混合器中,或写入文件。有可能是   一个有限滞后这点之间,以及音频硬件完成时   播放。

"Note that a speech item is considered complete once it's audio data has been sent to the audio mixer, or written to a file. There might be a finite lag between this point, and when the audio hardware completes playback."

在换句话说,这种方法是完全无用的。

In other words, this method is totally useless.

这篇关于与isSpeaking问题()使用在Android文本到语音的时候的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆