我对Sphinx演示代码有疑问。当我想实例化一个Robot对象时,程序在实例化行上什么都不做,并且不会继续代码。但该计划仍在运行。
ConfigurationManager cm;
cm = new ConfigurationManager(HelloWorld.class.getResource("helloworld.config.xml"));
Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
recognizer.allocate();
// start the microphone or exit if the programm if this is not possible
Microphone microphone = (Microphone) cm.lookup("microphone");
if (! microphone.startRecording()) {
System.out.println("Cannot start microphone.");
recognizer.deallocate();
System.exit(1);
}
Robot rob = new Robot();
Result result = recognizer.recognize();
if (result != null) {
recognizer.deallocate();
microphone.stopRecording();
String resultText = result.getBestFinalResultNoFiller();
System.out.println("You said: " + resultText + '\n');
} else {
System.out.println("I can't hear what you said.\n");
}
我还试图在一个线程中启动Sphinx代码,并在另一个线程中启动Robot代码。但它有同样的问题。
我认为问题出在线程" Java Sound Event Dispatcher",但我不知道解决它。
没有行Robot rob = new Robot();
,一切正常。