I'm having a problem with the OnUtteranceCompletedListener in
TextToSpeech. In execution of the code below, the listener is
registered successfully, but OnUtteranceCompleted is never executed. I
tried this with both the Eclipse emulator (2.3) and an HTC phone
(2.2).

I saw some earlier reports of the same problem, and wondered if
there's been any progress in resolving it.


import java.util.HashMap;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener;
import android.util.Log;
import android.widget.Toast;

public class SpeechSynthesis extends Activity
                implements TextToSpeech.OnInitListener, 
OnUtteranceCompletedListener
{

        private static final String TAG = "SpeechSynthesis";
    private TextToSpeech tts;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Log.e(TAG, "Starting SpeechSynthesis");

        tts = new TextToSpeech(this, this);
    } // end onCreate

    public void onInit(int status) {
        Toast.makeText(this, "onInit", Toast.LENGTH_SHORT).show();

        if (status != TextToSpeech.SUCCESS) {
                Log.e(TAG, "TTS failed to initialize"+status);
                return;
        }

        int result = tts.setOnUtteranceCompletedListener(this);
        if (result != TextToSpeech.SUCCESS){
                Log.e(TAG, "Failed setOnUtteranceCompletedListener");
                return;
        }

        HashMap<String, String> map = new HashMap<String, String>();
        map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "some ID
stuff");
        tts.speak("Hello there", TextToSpeech.QUEUE_FLUSH, map);
    } // end onInit

    public void onUtteranceCompleted(String utteranceId) {
        Toast.makeText(this, "onUC", Toast.LENGTH_SHORT).show();
    } // end onUtteranceCOmpleted

} // end SpeechSynthesis

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to