Null指针异常配置文件



我正试图通过剖析配置文件来熟悉Sphinx。

不幸的是,我还没能编译它。我使用helloworld示例中相同的类内容,删除了列出的配置文件,并将其替换为http://cmusphinx.sourceforge.net/sphinx4/javadoc/edu/cmu/sphinx/util/props/doc-files/ConfigurationManagement.html

我得到一个空指针异常,不知道为什么。我进口了sphinx4.jar、WSJ_8gau。。。。jar、js.jar和jsapi.jar。我知道它是从配置文件中读取的。当我把它作为时,它正在正确编译

HelloWorld.class.getResource("HelloWorld.config.xml")。以下是经过轻微更改的代码。

package speechcapture;
//import edu.cmu.sphinx.demo.helloworld.HelloWorld;
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 capturespeech {
    public void speechtolist(String[] args){
           ConfigurationManager cm;
            if (args.length > 0) {
                cm = new ConfigurationManager(args[0]);
            } else {
                cm = new ConfigurationManager("testing.config.xml");
            }
            Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
            recognizer.allocate(); //Where error occurs
            // start the microphone or exit if the program 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 program 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");
                }
         }      
    }   
}

识别器在以下行为空:

        Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
        recognizer.allocate(); //Where error occurs

因为在配置xml文件中缺少名为"identifier"的组件。更新XML文件时,请检查代码是否同步。

有关更多详细信息,请参阅原始讨论:

https://sourceforge.net/p/cmusphinx/discussion/sphinx4/thread/91efe5b7/?limit=25#52da

相关内容

最新更新