这是由于Android 14上TextToSpeech引擎中的某些漏洞造成的。您可以使用Android提供的另一个TTS引擎Pico或使用第三方TTS引擎来解决这个问题。
以下是使用Pico TTS引擎的代码示例:
// 初始化Pico TTS引擎
TextToSpeech tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
// 指定Pico TTS引擎
tts.setEngineByPackageName("com.svox.pico");
// 设置语言
Locale locale = new Locale("en", "US");
tts.setLanguage(locale);
// 文本转语音
tts.speak("Hello world", TextToSpeech.QUEUE_FLUSH, null);
}
}
});
如果想要使用第三方TTS引擎,您可以在Google Play上找到一些可用的选项。