gpt4 book ai didi

java - FreeTTS 找不到任何声音

转载 作者:行者123 更新时间:2023-11-29 03:42:05 24 4
gpt4 key购买 nike

我正在尝试使用 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 论坛中找到了解决方案:https://community.oracle.com/thread/2182800

尝试设置 Synthesizer 使用的 SystemProperty..

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

现在效果很好!

关于java - FreeTTS 找不到任何声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12684627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com