TextToSpeech:API Level 21中不推荐使用的发言功能

Not*_*ion 18 android text-to-speech

我尝试在我的应用中使用TextToSpeech,

String text = editText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
Run Code Online (Sandbox Code Playgroud)

但函数说(String text,int queueMode,HashMap params)在API Level 21中已被弃用.而不是这样,建议使用speak(CharSequence text,int queueMode,Bundle params,String utteranceId).但我不知道如何设置它.谢谢

Ati*_*ood 28

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);
}
Run Code Online (Sandbox Code Playgroud)