是否可以在 android.speech.tts.Voice
上安装和配置一些男声?我读过一些新闻,说 Android 最近提供了一些可用的功能,但我找不到或无法配置任何功能。我用 tts.setLanguage(Locale.ITALY);
命令尝试的都是女性。
最佳答案
为了增强@brandall 的回答,可以使用男声/女声并从 App UI 动态更改它。像这样定义 TTS(在构造函数中添加 tts 引擎):
tts = new TextToSpeech(context, this, "com.google.android.tts");
contex = activity/app
this= TextToSpeech.OnInitListener
从 tts.getVoices()
列表中,通过名称选择您想要的声音,如下所示:
for (Voice tmpVoice : tts.getVoices()) {
if (tmpVoice.getName().equals(_voiceName)) {
return tmpVoice;
break;
}
}
注意:您需要通过从 tts.getVoices()
获取硬编码的 voice_name 来设置 _voiceName
。例如:对于英国男性,它将是:“en-us-x-sfg#male_1-local”
关于Android TTS男声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36681232/