Freetts不适用于外部扬声器 [英] Freetts is not working with external speakers

查看:130
本文介绍了Freetts不适用于外部扬声器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java应用程序中使用了Freetts.jar文件来声明令牌号.我的应用程序可以在笔记本电脑上正常运行,但不能在带有外接扬声器的桌面上运行.我得到一个空指针异常.注意:我在两台计算机上都使用Windows 7.

I have used Freetts.jar file in my java application that announces the token number. My application is working perfectly in my laptop but is not working in my desktop that has an external speaker. I get a null pointer exception. NOTE: I use Windows 7 in both my computers.

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

The Below Code is the Sample Format I used.

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. 添加到您的项目
  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);

    }

}

只需确保所有这些库也都在您的桌面上.

Just be sure that all these libs are on your desktop too.

这篇关于Freetts不适用于外部扬声器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆