我正在尝试开发一个使用 java 中的 freetts 将文本转换为语音的程序。我已经添加了所有必需的 jar 文件和构建路径。
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class TextToSpeech {
public static void main(String[] args) {
Voice voice;//Creating object of Voice class
voice = VoiceManager.getInstance().getVoice("kevin");//Getting voice
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
voice.speak("Hello world");//Calling speak() method
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
但面临错误。
Exception in thread "main" java.lang.ClassCastException: class com.sun.speech.freetts.en.us.cmu_time_awb.AlanVoiceDirectory