线程" main"中的例外情况java.lang.NoSuchFieldError:engineListeners

时间:2016-12-28 04:39:25

标签: java speech-recognition

我正在写一个语音识别程序,我遇到了这个错误。

我尝试过的事情:

调试并重新运行程序

检查库中是否有重复的罐子

我真的很困惑?有人可以帮忙吗? 顺便说一下,完整的错误是:

  

线程中的异常" main" java.lang.NoSuchFieldError:engineListeners     在   com.sun.speech.engine.recognition.BaseRecognizer.fireRecognizerSuspended(BaseRecognizer.java:977)     在   com.sun.speech.engine.recognition.BaseRecognizer.dispatchSpeechEvent(BaseRecognizer.java:1273)     在   com.sun.speech.engine.SpeechEventUtilities.postSpeechEvent(SpeechEventUtilities.java:201)     在   com.sun.speech.engine.SpeechEventUtilities.postSpeechEvent(SpeechEventUtilities.java:132)     在   com.sun.speech.engine.recognition.BaseRecognizer.postRecognizerSuspended(BaseRecognizer.java:965)     在   com.sun.speech.engine.recognition.BaseRecognizer.commitChanges(BaseRecognizer.java:375)     在   edu.cmu.sphinx.jsapi.JSGFGrammar.createGrammar(JSGFGrammar.java:288)     在   edu.cmu.sphinx.linguist.language.grammar.Grammar.allocate(Grammar.java:123)     在   edu.cmu.sphinx.linguist.flat.FlatLinguist.allocate(FlatLinguist.java:225)     在   edu.cmu.sphinx.decoder.search.SimpleBreadthFirstSearchManager.allocate(SimpleBreadthFirstSearchManager.java:576)     在edu.cmu.sphinx.decoder.Decoder.allocate(Decoder.java:109)at   edu.cmu.sphinx.recognizer.Recognizer.allocate(Recognizer.java:182)at   demo.sphinx.speech.Program.main(Program.java:71)

以下是代码:

public static void main(String[] args) {

    try {
        URL url;
        if (args.length > 0) {
            url = new File(args[0]).toURI().toURL();
        } else {
            url = Program.class.getResource("SpeechConfig.config.xml");
        }

        System.out.println("Loading...");

        ConfigurationManager cm = new ConfigurationManager(url);

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

        Microphone microphone = (Microphone) cm.lookup("microphone");
        recognizer.allocate();

        if (microphone.startRecording()) {

            System.out.println
            ("Listening");

            while (true) {

                Result result = recognizer.recognize();

                if (result != null) {
                    resultText = result.getBestFinalResultNoFiller();

                } else {
                    System.out.println("I can't hear what you said.\n");
                }
            }
        } else {
            System.out.println("Cannot start microphone.");
            recognizer.deallocate();
            System.exit(1);
        }
    } catch (IOException e) {
        System.err.println("Problem when loading Program: " + e);
        e.printStackTrace();
    } catch (PropertyException e) {
        System.err.println("Problem configuring Program: " + e);
        e.printStackTrace();
    } catch (InstantiationException e) {
        System.err.println("Problem creating Program: " + e);
        e.printStackTrace();

    }

}

0 个答案:

没有答案