首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Central.createRecognizer返回null

Central.createRecognizer返回null
EN

Stack Overflow用户
提问于 2014-04-27 08:57:14
回答 1查看 836关注 0票数 0

我是语音识别方面的新手。

所以我想运行这样的代码:(原始链接:http://www.ling.helsinki.fi/~gwilcock/Tartu-2003/L7-Speech/JSAPI/index.html)

代码语言:javascript
复制
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,因为我的系统没有合适的语音引擎。所以我试着:

  • 安装CMUSphinx。(链接:http://cmusphinx.sourceforge.net/)

然而,狮身人面像一个软件,而不是语音引擎本身。(我觉得我不知道speech engine的任何确切定义。我认为这是一种可以将声音传输到计算机可读数据的软件)。

我下载了bin.zip并进行了解压缩,但我只能运行现成的示例,而不能运行引擎本身。现在,我真的找不到关于如何运行这个示例代码的任何线索。

不管怎么说,有这事吗?或者我应该为它安装另一个软件?如果是的话,请告诉我。我的操作系统是OSX小牛。

附注:

还有一个小问题:在原始链接中,他们创建了一个定义语法的文件。但他们没有提到文件的扩展名。是“.txt”文件还是其他文件?它看起来不像'.java‘或'.properties’文件。

文件内容如下:

代码语言:javascript
复制
grammar javax.speech.demo;

public <sentence> = hello world | good morning | 
                                      hello mighty computer;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-27 09:57:30

跟着这个指南。Sphinx4不再实现了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23321359

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档