【问题标题】:FreeTTS unable to find any voiceFreeTTS 找不到任何声音
【发布时间】:2012-09-22 23:20:06
【问题描述】:

我正在尝试使用 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 服务器虚拟机(build 20.0-b12,混合模式)

FreeTTS 1.2.2 版

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

【问题讨论】:

    标签: java text-to-speech freetts


    【解决方案1】:

    可能有些罐子没有正确链接.. 我使用 netbeans 构建项目后立即开始工作!

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

    对于那些可能遇到同样问题的人,请使用 netbeans 以避免库的麻烦。

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

    【讨论】:

      【解决方案2】:

      我最近遇到了同样的异常,这个异常是因为在您的应用中,您在构建路径中添加了 JAR,但没有在 lib 文件夹。

      请在 lib 文件夹中添加罐子,它将起作用。 希望对您有所帮助。

      【讨论】:

        【解决方案3】:

        我在以下 Java 论坛中找到了解决方案:https://community.oracle.com/thread/2182800

        尝试设置合成器使用的 SystemProperty..

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

        现在效果很好!

        【讨论】:

          猜你喜欢
          • 2014-12-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-05-22
          • 2011-12-22
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多