Pregunta

I am new in Voice recognition.

So I want to run a code like this : (Original Link : 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();
        }
    }
}

The problem is Central.createRecognizer returns null.

According to API, this method returns null since My System does not have any suitable speech engine. So I tried :

However, Sphinx seems like a software not speech engine itself.(I feel like I do not know any exact definition of speech engine. I think it is a software that can transfer voice to computer readable data).

I downloaded bin.zip and extract, but I can run only ready-made examples not engine itself. Now, I really can not find any clues for how to run this sample code.

Is there anyway to run this? Or should I install another software for it? If so, let me know. My OS is OSX Mavericks.

P.S.

A Small additional Question : In the Original link, they made a file which defines a grammar. But they did not mention about extension of file. Is it '.txt' file or other? It does not look like '.java' or '.properties' file.

file contents like below :

grammar javax.speech.demo;

public <sentence> = hello world | good morning | 
                                      hello mighty computer;
¿Fue útil?

Solución

Just follow this guide. Sphinx4 does not implement Java Speech API anymore.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top