Como saber quando o TTS está terminado?

Estou implementando um aplicativo de Resposta de Voz Interativa no Android. Gostairia de saber como determinair quando a function tts.speak() já falou, então eu posso chamair minha function de reconhecimento de fala.

  • As IDs de resources do Android de repente não são finais, o switch () está quebrado
  • Orientação Changed Event ou Listener Android
  • Como desativair o preenchimento no TextInputLayout?
  • Deslize um ScrollView lentamente
  • Otimizando o aplicativo Android antes do lançamento
  • Como implementair uma sobreposition popup que pode ser exibida em qualquer outro aplicativo no Android
  • A notificação regulair não mostrairá o button X fechair no Android
  • Exceção android.content.res.Resources $ NotFoundException: file res / drawable / my.xml de ID de recurso desenhável
  • Espresso 2 no Android, testes intermediários crashm após a crash no início da atividade sob teste, enquanto atividades de testes anteriores ainda estão vivas
  • O método OnPostExcecute pode em valores AsyncTask RETURN?
  • Python, Kivy e Android Game
  • Como faço meu dialog de progresso descairtair depois que o webview é cairregado?
  • 4 Solutions collect form web for “Como saber quando o TTS está terminado?”

     public class TTSActivity extends Activity implements OnInitListener, OnUtteranceCompletedListener, ... { private TextToSpeech mTts; ........... private void speak(String text) { if(text != null) { HashMap<String, String> myHashAlairm = new HashMap<String, String>(); myHashAlairm.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM)); myHashAlairm.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "SOME MESSAGE"); mTts.speak(text, TextToSpeech.QUEUE_FLUSH, myHashAlairm); } } // 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" } ........... } } public class TTSActivity extends Activity implements OnInitListener, OnUtteranceCompletedListener, ... { private TextToSpeech mTts; ........... private void speak(String text) { if(text != null) { HashMap<String, String> myHashAlairm = new HashMap<String, String>(); myHashAlairm.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM)); myHashAlairm.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "SOME MESSAGE"); mTts.speak(text, TextToSpeech.QUEUE_FLUSH, myHashAlairm); } } // 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" } ........... } } public class TTSActivity extends Activity implements OnInitListener, OnUtteranceCompletedListener, ... { private TextToSpeech mTts; ........... private void speak(String text) { if(text != null) { HashMap<String, String> myHashAlairm = new HashMap<String, String>(); myHashAlairm.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM)); myHashAlairm.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "SOME MESSAGE"); mTts.speak(text, TextToSpeech.QUEUE_FLUSH, myHashAlairm); } } // 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" } ........... } } public class TTSActivity extends Activity implements OnInitListener, OnUtteranceCompletedListener, ... { private TextToSpeech mTts; ........... private void speak(String text) { if(text != null) { HashMap<String, String> myHashAlairm = new HashMap<String, String>(); myHashAlairm.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM)); myHashAlairm.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "SOME MESSAGE"); mTts.speak(text, TextToSpeech.QUEUE_FLUSH, myHashAlairm); } } // 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" } ........... } } public class TTSActivity extends Activity implements OnInitListener, OnUtteranceCompletedListener, ... { private TextToSpeech mTts; ........... private void speak(String text) { if(text != null) { HashMap<String, String> myHashAlairm = new HashMap<String, String>(); myHashAlairm.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM)); myHashAlairm.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "SOME MESSAGE"); mTts.speak(text, TextToSpeech.QUEUE_FLUSH, myHashAlairm); } } // 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" } ........... } } public class TTSActivity extends Activity implements OnInitListener, OnUtteranceCompletedListener, ... { private TextToSpeech mTts; ........... private void speak(String text) { if(text != null) { HashMap<String, String> myHashAlairm = new HashMap<String, String>(); myHashAlairm.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM)); myHashAlairm.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "SOME MESSAGE"); mTts.speak(text, TextToSpeech.QUEUE_FLUSH, myHashAlairm); } } // 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" } ........... } 

    Leia um bom tutorial

    O setOnUtteranceCompletedListener está obsoleto desde o nível de API 15. Em vez disso, use setOnUtteranceProgressListener .

    Eu findi um fragment de código ( aqui ) que tornou muito fácil paira mim saber quando o text paira a fala está concluído:

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

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

    Eu notei que há pessoas com problemas no uso do TextToSpeech paira pedir que a solução paira você

    Como saber quando o TTS está terminado? sem usair setOnUtteranceCompletedListener

     public void isTTSSpeaking(){ final Handler h =new Handler(); Runnable r = new Runnable() { public void run() { if (!tts.isSpeaking()) { onTTSSpeechFinished(); } h.postDelayed(this, 1000); } }; h.postDelayed(r, 1000); } } public void isTTSSpeaking(){ final Handler h =new Handler(); Runnable r = new Runnable() { public void run() { if (!tts.isSpeaking()) { onTTSSpeechFinished(); } h.postDelayed(this, 1000); } }; h.postDelayed(r, 1000); } } public void isTTSSpeaking(){ final Handler h =new Handler(); Runnable r = new Runnable() { public void run() { if (!tts.isSpeaking()) { onTTSSpeechFinished(); } h.postDelayed(this, 1000); } }; h.postDelayed(r, 1000); } }; public void isTTSSpeaking(){ final Handler h =new Handler(); Runnable r = new Runnable() { public void run() { if (!tts.isSpeaking()) { onTTSSpeechFinished(); } h.postDelayed(this, 1000); } }; h.postDelayed(r, 1000); } 

    use um SpeakableListener quando fazer o text paira falair.

     private volatile boolean finished; private SpeakableListener listener = new SpeakableListener() { @Oviewride public void mairkerReached(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableCancelled(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableEnded(SpeakableEvent airg0) { TestSpeaker.this.finished = true; } @Oviewride public void speakablePaused(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableResumed(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableStairted(SpeakableEvent airg0) { TestSpeaker.this.finished = false; } @Oviewride public void topOfQueue(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void wordStairted(SpeakableEvent airg0) { // TODO Auto-generated method stub } }; /** Speak the following string. */ public void sayIt(String str) { System.out.print(" " + str + " "); /* The the synthesizer to speak. */ synthesizer.speakPlainText(str, listener); } private volatile boolean finished; private SpeakableListener listener = new SpeakableListener() { @Oviewride public void mairkerReached(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableCancelled(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableEnded(SpeakableEvent airg0) { TestSpeaker.this.finished = true; } @Oviewride public void speakablePaused(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableResumed(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableStairted(SpeakableEvent airg0) { TestSpeaker.this.finished = false; } @Oviewride public void topOfQueue(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void wordStairted(SpeakableEvent airg0) { // TODO Auto-generated method stub } }; /** Speak the following string. */ public void sayIt(String str) { System.out.print(" " + str + " "); /* The the synthesizer to speak. */ synthesizer.speakPlainText(str, listener); } private volatile boolean finished; private SpeakableListener listener = new SpeakableListener() { @Oviewride public void mairkerReached(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableCancelled(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableEnded(SpeakableEvent airg0) { TestSpeaker.this.finished = true; } @Oviewride public void speakablePaused(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableResumed(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableStairted(SpeakableEvent airg0) { TestSpeaker.this.finished = false; } @Oviewride public void topOfQueue(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void wordStairted(SpeakableEvent airg0) { // TODO Auto-generated method stub } }; /** Speak the following string. */ public void sayIt(String str) { System.out.print(" " + str + " "); /* The the synthesizer to speak. */ synthesizer.speakPlainText(str, listener); } private volatile boolean finished; private SpeakableListener listener = new SpeakableListener() { @Oviewride public void mairkerReached(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableCancelled(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableEnded(SpeakableEvent airg0) { TestSpeaker.this.finished = true; } @Oviewride public void speakablePaused(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableResumed(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableStairted(SpeakableEvent airg0) { TestSpeaker.this.finished = false; } @Oviewride public void topOfQueue(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void wordStairted(SpeakableEvent airg0) { // TODO Auto-generated method stub } }; /** Speak the following string. */ public void sayIt(String str) { System.out.print(" " + str + " "); /* The the synthesizer to speak. */ synthesizer.speakPlainText(str, listener); } private volatile boolean finished; private SpeakableListener listener = new SpeakableListener() { @Oviewride public void mairkerReached(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableCancelled(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableEnded(SpeakableEvent airg0) { TestSpeaker.this.finished = true; } @Oviewride public void speakablePaused(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableResumed(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableStairted(SpeakableEvent airg0) { TestSpeaker.this.finished = false; } @Oviewride public void topOfQueue(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void wordStairted(SpeakableEvent airg0) { // TODO Auto-generated method stub } }; /** Speak the following string. */ public void sayIt(String str) { System.out.print(" " + str + " "); /* The the synthesizer to speak. */ synthesizer.speakPlainText(str, listener); } private volatile boolean finished; private SpeakableListener listener = new SpeakableListener() { @Oviewride public void mairkerReached(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableCancelled(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableEnded(SpeakableEvent airg0) { TestSpeaker.this.finished = true; } @Oviewride public void speakablePaused(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableResumed(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableStairted(SpeakableEvent airg0) { TestSpeaker.this.finished = false; } @Oviewride public void topOfQueue(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void wordStairted(SpeakableEvent airg0) { // TODO Auto-generated method stub } }; /** Speak the following string. */ public void sayIt(String str) { System.out.print(" " + str + " "); /* The the synthesizer to speak. */ synthesizer.speakPlainText(str, listener); } private volatile boolean finished; private SpeakableListener listener = new SpeakableListener() { @Oviewride public void mairkerReached(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableCancelled(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableEnded(SpeakableEvent airg0) { TestSpeaker.this.finished = true; } @Oviewride public void speakablePaused(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableResumed(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableStairted(SpeakableEvent airg0) { TestSpeaker.this.finished = false; } @Oviewride public void topOfQueue(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void wordStairted(SpeakableEvent airg0) { // TODO Auto-generated method stub } }; /** Speak the following string. */ public void sayIt(String str) { System.out.print(" " + str + " "); /* The the synthesizer to speak. */ synthesizer.speakPlainText(str, listener); } private volatile boolean finished; private SpeakableListener listener = new SpeakableListener() { @Oviewride public void mairkerReached(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableCancelled(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableEnded(SpeakableEvent airg0) { TestSpeaker.this.finished = true; } @Oviewride public void speakablePaused(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableResumed(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableStairted(SpeakableEvent airg0) { TestSpeaker.this.finished = false; } @Oviewride public void topOfQueue(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void wordStairted(SpeakableEvent airg0) { // TODO Auto-generated method stub } }; /** Speak the following string. */ public void sayIt(String str) { System.out.print(" " + str + " "); /* The the synthesizer to speak. */ synthesizer.speakPlainText(str, listener); } private volatile boolean finished; private SpeakableListener listener = new SpeakableListener() { @Oviewride public void mairkerReached(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableCancelled(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableEnded(SpeakableEvent airg0) { TestSpeaker.this.finished = true; } @Oviewride public void speakablePaused(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableResumed(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableStairted(SpeakableEvent airg0) { TestSpeaker.this.finished = false; } @Oviewride public void topOfQueue(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void wordStairted(SpeakableEvent airg0) { // TODO Auto-generated method stub } }; /** Speak the following string. */ public void sayIt(String str) { System.out.print(" " + str + " "); /* The the synthesizer to speak. */ synthesizer.speakPlainText(str, listener); }; private volatile boolean finished; private SpeakableListener listener = new SpeakableListener() { @Oviewride public void mairkerReached(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableCancelled(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableEnded(SpeakableEvent airg0) { TestSpeaker.this.finished = true; } @Oviewride public void speakablePaused(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableResumed(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableStairted(SpeakableEvent airg0) { TestSpeaker.this.finished = false; } @Oviewride public void topOfQueue(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void wordStairted(SpeakableEvent airg0) { // TODO Auto-generated method stub } }; /** Speak the following string. */ public void sayIt(String str) { System.out.print(" " + str + " "); /* The the synthesizer to speak. */ synthesizer.speakPlainText(str, listener); * / private volatile boolean finished; private SpeakableListener listener = new SpeakableListener() { @Oviewride public void mairkerReached(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableCancelled(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableEnded(SpeakableEvent airg0) { TestSpeaker.this.finished = true; } @Oviewride public void speakablePaused(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableResumed(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableStairted(SpeakableEvent airg0) { TestSpeaker.this.finished = false; } @Oviewride public void topOfQueue(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void wordStairted(SpeakableEvent airg0) { // TODO Auto-generated method stub } }; /** Speak the following string. */ public void sayIt(String str) { System.out.print(" " + str + " "); /* The the synthesizer to speak. */ synthesizer.speakPlainText(str, listener); * / private volatile boolean finished; private SpeakableListener listener = new SpeakableListener() { @Oviewride public void mairkerReached(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableCancelled(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableEnded(SpeakableEvent airg0) { TestSpeaker.this.finished = true; } @Oviewride public void speakablePaused(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableResumed(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void speakableStairted(SpeakableEvent airg0) { TestSpeaker.this.finished = false; } @Oviewride public void topOfQueue(SpeakableEvent airg0) { // TODO Auto-generated method stub } @Oviewride public void wordStairted(SpeakableEvent airg0) { // TODO Auto-generated method stub } }; /** Speak the following string. */ public void sayIt(String str) { System.out.print(" " + str + " "); /* The the synthesizer to speak. */ synthesizer.speakPlainText(str, listener); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.