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");
            }
        }
    }
}

while i try to run this program 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.<init>(ConfigurationManager.java:58)
    at HelloWorld.main(HelloWorld.java:22)

Please suggest...

Thanks

Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87
PradeepBhati
  • 63
  • 1
  • 3
  • 11

3 Answers3

3

i had the same error and fixed it. you simply will find a HelloWord.jar file in sphinx bin folder just include the jar file to your project and it will run normally


the path for the jar file : sphinx4-1.0beta6-bin\sphinx4-1.0beta6\bin\HelloWorld.jar

2

If you are using the src version, make sure you have lib/sphinx4.jar if not go to the top directory (sphinx4.0beta-src, for example) and type ant.

Then you can run it typing :

sphinx4> java -mx256m -jar bin/HelloWorld.jar

If you want more information go :CMU-Sphinx-Helloword

karensantana
  • 1,599
  • 4
  • 21
  • 34
2

It's not clear which line is actually line 22 in your code, but I suspect it's this:

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

My guess is that helloworld.config.xml can't be found, so getResource is returning null, which you're passing to the ConfigurationManager.

There are various reasons why the config may not be found, such as:

  • It's not on the classpath (e.g. not bundled into a jar file, not copied to the bin directory by Eclipse)
  • It's not in the right place - that code will try to find it relative to HelloWorld.class, whereas you might have it in the "package root"

It's hard to say any more without more information from you.

Assuming that is the case, it has nothing to do with Sphinx.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194