TextToSpeech:API 级别 21 中已弃用的朗读功能
TextToSpeech : deprecated speak function in API Level 21
我尝试在我的应用程序中使用 TextToSpeech,
String text = editText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
但是函数 speak(String text, int queueMode, HashMap params) 在 API 级别 21 中被弃用。建议使用 speak(CharSequence text, int queueMode, Bundle params,字符串 utteranceId)。
但我不知道如何设置它。谢谢
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);
}
这是适合我的完整作品
Private TextToSpeech ts
ts=new TextToSpeech(CurrentActivity.this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
String text = "Any Text to Speak";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ts.speak(text,TextToSpeech.QUEUE_FLUSH,null,null);
} else {
ts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}
});
我尝试在我的应用程序中使用 TextToSpeech,
String text = editText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
但是函数 speak(String text, int queueMode, HashMap params) 在 API 级别 21 中被弃用。建议使用 speak(CharSequence text, int queueMode, Bundle params,字符串 utteranceId)。 但我不知道如何设置它。谢谢
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);
}
这是适合我的完整作品
Private TextToSpeech ts
ts=new TextToSpeech(CurrentActivity.this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
String text = "Any Text to Speak";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ts.speak(text,TextToSpeech.QUEUE_FLUSH,null,null);
} else {
ts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}
});