我正在尝试开发一个程序,使用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发布于 2020-11-08 23:42:09
可能某些jars链接不正确..当我使用netbeans构建项目时,我就开始工作了!
谢谢大家(@netbeans)..你拯救了我的一天!:)
对于那些可能有相同问题的人,可以使用netbeans来避免库的麻烦。
https://stackoverflow.com/questions/64739617
复制相似问题