TextToSpeech setOnUtteranceCompletedListener always returns -1 error?
I've been working with Android's TTS functions with general success however, one piece of it refuses to work for me; I can not successfully assign an OnUtteranceCompletedListener to my TextToSpeech object.
I've tried implementing OnUtteranceCompletedListener in one of my classes and I've tried creating a new, stand-alone OnUtteranceCompletedListener instance. Both approaches are simple enough to implement and appear to yield proper listeners without exceptions...yet setOnUtteranceCompletedListener(myListener) ALWAYS returns -1 (ERROR).
The documentation for this seems straight forward. Has anyone gotten this to work? I'm targeting SDK 4. Are t开发者_StackOverflow中文版here known issues with this with SDK4/v1.6?
Naturally, after being stumped for more than a day I stumbled onto the answer 15 mins after I asked the question on here.
The answer: the OnUtteranceCompletedListener can only be assigned to the TextToSpeech object AFTER the TTS onInit fires.
I was trying to set the listener immediately after creating the TTS instance. I moved setOnUtteranceCompletedListener(myListener) to my onInit code and now it returns result code 0 (SUCCESS).
IMO, the TextToSpeech setOnUtteranceCompletedListener documentation lacks this detail and should be updated.
There's also another caveat with this listener: http://groups.google.com/group/tts-for-android/browse_thread/thread/6d5feb49a599e9f9
精彩评论