Java Android 文字转语音男声
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9815245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Text To Speech Male Voice
提问by user1284791
I have a working text to speech but I was wondering instead of a female voice when the app calls it to be played it will do a male voice instead?
我有一个有效的文本到语音,但我想知道当应用程序调用它来播放时,它会用男声代替女声吗?
回答by Nikolay Elenkov
That depends on the underlying TTS engine. Some are configurable and have different voices (male, female, etc.), some only have one voice. In any case, you cannot control this from your app, the user has to change the TTS engine settings from the Settings app. You could only instruct them to install a particular engine, and setup your app to use it.
这取决于底层的 TTS 引擎。有些是可配置的并且有不同的声音(男性、女性等),有些只有一种声音。在任何情况下,您都无法从您的应用程序控制这一点,用户必须从“设置”应用程序更改 TTS 引擎设置。您只能指示他们安装特定引擎,并设置您的应用程序以使用它。
回答by gregm
You cannot make the Android TextToSpeech sounds like a male. If you change the TextToSpeech.setPitch()value to something low, like 0.1, it will sound very bad.
你不能让 Android TextToSpeech 听起来像一个男性。如果将TextToSpeech.setPitch()值更改为较低的值,例如 0.1,听起来会很糟糕。
Your only option is to try another Text-to-Speech engine, or live with the female sounding voice.
您唯一的选择是尝试另一个文本到语音转换引擎,或者与女性的声音一起生活。
回答by Viroj Fernando
It is possible to change voice into male. Set in onCreate()
: tts.setEngineByname("com.google.android.tts")
and make the google tts service default in text to speech settings and instaling the male voice in google tts service.
可以将声音变成男性。设置onCreate()
:tts.setEngineByname("com.google.android.tts")
并在文本到语音设置中使 google tts 服务默认,并在 google tts 服务中安装男声。
Like this you can use any third party android tts services and check the device. Or ask to install.
像这样,您可以使用任何第三方 android tts 服务并检查设备。或者要求安装。
回答by Saad Mahmud
It is now possible to use male/female voice and change it from App UI dynamically. Define TTS like this (add google tts engine in constructor):
现在可以使用男/女声并从 App UI 动态更改它。像这样定义 TTS(在构造函数中添加 google tts 引擎):
tts = new TextToSpeech(context, this, "com.google.android.tts");
contex = activity/app
this= TextToSpeech.OnInitListener
上下文 = 活动/应用
this=TextToSpeech.OnInitListener
From tts.getVoices()
list, chose your desired voice by it's name like this:
从tts.getVoices()
列表中,按名称选择您想要的声音,如下所示:
for (Voice tmpVoice : tts.getVoices()) {
if (tmpVoice.getName().equals(_voiceName)) {
return tmpVoice;
break;
}
}
N.B: U need to set _voiceName
by getting hard coded voice_name from tts.getVoices()
. e.g: for English male it would be: "en-us-x-sfg#male_1-local"
注意:您需要_voiceName
通过从tts.getVoices()
. 例如:对于英国男性,它将是:“en-us-x-sfg#male_1-local”
回答by Dato' Sapik
Either way you can set your android Text-to-Speech to google TTS service by :
无论哪种方式,您都可以通过以下方式将您的 android Text-to-Speech 设置为 google TTS 服务:
tts = new TextToSpeech(context, this, "com.google.android.tts")
, or- Install new male ( English ) voice and set it by default in android.
tts = new TextToSpeech(context, this, "com.google.android.tts")
, 或者- 安装新的男性(英语)语音并在android中默认设置。
Hope it helps.
希望能帮助到你。
回答by Saurabh Gaddelpalliwar
It is possible to change voice into male
可以把声音变男声
here is my code,hope it will help you!
这是我的代码,希望对您有所帮助!
//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);
implements TextToSpeech.OnInitListener on Activity.
在 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!");
}
}
And add this function also:
并添加此功能:
private void speakOut(String message) {
t1.speak(message, TextToSpeech.QUEUE_FLUSH, null);
}