Freetts无法找到任何声音
-
12-12-2019 - |
题
我正在尝试使用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
为什么它给出那个错误?请帮助
解决方案
可能有些罐子没有正确挂钩.. 一旦我使用NetBeans建立了项目,就开始工作!
谢谢人(@netbeans)..你救了我的一天!:)
对于那些可能具有相同问题的人,使用NetBeans避免库的麻烦。
- 在“fretts-1.2.2-src.zip”中的“lib”文件夹中添加lib / freetts.jar (从 sf.net )
- 将jdk文件夹(如果尚未列出)到项目库
- 你完成了!现在运行代码。
其他提示
我最近得到了同样的例外,这个例外是因为在你的应用程序中,你在构建路径中添加了jar,但不在 lib文件夹。
请在lib文件夹中添加jars,它将工作。 希望它有所帮助。
我在以下java论坛中找到了一个解决方案: https://community.oracle.com/thread/ 2182800
尝试设置SystemProperty哪个合成器使用..
System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
.
现在它很好!
不隶属于 StackOverflow