cmusphinx / sphinx4

Pure Java speech recognition library
cmusphinx.sourceforge.net
Other
1.4k stars 587 forks source link

Demo code impossible to instantiate awt.robot object #28

Closed baimard closed 9 years ago

baimard commented 9 years ago

I have a big issue with the Sphinx demo Code. When I want to instantiate à Robot object. the program just do nothing on the instantiation line for Robot object, and doesn't continue the code. But the program is still running.

ConfigurationManager cm;
cm = new       
ConfigurationManager(HelloWorld.class.getResource("helloworld.config.xml"));

Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
recognizer.allocate();

// start the microphone or exit if the programm if this is not possible
Microphone microphone = (Microphone) cm.lookup("microphone");
if (!microphone.startRecording()) {
    System.out.println("Cannot start microphone.");
    recognizer.deallocate();
    System.exit(1);
}

Robot rob = new Robot();

 // loop the recognition until the programm exits.
    System.out.println("Start speaking. Press Ctrl-C to quit.\n");

    Result result = recognizer.recognize();

    if (result != null) {

        recognizer.deallocate();
        microphone.stopRecording();

        String resultText = result.getBestFinalResultNoFiller();
        System.out.println("You said: " + resultText + '\n');

    } else {
        System.out.println("I can't hear what you said.\n");
    }

image

I have also try to launch the Sphinx code in a thread, and the Robot code in an other thread. With this solution I have also the same problem.

I think the problem is with the thread "Java Sound Event Dispatcher" but I have no idea to solve it.

Precision : Without the line Robot rob = new Robot(); All work very fine.

Thank for reading.

nshmyrev commented 9 years ago

If you want to get help on exception you need to provide exception stacktrace.

Also you are using some outdated code it seems, you can find latest API in our tutorial

http://cmusphinx.sourceforge.net/wiki/tutorialsphinx4

baimard commented 9 years ago

I don't understand because the code i used are from github repository sphinx 4. ...