gpt4 book ai didi

android - 文字转语音 : deprecated speak function in API Level 21

转载 作者:IT老高 更新时间:2023-10-28 23:21:52 26 4
gpt4 key购买 nike

我尝试在我的应用中使用 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, String 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);
}

关于android - 文字转语音 : deprecated speak function in API Level 21,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30706780/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com