gpt4 book ai didi

java - Freetts 不适用于外部扬声器

转载 作者:行者123 更新时间:2023-11-30 10:35:49 25 4
gpt4 key购买 nike

我在我的 java 应用程序中使用了 Freetts.jar 文件来公布 token 号。我的应用程序在我的笔记本电脑上运行良好,但在我的带有外部扬声器的台式机上无法运行。我得到一个空指针异常。注意:我的两台计算机都使用 Windows 7。

下面的代码是我使用的示例格式。

package tsapp;

import java.util.Locale;
import javax.speech.Central;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerModeDesc;
import javax.swing.JOptionPane;
public class TextSpeech {
public static void main(String[] args){
try
{
System.setProperty("freetts.voices",
"com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");

Central.registerEngineCentral
("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
Synthesizer synthesizer =
Central.createSynthesizer(new SynthesizerModeDesc(Locale.US));
synthesizer.allocate();
synthesizer.resume();
String str;

str=JOptionPane.showInputDialog(null,"Voice Check");
if(str==null)
return;
synthesizer.speakPlainText(str, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
synthesizer.deallocate();
}
catch(Exception e)
{
System.out.println(e.getClass());
e.printStackTrace();
}
}
}

最佳答案

我们可以做一件简单的事情吗:

  1. 下载二进制文件 https://netix.dl.sourceforge.net/project/freetts/FreeTTS/FreeTTS%201.2.2/freetts-1.2.2-bin.zip
  2. 添加到您的项目 enter image description here
  3. 编写简单的代码。

像这样

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;

public class TestVoice {


public static void main(String[] args) {

String text = "Voice check!";

Voice voice;
VoiceManager voiceManager = VoiceManager.getInstance();
voice = voiceManager.getVoice("kevin");
voice.allocate();
voice.speak(text);

}

}

请确保所有这些库也在您的桌面上。

关于java - Freetts 不适用于外部扬声器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40924717/

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