Search code examples
androidtext-to-speech

Text to speech receiving many speak requests at once


I am writing an app that reads out strings one after the other. My problem is that TTS seems to stutter through the first couple, say one properly and then stop. I can't understand why.

    public void onInit(int status) {

    Log.d("TTS", "2");
    String text = desc;
    Toast.makeText(ct, "Saying: " + text, Toast.LENGTH_LONG).show();
    tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}

This onInit method is located in a Broadcast Receiver so every time a proximity alert is received it reads the associated String. I'd really appreciate some help with this.


Solution

  • I don't know whether it can help you in your case or not,but I was facing problem like it gets requests to speak many time and hence it keeps on repeating the new strings and doesn't complete the previous one.So I did this trick.Hope it can help you for yours.:P

    public void onInit(int status) {
    
        Log.d("TTS", "2");
        String text = desc;
        Toast.makeText(ct, "Saying: " + text, Toast.LENGTH_LONG).show();
    
        if(!tts.isSpeaking())               
            tts.speak(text,TextToSpeech.QUEUE_FLUSH,null);       
    }