I have been surfing the web (read google/ android developer document, read stackoverflow's similar questions, read book) and very closely followed the examples. The Text-to-Speech "speak" works great. But I just can't get OnUtteranceCompleted to be called.
It must be so simple that I am not seeing the answer. Please help! Here's my code after several interactions.
Or could someone be kind enough to provide a full source code (not snippets) of one that actually works to see if it works on my emulator/ actual device?
public class testActivity extends Activity implements OnInitListener, OnUtteranceCompletedListener {
...
protected void checkTtS() {
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, TTS_DATA_CHECK_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
....
if (requestCode == TTS_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// success, create the TTS instance
mTts = new TextToSpeech(this, this);
....
// Implements TextToSpeech.OnInitListener.
public void onInit(int status) {
// status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR.
if (status == TextToSpeech.SUCCESS) {
int result = mTts.setLanguage(Locale.FRANCE);
result = mTts.setOnUtteranceCompletedListener(this);
HashMap<String, String> params = new HashMap<String, String>();
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"stringId");
mTts.speak("Text to Speak",TextToSpeech.QUEUE_FLUSH, params);
....
public void onUtteranceCompleted(String uttId) {
Toast.makeText(getBaseContext(), "onutterancecompleted", Toast.LENGTH_SHORT).show();
}