1

Hi i am making a software in java in which i want to develop a speech software... I am running a "Hello" sphinx code in java:

import edu.cmu.sphinx.frontend.util.Microphone; 
import edu.cmu.sphinx.recognizer.Recognizer; 
import edu.cmu.sphinx.result.Result; 
import edu.cmu.sphinx.util.props.ConfigurationManager;

public class HelloWorld {

public static void main(String[] args) {
    ConfigurationManager cm;

    if (args.length > 0) {
        cm = new ConfigurationManager(args[0]);
    } else {
        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);
    }

    System.out.println("Say: (Good morning | Hello) ( Bhiksha | Evandro | Paul | Philip | Rita | Will )");

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

        Result result = recognizer.recognize();

        if (result != null) {
            String resultText = result.getBestFinalResultNoFiller();
            System.out.println("You said: " + resultText + '\n');
        } else {
            System.out.println("I can't hear what you said.\n");
        }
    }
}

}

i got this error...

Exception in thread "main" java.lang.NullPointerException at 
edu.cmu.sphinx.util.props.SaxLoader.load(SaxLoader.java:74) at 
edu.cmu.sphinx.util.props.ConfigurationManager.(ConfigurationManager.java:58) at 
HelloWorld.main(HelloWorld.java:22)

I've added the HelloWord.jar file to my project, but i still having the same result! Please sugest...

Ankur
  • 12,676
  • 7
  • 37
  • 67
karensantana
  • 1,599
  • 4
  • 21
  • 34
  • line 22: cm = new ConfigurationManager(HelloWorld.class.getResource("helloworld.config.xml")); – karensantana Nov 10 '12 at 18:29
  • 1
    I think that code `HelloWorld.class.getResource("helloworld.config.xml")` is returning null – Ankur Nov 10 '12 at 18:30
  • yes i know but is returning null 'cause can not find Helloworld.jar but i've added to my project! – karensantana Nov 10 '12 at 18:34
  • 1
    refer this question http://stackoverflow.com/questions/944610/how-do-i-access-a-config-file-inside-the-jar – Ankur Nov 10 '12 at 18:35
  • i want to know in which folder i have to add Helloword.jar... in the src or my package? – karensantana Nov 10 '12 at 18:36
  • 1
    you need to include it in classpath. For more info : http://stackoverflow.com/questions/2096283/including-jars-in-classpath-on-commandline-javac-or-apt – Ankur Nov 10 '12 at 18:37

1 Answers1

1

getResource("helloworld.config.xml") is pointing to null. Check if the file where the url is pointing at is configured properly. Make sure it is on your classpath.

Yves_T
  • 1,170
  • 2
  • 10
  • 16