的FreeTTS无法找到任何声音(FreeTTS unable to find any voice)

2019-08-01 02:16发布

我想使用的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

为什么给这个错误? 请帮忙

Answer 1:

也许有些罐子无法正确链接..开始,只要我建使用NetBeans项目工作!

谢谢你们(@netbeans)..ü救了我的天! :)

对于那些谁可能有同样的问题,使用NetBeans避免库的麻烦。

  1. 从在“freetts-1.2.2-src.zip” “LIB”文件夹添加LIB / freetts.jar(来自下载的sf.net )
  2. 添加JDK文件夹(如果尚未上市),将项目库
  3. 你完成了! 现在运行代码。


Answer 2:

我得到了同样的异常最近,这个例外是因为在你的应用程序,你已经添加在构建路径的JAR文件,但不是在lib文件夹中。

请lib文件夹中添加的罐子,它会工作。 希望能帮助到你。



Answer 3:

我发现下面的Java论坛的解决方案: https://community.oracle.com/thread/2182800

尝试设置SystemProperty该综合使用..

System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");

现在,它很好地工作!



文章来源: FreeTTS unable to find any voice