我想要男性和女性语音的文本到语音的java代码,之后我想将该音频保存到wav文件。我尝试使用此代码,但它只给出男性声音。请建议我一种无需下载 jar 文件即可获得女性声音的方法(只需添加 maven 依赖项左右)。
目前使用此代码 -
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();
}
而这段代码 -
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();
}
但两者都发出男性声音(并且 KevinVoiceDirectory 中没有任何女性声音)。