Java JSAPI:Central.CreateRecognitizer返回null
我是语音识别方面的新手 所以我想运行这样的代码: (原始链接:)Java JSAPI:Central.CreateRecognitizer返回null,java,grammar,voice-recognition,cmusphinx,jsapi,Java,Grammar,Voice Recognition,Cmusphinx,Jsapi,我是语音识别方面的新手 所以我想运行这样的代码: (原始链接:) 照这个做就行了。Sphinx4不再实现Java语音API。此外,我不想使用ANT。不知何故,Sphinx示例(HelloWorld.jar)运行良好。这能证明我有一个语音引擎吗? public class HelloWorld extends ResultAdapter { static Recognizer rec; // Receives RESULT_ACCEPTED event: print it, cl
照这个做就行了。Sphinx4不再实现Java语音API。此外,我不想使用ANT。不知何故,Sphinx示例(HelloWorld.jar)运行良好。这能证明我有一个语音引擎吗?
public class HelloWorld extends ResultAdapter {
static Recognizer rec;
// Receives RESULT_ACCEPTED event: print it, clean up, exit
public void resultAccepted(ResultEvent e) {
Result r = (Result)(e.getSource());
ResultToken tokens[] = r.getBestTokens();
for (int i = 0; i < tokens.length; i++)
System.out.print(tokens[i].getSpokenText() + " ");
System.out.println();
// Deallocate the recognizer and exit
rec.deallocate();
System.exit(0);
}
public static void main(String args[]) {
try {
// Create a recognizer that supports English.
rec = Central.createRecognizer(
new EngineModeDesc(Locale.ENGLISH));
// Start up the recognizer
rec.allocate();
// Load the grammar from a file, and enable it
FileReader reader = new FileReader(args[0]);
RuleGrammar gram = rec.loadJSGF(reader);
gram.setEnabled(true);
// Add the listener to get results
rec.addResultListener(new HelloWorld());
// Commit the grammar
rec.commitChanges();
// Request focus and start listening
rec.requestFocus();
rec.resume();
} catch (Exception e) {
e.printStackTrace();
}
}
}
grammar javax.speech.demo;
public <sentence> = hello world | good morning |
hello mighty computer;