Is it possible to install and configure some male voices on android.speech.tts.Voice
? I have read some news that Android had made some available recently, but I can't find or configure any. All the ones that I try with command tts.setLanguage(Locale.ITALY);
are female.
No, not at present. An enhancement request is needed so that the gender can be included in the Voice Feature Set, such that:
Voice[Name: en-AU-afi-network, locale: en_AU, quality: 500, latency: 400, requiresNetwork: true, features: [networkTimeoutMs, networkRetriesCount, male]]
I have sent emails to Text to Speech providers about including this - as waiting for an enhancement from Google is probably years away.
All you can do in the mean time, is hard-code the name of the engine with a reference to the gender. It's time consuming and there's no guarantee that they won't change the name.... Needs must for me.
To enhance @brandall 's answer, It is possible to use male/female voice and change it from App UI dynamically. Define TTS like this (add 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"
Here I am posting code for select male or female voice using google speech engine.
Set<String> a=new HashSet<>();
a.add("female");//here you can give male if you want to select mail voice.
Voice v=new Voice("en-us-x-sfg#female_2-local",new Locale("en","US"),400,200,true,a);
myTTS.setVoice(v);
Here most take care about Voices name. like "en-us-x-sfg#female_2-local"
You can get all voices by using following method and you can download in file.
myTTS.getVoices() // you can get all voices of male female related information which we can set in Voice.whoever voice we want to listen.(male /female.)
// use this code after onInit success assuming you have initilaised text to speech as tts
Set<Voice> voices = tts.getVoices();
for (Voice tmpVoice : tts.getVoices()) {
if (tmpVoice.getName().contains("#male") && tmpVoice.getName().contains("en-us")) {
voice = tmpVoice;
break;
}
else {
voice = null;
}
}
if (voice != null) {
tts.setVoice(voice);
}
use this code on after on_init
gets successful, do a version check because getVoices()
got added on API level 21
来源:https://stackoverflow.com/questions/36681232/android-tts-male-voices