我有一个文本到语音的工作,但我想知道,当应用程序调用它播放时,会不会用男性声音来代替女性声音?
发布于 2017-01-12 17:14:53
现在可以使用男性/女性语音,并从App UI动态更改它。如下定义TTS (在构造函数中添加google tts引擎):
tts = new TextToSpeech(context, this, "com.google.android.tts");contex =活动/应用
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“
发布于 2018-10-20 15:01:15
可以将声音转换为男性
这是我的代码,希望能对你有所帮助!
//onCreate
T2S= new TextToSpeech(testApp.getInstance().getApplicationContext(), this, "com.google.android.tts");
Set<String> a=new HashSet<>();
a.add("male");//here you can give male if you want to select male voice.
Voice v=new Voice("en-us-x-sfg#male_2-local",new Locale("en","US"),400,200,true,a);
T2S.setVoice(v);
T2S.setSpeechRate(0.8f);在Activity上实现TextToSpeech.OnInitListener。
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
Set<String> a=new HashSet<>();
a.add("male");//here you can give male if you want to select male voice.
//Voice v=new Voice("en-us-x-sfg#female_2-local",new Locale("en","US"),400,200,true,a);
Voice v=new Voice("en-us-x-sfg#male_2-local",new Locale("en","US"),400,200,true,a);
T2S.setVoice(v);
T2S.setSpeechRate(0.8f);
// int result = T2S.setLanguage(Locale.US);
int result = T2S.setVoice(v);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} else {
// btnSpeak.setEnabled(true);
speakOut(mMessageVoice);
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}并添加此函数:
private void speakOut(String message) {
t1.speak(message, TextToSpeech.QUEUE_FLUSH, null);
}发布于 2012-03-22 10:42:45
这取决于底层的TTS引擎。有些是可配置的,有不同的声音(男性、女性等),有些只有一种声音。在任何情况下,您都不能从您的应用程序控制这一点,用户必须从设置应用程序更改TTS引擎设置。你只能指示他们安装一个特定的引擎,并设置你的应用程序来使用它。
https://stackoverflow.com/questions/9815245
复制相似问题