import java.io.*; import java.util.Locale; import java.util.ResourceBundle; import java.util.StringTokenizer; import javax.speech.*; //import javax.speech.recognition.*; import javax.speech.synthesis.*;public class TTS { protected static boolean _DEBUG = true; // debug static Synthesizer synth; static ResourceBundle resources; public TTS() { try { // locale, resources //if (args.length>0) Locale.setDefault(new Locale(args[0], "")); //if (args.length>1) Locale.setDefault(new Locale(args[0], args[1])); // dbg("locale is " + Locale.getDefault()); // create a synthesizer, speak a greeting synth = Central.createSynthesizer(null); // myEngineListener listener = new myEngineListener(); // synth.addEngineListener(listener); synth.allocate(); } catch (Exception e) { e.printStackTrace(); // System.exit(-1); } } // end ctor public static void main(String args[]) { TTS aTTS = new TTS(); aTTS.say("hello this is a test"); } // end main // Cancel output of this Synthesizer and remove all items from the speaking queue. public void cancelAll() { synth.cancelAll(); } public void say(String msg) { int chunkSize = 100; int startPos = 0; int endPos = 0; int pos = 0; while (pos <= msg.length()) { endPos = pos + chunkSize; if (endPos>msg.length()) endPos = msg.length(); sayChunk(msg.substring(pos,endPos)); pos = endPos+1; } } private void sayChunk(String msg) { try { // synthesizer.speak(resources.getString("greeting"), null); if (_DEBUG )System.out.println("SAY > "+msg); mySpeakableListener aSpeakableListener = new mySpeakableListener(); synth.speak(msg, aSpeakableListener); //synth.waitQueueEmpty(); //System.out.println("after"+synth.isQueueEmpty()); //synth.deallocate(); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } } static void dbg(String s) { System.out.println(s); }}class myEngineListener implements EngineListener { public void engineAllocated(EngineEvent e) {System.out.println("engineAllocated");} public void engineDeallocated(EngineEvent e) {System.out.println("engineDeallocated");} public void enginePaused(EngineEvent e) {System.out.println("enginePaused");} public void engineResumed(EngineEvent e) {System.out.println("engineResumed");} }class mySpeakableListener implements SpeakableListener { public void beginSpeakable(SpeakableEvent ev){ System.out.println( "BEGIN_SPEAKABLE event has occurred");} public void cancelSpeakable(SpeakableEvent ev) { System.out.println( "CANCEL_SPEAKABLE event has occurred");} public void endSpeakable(SpeakableEvent ev) { System.out.println( "END_SPEAKABLE event has occurred");} public void erReached(SpeakableEvent ev) { System.out.println( "MARKER_REACHED event has occurred");} public void pauseSpeakable(SpeakableEvent ev) { System.out.println( "PAUSE_SPEAKABLE event has occurred");} public void resumeSpeakable(SpeakableEvent ev) { System.out.println( "RESUME_SPEAKABLE event has occurred");} public void startWord(SpeakableEvent ev) { System.out.println( "START_WORD event has occurred");} public void topOfQueue(SpeakableEvent ev) { System.out.println( "TOP_OF_QUEUE event has occurred");}} // end class
谢谢你,我也觉得依靠IBM是没什么戏了,你尝试过JNI吗?我这边又出了个问题啊, Exception in thread "main" java.lang.UnsatisfiedLinkError: test.WinMsgBox.showMsgBox(Ljava/lang/String;)V at test.WinMsgBox.showMsgBox(Native Method) at test.TestJNI.main(TestJNI.java:12) 我也不知道是哪有问题,能帮忙看看吗?是不是环境没有配置好啊
应该不是吧,你的JAVA本地声明是什么样的?你的代码是什么样的?
hi please refer to INITPORT INC. 音港公司 www.initport.com 专注在语音识别领域(ASR), 提供各个平台的语音识别软件解决方案a 运行在嵌入平台的嵌入式语音识别软件产品 (目前为国内主流手机公司以及手机设计公司提供嵌入式的语音识别解决方案.可以在目前所有的主流手机平台 (从Arm7到Arm9)实现语音识别功能. )b 运行PC机上的桌面系统语音识别软件产品 目已经有盲人上网软件使用了桌面系统的语音识别软件产品c 运行在服务器上的语音识别软件产品 这个主要是针对呼叫中心领域的应用如果有兴趣麻烦 mailto: [email protected]
import javax.speech.synthesis.*;
import java.util.Locale;public class HelloWorld_Synthesis { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
SynthesizerModeDesc temp=new SynthesizerModeDesc(Locale.ENGLISH);
Synthesizer synth=Central.createSynthesizer(temp);
if(synth==null)
synth=Central.createSynthesizer(new SynthesizerModeDesc(Locale.getDefault()));
synth.allocate();
//System.out.println("something is wrong");
synth.resume();
synth.speakPlainText("hello,world!", null);
synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
synth.deallocate();
}catch(Exception e){
e.printStackTrace();
} }}
系统报错:java.lang.NullPointerException
at testSynthesis.HelloWorld_Synthesis.main(HelloWorld_Synthesis.java:19)
即 在rec.allocte()使有空指针错误
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import javax.speech.*;
//import javax.speech.recognition.*;
import javax.speech.synthesis.*;public class TTS {
protected static boolean _DEBUG = true; // debug
static Synthesizer synth;
static ResourceBundle resources; public TTS() {
try {
// locale, resources
//if (args.length>0) Locale.setDefault(new Locale(args[0], ""));
//if (args.length>1) Locale.setDefault(new Locale(args[0], args[1]));
// dbg("locale is " + Locale.getDefault());
// create a synthesizer, speak a greeting
synth = Central.createSynthesizer(null); // myEngineListener listener = new myEngineListener();
// synth.addEngineListener(listener);
synth.allocate();
} catch (Exception e) {
e.printStackTrace();
// System.exit(-1);
} } // end ctor public static void main(String args[]) {
TTS aTTS = new TTS();
aTTS.say("hello this is a test");
} // end main // Cancel output of this Synthesizer and remove all items from the speaking queue.
public void cancelAll() {
synth.cancelAll();
} public void say(String msg) {
int chunkSize = 100;
int startPos = 0;
int endPos = 0;
int pos = 0;
while (pos <= msg.length()) {
endPos = pos + chunkSize;
if (endPos>msg.length()) endPos = msg.length();
sayChunk(msg.substring(pos,endPos));
pos = endPos+1;
}
} private void sayChunk(String msg) { try {
// synthesizer.speak(resources.getString("greeting"), null);
if (_DEBUG )System.out.println("SAY > "+msg);
mySpeakableListener aSpeakableListener = new mySpeakableListener();
synth.speak(msg, aSpeakableListener);
//synth.waitQueueEmpty();
//System.out.println("after"+synth.isQueueEmpty());
//synth.deallocate(); } catch (Exception e) {
e.printStackTrace();
System.exit(-1); }
} static void dbg(String s) {
System.out.println(s);
}}class myEngineListener implements EngineListener {
public void engineAllocated(EngineEvent e) {System.out.println("engineAllocated");}
public void engineDeallocated(EngineEvent e) {System.out.println("engineDeallocated");}
public void enginePaused(EngineEvent e) {System.out.println("enginePaused");}
public void engineResumed(EngineEvent e) {System.out.println("engineResumed");}
}class mySpeakableListener implements SpeakableListener { public void beginSpeakable(SpeakableEvent ev){
System.out.println( "BEGIN_SPEAKABLE event has occurred");} public void cancelSpeakable(SpeakableEvent ev) {
System.out.println( "CANCEL_SPEAKABLE event has occurred");} public void endSpeakable(SpeakableEvent ev) {
System.out.println( "END_SPEAKABLE event has occurred");} public void erReached(SpeakableEvent ev) {
System.out.println( "MARKER_REACHED event has occurred");} public void pauseSpeakable(SpeakableEvent ev) {
System.out.println( "PAUSE_SPEAKABLE event has occurred");} public void resumeSpeakable(SpeakableEvent ev) {
System.out.println( "RESUME_SPEAKABLE event has occurred");} public void startWord(SpeakableEvent ev) {
System.out.println( "START_WORD event has occurred");} public void topOfQueue(SpeakableEvent ev) {
System.out.println( "TOP_OF_QUEUE event has occurred");}} // end class
Exception in thread "main" java.lang.UnsatisfiedLinkError: test.WinMsgBox.showMsgBox(Ljava/lang/String;)V
at test.WinMsgBox.showMsgBox(Native Method)
at test.TestJNI.main(TestJNI.java:12)
我也不知道是哪有问题,能帮忙看看吗?是不是环境没有配置好啊
please refer to INITPORT INC. 音港公司 www.initport.com
专注在语音识别领域(ASR),
提供各个平台的语音识别软件解决方案a 运行在嵌入平台的嵌入式语音识别软件产品
(目前为国内主流手机公司以及手机设计公司提供嵌入式的语音识别解决方案.可以在目前所有的主流手机平台
(从Arm7到Arm9)实现语音识别功能. )b 运行PC机上的桌面系统语音识别软件产品
目已经有盲人上网软件使用了桌面系统的语音识别软件产品c 运行在服务器上的语音识别软件产品
这个主要是针对呼叫中心领域的应用如果有兴趣麻烦
mailto: [email protected]