Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know when TTS is finished?

I'm implementing an Interactive Voice Response application on Android. I would like to know how to determine when the tts.speak() function has done talking so I can call my speech recognizer function.

like image 516
Felipeap Avatar asked Jan 11 '11 13:01

Felipeap


People also ask

How do I add a long pause in TTS?

Amazon Polly You can make the TTS pause between sentences, or anywhere you want by adding up to three periods (".") all followed by a single space " ".

Why TTS is not working in Android?

Look under Accessibility > Text-to-speech output. Ensure you have "Google Text to Speech" selected and the correct language. Note that Speaking Email won't use Samsung or other vendor voices - so you need to enable the Google voices as your default TTS engine.

Does Google TTS require Internet?

you can have this feature offline by doing as follows: Go to “Language and Input” in the Setting. Tap on "Download offline speech recognition" under the "Voice Search" Choose the language pack you want your Android device to recognize.


2 Answers

public class TTSActivity extends Activity implements OnInitListener, OnUtteranceCompletedListener, ... { private TextToSpeech mTts; ........... private void speak(String text) {    if(text != null) {       HashMap<String, String> myHashAlarm = new HashMap<String, String>();       myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM));       myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "SOME MESSAGE");       mTts.speak(text, TextToSpeech.QUEUE_FLUSH, myHashAlarm);    } } // Fired after TTS initialization public void onInit(int status) {     if(status == TextToSpeech.SUCCESS) {         mTts.setOnUtteranceCompletedListener(this);     } } // It's callback public void onUtteranceCompleted(String utteranceId) {    Log.i(TAG, utteranceId); //utteranceId == "SOME MESSAGE"    } ........... } 

Read A good tutorial

like image 170
mysuperass Avatar answered Sep 27 '22 22:09

mysuperass


The setOnUtteranceCompletedListener is deprecated since API level 15. Instead, use setOnUtteranceProgressListener.

I found a code snippet (here) that made it really easy for me to know when text to speech is finished:

@Override public void onInit(int status) {     if (status == TextToSpeech.SUCCESS) {         myTTS.setOnUtteranceProgressListener(new UtteranceProgressListener() {             @Override             public void onDone(String utteranceId) {                 // Log.d("MainActivity", "TTS finished");             }              @Override             public void onError(String utteranceId) {             }              @Override             public void onStart(String utteranceId) {             }         });     } else {         Log.e("MainActivity", "Initilization Failed!");     } } 

http://www.codota.com/android/scenarios/52fcbd34da0ae25e0f855408/android.speech.tts.TextToSpeech?tag=dragonfly

like image 35
kevinweber Avatar answered Sep 27 '22 23:09

kevinweber