【问题标题】:Freetts is not working with external speakersFreetts 无法使用外部扬声器
【发布时间】:2016-12-02 04:16:34
【问题描述】:

我在我的 java 应用程序中使用了 Freetts.jar 文件来宣布令牌编号。我的应用程序在我的笔记本电脑上运行良好,但在我的带有外接扬声器的桌面上运行不正常。我得到一个空指针异常。注意:我的两台电脑都使用 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();
   }
 }
}

【问题讨论】:

  • 你可以使用 MaryTTS ,好多了;)mary.dfki.de
  • 感谢您的建议。但我想知道是什么导致我的应用程序出错。
  • 您能否提供一段正在运行的简单代码,以便我们对其进行测试?可能与资源分配或内部因素有关。

标签: java freetts


【解决方案1】:

我们能不能做一件简单的事情:

  1. 下载二进制文件https://netix.dl.sourceforge.net/project/freetts/FreeTTS/FreeTTS%201.2.2/freetts-1.2.2-bin.zip
  2. 添加到您的项目
  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);

    }

}

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

【讨论】:

  • 谢谢 Saulius 先生。但是你能解释一下我犯的错误吗?
  • 我怀疑您没有将所有库复制到您的桌面。下次请提供例外情况,然后我可以就问题说更多,并尝试编写简单的代码,因为这样您可以获得投注结果。我不是 FreeTTS 的专家,因此我无法评论其他任何内容。
  • 感谢 Saulius 先生的帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多