2012-10-02 58 views
1

我想使用的FreeTTS,這裏是代碼:的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(); 
} 

}

它編譯罰款,但引發以下運行時錯誤:

[email protected]:~/dev/java/speech/viame-speech$ javac FreeTTSVoice.java 
    [email protected]:~/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 Runtime Environment(Ice dTea6 1.11.3)(6b24-1.11.3-1ubuntu0.12.04.1)

OpenJDK的服務器VM(建設20.0 - B12,混合模式)

版本的FreeTTS 1.2.2

爲什麼給出這個錯誤?請幫助

回答

2

可能有些罐子沒有正確鏈接。 只要我使用netbeans構建項目,就開始工作!

謝謝你們(@netbeans)..你救了我的一天! :)

對於那些可能有同樣問題的人,使用netbeans來避免圖書館的麻煩。

  1. 從 「freetts-1.2.2-src.zip」 「LIB」 添加文件夾的lib/freetts.jar (從sf.net下載)
  2. 添加JDK文件夾(如果尚未上市),將項目庫
  3. 你完成了!現在運行代碼。
0

我得到了同樣的異常最近,這個例外是因爲在你的應用程序,你已經添加在構建路徑的JAR文件,但不能在 lib文件夾中。

請將lib添加到lib文件夾中,它將起作用。 希望它有幫助。