I want java code for text to speech in both male and female voice and after that I want to save that audio to wav file. I tried using this code but its only giving male voice. Please suggest me a way to get female voice without downloading a jar file (just by adding maven dependency or so).
Currently using this code -
try
{
// set property as Kevin Dictionary
System.setProperty("freetts.voices",
"com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
// Register Engine
Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
// Create a Synthesizer
Synthesizer synthesizer = Central.createSynthesizer(new
SynthesizerModeDesc(Locale.US));
// Allocate synthesizer
synthesizer.allocate();
// Resume Synthesizer
synthesizer.resume();
// speaks the given text until queue is empty.
synthesizer.speakPlainText("Hi, this is me. Fine.", null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
// Deallocate the Synthesizer.
synthesizer.deallocate();
}
catch (Exception e) {
e.printStackTrace();
}
and this code -
try {
System.setProperty("FreeTTSSynthEngineCentral", "com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
SynthesizerModeDesc desc = new SynthesizerModeDesc(null, "general", Locale.US, null, null);
Synthesizer synth = Central.createSynthesizer(desc);
synth.allocate();
desc = (SynthesizerModeDesc) synth.getEngineModeDesc();
Voice voice = new Voice();
// "business", "casual", "robotic", "breathy"
voice.setAge(Voice.AGE_TEENAGER);
voice.setGender(Voice.GENDER_FEMALE);
voice.setStyle("breathy");
synth.getSynthesizerProperties().setVoice(voice);
synth.resume();
synth.speakPlainText("Hi, this is me. Fine.", null);
synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
synth.deallocate();
} catch (Exception ex) {
ex.printStackTrace();
}
but both are giving male voices (And there isn't any female voice available in KevinVoiceDirectory).
Use cloud providers: Amazon, Asure, Google, IBM. They all have text to speech services with tutorials and examples available.
Below example of using Asure: