我正在尝试使用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服务器VM (内部版本20.0-b12,混合模式)
FreeTTS版本1.2.2
为什么它会给出这个错误呢?请帮帮忙
发布于 2012-10-02 15:18:16
可能某些jars链接不正确..当我使用netbeans构建项目时,我就开始工作了!
谢谢大家(@netbeans)..你拯救了我的一天!:)
对于那些可能有相同问题的人,可以使用netbeans来避免库的麻烦。
从"freetts-1.2.2-src.zip“中的"lib”文件夹中添加lib/freetts.jar (可从sf.net)
发布于 2018-11-18 20:14:42
我在下面的Java论坛中找到了一个解决方案:https://community.oracle.com/thread/2182800
尝试设置合成器使用的SystemProperty。
System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
现在它运行得很好!
发布于 2016-10-16 21:01:40
我最近得到了同样的异常,这个异常是因为在你的应用程序中,你在构建路径中添加了JAR,而不是在lib文件夹中。
请将Jars添加到lib文件夹中,即可正常工作。希望能有所帮助。
https://stackoverflow.com/questions/12684627
复制相似问题