FreeTTS unable to find any voice

家住魔仙堡 提交于 2019-12-12 09:18:39

问题


I am trying to use FreeTTS, here is the code:

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();
}

}

It compiles fine, but throws the following runtime-error:

    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)

I am using: java version "1.6.0_24"

OpenJDK Runtime Environment (IcedTea6 1.11.3) (6b24-1.11.3-1ubuntu0.12.04.1)

OpenJDK Server VM (build 20.0-b12, mixed mode)

FreeTTS version 1.2.2

Why is it giving that error? Please help


回答1:


Probably some jars were not linked correctly.. Started working as soon as i built the project using netbeans!

Thanks guys (@netbeans).. u saved my day! :)

For those who might be having the same problem, use netbeans to avoid hassle of libraries.

  1. add lib/freetts.jar from "lib" folder in "freetts-1.2.2-src.zip" (downloadable from sf.net)
  2. add jdk folder (if not already listed) to project libraries
  3. You are done! now run the code.



回答2:


I got the same exception recently, this exception is because in your app you have added JARs in build path but not in lib folder.

Please add the Jars in lib folder and it will work. Hope it helps.




回答3:


I found a solution in the following Java Forum: https://community.oracle.com/thread/2182800

try setting SystemProperty which Synthesizer use..

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

Now it works nicely!



来源:https://stackoverflow.com/questions/12684627/freetts-unable-to-find-any-voice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!