问题描述
我有问题, 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:
-
isSpeaking()
总是返回的错误如果叫onUtteranceCompleted()
。 -
isSpeaking()
总是返回真正如果在第一马上打电话TTS .speak()
之后的onUtteranceCompleted()
。 -
isSpeaking()
总是返回的错误如果一个tts.speak后,立即叫()
有至少一个或多个tts.speak()
是最后onUtteranceCompleted()
和自身之间分离
isSpeaking()
will always return false if called inonUtteranceCompleted()
.isSpeaking()
will always return true if called immediately after the firsttts.speak()
after anonUtteranceCompleted()
.isSpeaking()
will always return false if called immediately after atts.speak()
that has at least one moretts.speak()
s separating between the lastonUtteranceCompleted()
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.
另外请注意以下除official文档:
的请注意,语音项被认为是完整的,一旦它的音频数据 已发送到音频混合器中,或写入文件。有可能是 一个有限滞后这点之间,以及音频硬件完成时 播放。的
在换句话说,这种方法是完全无用的。
In other words, this method is totally useless.
这篇关于与isSpeaking问题()使用在Android文本到语音的时候的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!