TextToSpeech:API级别21中不建议使用的语音功能

TextToSpeech:API级别21中不建议使用的语音功能

问题描述:

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

I try to use a TextToSpeech in my app,

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

但是在API级别21中不建议使用函数talk(String text,int queueMode,HashMap params).相反,建议不要使用talk(CharSequence text,int queueMode,Bundle params,String utteranceId).但是我不知道如何设置.谢谢

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

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);
}