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.
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...
So I can only guess that whoever wrote this piece of code intended it to mean
Does this make sense?
The only problem is that, regardless of whether in
QUEUE_ADD
orQUEUE_FLUSH
mode, empirical observations suggest that there are serious timing race conditions involved: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":
Why it behaves likes this is beyond me, but that's at least what LogCat shows.
Also note the following addition to the official documentation:
In other words, this method is totally useless.
There is a broadcast intent when the queue is complete: ACTION_TTS_QUEUE_PROCESSING_COMPLETED.
Here is an example class to register a BroadCastReceiver and use this to determine the isSpeaking state.
Call Init and Shutdown from the relevant places in your activity and use the Speak and isSpeaking functions provided in this class: