首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Freetts不与外部扬声器合作

Freetts不与外部扬声器合作
EN

Stack Overflow用户
提问于 2016-12-02 04:16:34
回答 1查看 489关注 0票数 2

我在我的java应用程序中使用了Freetts.jar文件来宣布令牌号。我的应用程序在我的笔记本电脑上工作得很好,但在有外部扬声器的台式机上却无法工作。我得到一个空指针异常。注意:我在两台电脑上都使用Windows 7。

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

代码语言:javascript
复制
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();
   }
 }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-19 16:59:36

我们能做一件简单的事吗?

  1. 下载二进制https://netix.dl.sourceforge.net/project/freetts/FreeTTS/FreeTTS%201.2.2/freetts-1.2.2-bin.zip
  2. 添加到项目中

  1. 写简单的代码。

像这样

代码语言:javascript
复制
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);

    }

}

只要确保所有这些库都在你的桌面上。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40924717

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档