Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextToSpeech : deprecated speak function in API Level 21

I try to use a TextToSpeech in my app,

String text = editText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);

But the function speak(String text, int queueMode, HashMap params) is deprecated in API Level 21. Instead of that, it is adviced to use speak(CharSequence text, int queueMode, Bundle params, String utteranceId). But I don't know how to set it. Thanks

like image 683
Francis Ngueukam Avatar asked Jun 08 '15 10:06

Francis Ngueukam


1 Answers

String text = editText.getText().toString();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    tts.speak(text,TextToSpeech.QUEUE_FLUSH,null,null);
} else {
    tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
like image 198
Atif Mahmood Avatar answered Oct 14 '22 02:10

Atif Mahmood