我正在尝试使用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(内部版本20.0-b12,混合模式)

FreeTTS版本1.2.2

为什么会出现该错误?请帮忙

最佳答案

可能某些罐子未正确链接。
我使用Netbeans构建项目后就开始工作!

谢谢大家(@netbeans)..你救了我的一天! :)

对于可能遇到相同问题的用户,请使用netbeans以避免麻烦的库。


从“ freetts-1.2.2-src.zip”中的“ lib”文件夹添加lib / freetts.jar
(可从sf.net下载)
将jdk文件夹(如果尚未列出)添加到项目库
大功告成!现在运行代码。

08-03 22:24