views:

77

answers:

1

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 there known issues with this with SDK4/v1.6?

A: 

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.

Robert Nekic