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");
添加回答
舉報