Search code examples
androidtext-to-speechvoice-recognition

error in text to speech code


I am following this tutorial for text to speech implementation in my app

http://www.androidhive.info/2012/01/android-text-to-speech-tutorial/

The speech is striked. please refer to the image below

After adding the code

After editing the code


Solution

  • Change the below liine of code:-

    TextToSpeech textSpeach = new TextToSpeech(this, this);
    

    Change To

       TextToSpeech textSpeach = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
                @Override
                public void onInit(int status) {
    
                }
            });
    

    Reason of Problem :- You are passing the context this in both the parameter of TextToSpeech therefore this problem occurred, second this is the listner of the TextToSpeech