Reputation: 179
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?
Upvotes: 14
Views: 44614
Reputation: 306
This worked for me
const allVoices = await Tts.voices()
const maleVoice = allVoices.filter(item => item.id === "hi-in-x-hie-local")
Tts.setDefaultVoice(maleVoice[0].id)
Tts.speak("Read My Text")
Upvotes: 0
Reputation: 338
I found 3 Male voices in google tts
Use these in the following way:
textToSpeechEngine.voice = Voice("hi-in-x-hie-local", Locale("hi_IN"), 400, 200, false, HashMap<String>())
Upvotes: 1
Reputation: 7437
Contrary to some previous answers, gender is not a parameter (or even a "feature") of a Voice object.
As you can see... as of 5/2021, there is no "isMale" boolean parameter.
There is a "features" Set<String> parameter, but what those strings actually contain is engine dependent and extremely poorly documented and/or implemented... and no engines describe gender using this parameter that I know of.
TextToSpeech.setVoice() is designed such that the Voice being set must be an exact match/instance of one of the Voice objects that was previously returned by TextToSpeech.getVoices() -- it is not a way to somehow create/request a new custom Voice or to attempt to mix and match parameters. (That's not to say some engines won't try to make a best approximation of the non-existent new voice you try to send to it).
Even if gender were implemented, Voice parameters are not designed to be independently settable.
Voice objects are a means by which an engine can describe its available voices using getVoices() -- they are not the voices themselves.
As far as I can tell, the Voice class' constructor is really not useful to anyone other than a speech engine developer.
All of this means that unless the authors of a specific engine have chosen to include "male" or "female" as a substring of the voice's name, there is no way for you to determine whether a voice sounds male or female other than listening to it first.
So, in order to control whether speech output "is" male/female, all the following would have to be true:
PS - Even if you think you've found a male voice, it could actually be a female that just sounds male to you. :)
PPS - You could use a cloud service instead to remove all the device unpredictability.
Upvotes: 2
Reputation: 1645
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);
}
Upvotes: 7
Reputation: 11
Either way you can set your android Text-to-Speech to google TTS service by :
tts = new TextToSpeech(context, this, "com.google.android.tts")
, orHope it helps.
Upvotes: 0
Reputation: 3019
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"
Upvotes: 17
Reputation: 461
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.
Upvotes: 0
Reputation: 12159
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.
Upvotes: 3
Reputation: 52936
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.
Upvotes: 2