我是语音识别的新手。
所以我想运行这样的代码:(原始链接: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,因为 My System 没有任何合适的语音引擎。所以我尝试了:
- 安装 CMUSphinx。(链接:http ://cmusphinx.sourceforge.net/ )
但是,Sphinx 本身看起来像是一个软件,而不是语音引擎。(我觉得我不知道 . 的确切定义speech engine
。我认为它是一个可以将语音转换为计算机可读数据的软件)。
我下载了 bin.zip 并解压,但我只能运行现成的示例,不能运行引擎本身。现在,我真的找不到任何关于如何运行此示例代码的线索。
反正有运行这个吗?还是我应该为它安装另一个软件?如果是这样,请告诉我。我的操作系统是 OSX Mavericks。
附言
一个额外的小问题:在原始链接中,他们制作了一个定义语法的文件。但他们没有提到文件扩展名。是“.txt”文件还是其他文件?它看起来不像“.java”或“.properties”文件。
文件内容如下:
grammar javax.speech.demo;
public <sentence> = hello world | good morning |
hello mighty computer;