我是语音识别方面的新手。
所以我想运行这样的代码:(原始链接:http://www.ling.helsinki.fi/~gwilcock/Tartu-2003/L7-Speech/JSAPI/index.html)
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();
}
}
}问题是Central.createRecognizer返回null。
根据API,该方法返回null,因为我的系统没有合适的语音引擎。所以我试着:
然而,狮身人面像一个软件,而不是语音引擎本身。(我觉得我不知道speech engine的任何确切定义。我认为这是一种可以将声音传输到计算机可读数据的软件)。
我下载了bin.zip并进行了解压缩,但我只能运行现成的示例,而不能运行引擎本身。现在,我真的找不到关于如何运行这个示例代码的任何线索。
不管怎么说,有这事吗?或者我应该为它安装另一个软件?如果是的话,请告诉我。我的操作系统是OSX小牛。
附注:
还有一个小问题:在原始链接中,他们创建了一个定义语法的文件。但他们没有提到文件的扩展名。是“.txt”文件还是其他文件?它看起来不像'.java‘或'.properties’文件。
文件内容如下:
grammar javax.speech.demo;
public <sentence> = hello world | good morning |
hello mighty computer;发布于 2014-04-27 09:57:30
跟着这个指南。Sphinx4不再实现了。
https://stackoverflow.com/questions/23321359
复制相似问题