mystic
mystic

Reputation: 85

Android TTS error

How do i implement text to speech in my app to support minSdk 15? current API is 24. I get an error in this method.

  public void TextToSpeech(string Text)
    {
    myTTS.speak(Text,TextToSpeech.QUEUE_FLUSH,null);
    }

error says that speak is deprecated and I tried replacing that with this

 public void TextToSpeech(string Text)
    {
    myTTS.speak(Text,TextToSpeech.QUEUE_FLUSH,null,"myTTSid");
    }

a recent version but that is also not supported on the minSdk 15 i want to use. Is there a way I can implement TTS to supported the minSdk 15 i'm targetting?

Upvotes: 1

Views: 795

Answers (1)

Alexander M.
Alexander M.

Reputation: 3468

private void speak(String text) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        myTTS.speak(text, TextToSpeech.QUEUE_FLUSH, null, "myTTSid");
    } else {
        myTTS.speak(text, TextToSpeech.QUEUE_FLUSH, null);
    }    
}

Upvotes: 2

Related Questions