我正在尝试使用 android 应用程序重现一些文本,这将有助于视障人士,尤其是 TTS,但就我而言,我需要葡萄牙语-巴西语,而 TTS 类没有葡萄牙语作为区域设置。有没有人知道如何实现葡萄牙语巴西阅读器?
我使用的是Android Studio,MinSDK是15。
...
tts = new TextToSpeech (this, this);
tts.setLanguage(Locale.[X]);
...
tts.speak("Muito obrigado a todos!", TextToSpeech.QUEUE_FLUSH, null);
...
你是如何onInitListener()
的?调用时tts = new TextToSpeech (this, this);
onInitListener()
会将文本转语音服务连接到tts
实例。因此,如果您尝试设置语言或说出声音,请检查此值:
tts = new TextToSpeech (this, this);
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int res = tts.setLanguage(Locale.[X]);
if (res >= TextToSpeech.LANG_AVAILABLE) {
// Then, you can speak with your locale.
// Call speak() in here or after this method.
tts.speak("Muito obrigado a todos!", TextToSpeech.QUEUE_FLUSH, null);
}
}
}
解决了!我的问题是设备上没有安装TTS。因此,只需从谷歌商店(https://play.google.com/store/apps/details?id=com.google.android.tts&hl=en)安装它。