1

我试图通过剖析配置文件来熟悉 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");
                }
         }      
    }   
}
4

1 回答 1

0

此行上的识别器为空:

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

因为配置 xml 文件中缺少名为“recognizer”的组件。当您更新 XML 文件时,请检查代码是否同步。

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

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

于 2013-07-11T16:47:45.000 回答