我正在尝试使用FreeTTS,这是代码:
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class FreeTTSVoice {
public static final String VOICE_ALAN = "alan";
public static final String VOICE_KEVIN = "kevin";
public static final String VOICE_KEVIN16 = "kevin16";
private Voice voice;
public FreeTTSVoice(String voiceName) {
VoiceManager voiceManager = VoiceManager.getInstance();
voice = voiceManager.getVoice(voiceName);
if (voice == null) {
System.err.println(
"Cannot find a voice named "
+ voiceName + ". Please specify a different voice.");
System.exit(1);
}
}
public void speak(String msg) {
voice.speak(msg);
}
public void open() {
voice.allocate();
}
public void close() {
voice.deallocate();
}
public static void main(String[] args) {
System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
FreeTTSVoice me = new FreeTTSVoice(FreeTTSVoice.VOICE_KEVIN);
me.open();
me.speak("Hello java is smart. isn't is?");
me.close();
}
}
编译正常,但会抛出以下运行时错误:
pkswatch@neurals:~/dev/java/speech/viame-speech$ javac FreeTTSVoice.java
pkswatch@neurals:~/dev/java/speech/viame-speech$ java FreeTTSVoice
Exception in thread "main" java.lang.Error: Unable to load voice directory.java.lang.ClassNotFoundException: com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory
at com.sun.speech.freetts.VoiceManager.getVoiceDirectories(VoiceManager.java:198)
at com.sun.speech.freetts.VoiceManager.getVoices(VoiceManager.java:110)
at com.sun.speech.freetts.VoiceManager.getVoice(VoiceManager.java:502)
at FreeTTSVoice.<init>(FreeTTSVoice.java:15)
at FreeTTSVoice.main(FreeTTSVoice.java:39)
我正在使用: java版“1.6.0_24”
OpenJDK运行时环境(IcedTea6 1.11.3)(6b24-1.11.3-1ubuntu0.12.04.1)
OpenJDK Server VM(build 20.0-b12,混合模式)
FreeTTS 1.2.2版
为什么会出错?请帮忙
答案 0 :(得分:2)
可能有些罐子没有正确连接.. 我使用netbeans建立项目后立即开始工作!
谢谢你们(@netbeans)..你救了我的一天! :)
对于那些可能遇到同样问题的人,请使用netbeans来避免图书馆的麻烦。
答案 1 :(得分:1)
我最近得到了同样的异常,这个例外是因为在你的应用中你已经在构建路径中添加了JAR但是没有 lib文件夹。
请在lib文件夹中添加Jars,它会起作用。 希望它有所帮助。
答案 2 :(得分:1)
我在以下Java论坛中找到了一种解决方案:https://community.oracle.com/thread/2182800
尝试设置合成器使用的SystemProperty。
System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
现在效果很好!