问题
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?
回答1:
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):
tts = new TextToSpeech(context, this, "com.google.android.tts");
contex = activity/app
this= TextToSpeech.OnInitListener
From tts.getVoices()
list, chose your desired voice by it's name like this:
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"
回答2:
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.
@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);
}
回答3:
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.
回答4:
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.
Your only option is to try another Text-to-Speech engine, or live with the female sounding voice.
回答5:
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.
Like this you can use any third party android tts services and check the device. Or ask to install.
回答6:
Either way you can set your android Text-to-Speech to google TTS service by :
tts = new TextToSpeech(context, this, "com.google.android.tts")
, or- Install new male ( English ) voice and set it by default in android.
Hope it helps.
来源:https://stackoverflow.com/questions/9815245/android-text-to-speech-male-voice