2 回答
TA贡献1772条经验 获得超5个赞
像这样更改 TextToSpeech 构造函数:
public TextToSpeech(String words) {
System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
voice = VoiceManager.getInstance().getVoice("kevin16");
if (voice != null) {
voice.allocate();// Allocating Voice
try {
voice.setRate(190);// Setting the rate of the voice
voice.setPitch(150);// Setting the Pitch of the voice
voice.setVolume(3);// Setting the volume of the voice
SpeakText(words);// Calling speak() method
} catch (Exception e1) {
e1.printStackTrace();
}
} else {
throw new IllegalStateException("Cannot find voice: kevin16");
}
}
这个想法是指示 freetts 使用com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory类而不是AlanVoiceDirectory类。
TA贡献1830条经验 获得超9个赞
代码更改:
而不是以下行
freeVM = VoiceManager.getInstance();
voice = VoiceManager.getInstance().getVoice("kevin16");
修改为
freeVM = VoiceManager.getInstance();
voice = freeVM.getVoice("kevin16");
添加回答
举报