Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 找不到语音识别jar在其执行语法类上抛出错误_Java_Jar_Cmusphinx - Fatal编程技术网

Java 找不到语音识别jar在其执行语法类上抛出错误

Java 找不到语音识别jar在其执行语法类上抛出错误,java,jar,cmusphinx,Java,Jar,Cmusphinx,我通过Sphinx在JAVA中创建了一个语音识别项目的jar。我的代码执行得很完美,但当我通过“runnable jar file->copy required libraries to sub folder”创建jar,并通过命令“java-jar{jar name}.jar”通过cmd执行它时,它会打开,但在选择speak按钮或调用sphinx方法后,它会给出错误edu.cmu.sphinx.jsapi.JSGFGrammar类找不到。 我没有办法解决这个问题。 我的语音转换代码是: pac

我通过Sphinx在JAVA中创建了一个语音识别项目的jar。我的代码执行得很完美,但当我通过“runnable jar file->copy required libraries to sub folder”创建jar,并通过命令“java-jar{jar name}.jar”通过cmd执行它时,它会打开,但在选择speak按钮或调用sphinx方法后,它会给出错误edu.cmu.sphinx.jsapi.JSGFGrammar类找不到。 我没有办法解决这个问题。 我的语音转换代码是:

package com.ongraph;
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 SpeechToTextOperation {
    ConfigurationManager cm;
    SpeechRecognizer speechRecognizer;
    Result result;
    Recognizer recognizer;
    Microphone microphone;
    private final static String STOP = "stop";
    private final static String XML_FILE = "helloworld.config.xml";

    public void voiceGet() throws InterruptedException {
        String resultString = null;
        int count_Check = 0;
        if (cm == null) {
            cm = new ConfigurationManager(getClass().getClassLoader().getResource(XML_FILE));
        }
        if (recognizer == null) {
            recognizer = (Recognizer) cm.lookup("recognizer");
            microphone = (Microphone) cm.lookup("microphone");
            microphone.clear();
        }
        recognizer.allocate();
        if (!(microphone.startRecording())) {
            System.out.println("Cannot start microphone.");
            recognizer.deallocate();
            System.exit(1);
        }
        instructions();
        //SpeechRecognizer.please_Speak.setVisible(true);
        while (true) {
            System.out
                    .println("Start speaking. Speak 'Stop' to Stop Recording.");
            if(count_Check == 0)
            {
                SpeechRecognizer.textArea.append("\n Start speaking...\n");
                count_Check++;
            }

            Result result = recognizer.recognize();
            resultString = result.getBestFinalResultNoFiller();
            if (resultString != null && !"".equals(resultString)
                    && !resultString.contains(STOP)) {
                SpeechRecognizer.textArea.append(resultString + "\n");
            } else {
                SpeechRecognizer.textArea
                        .append("'Application Stopped. Press 'Speak' again to restart'");
                recognizer.deallocate();
                microphone.stopRecording();
                break;
            }
        }
    }

    public void voiceStop() {
        microphone.clear();
        cm = null;
    }

    public void instructions() {
        // TODO Auto-generated method stub
        SpeechRecognizer.please_Speak.setVisible(true);

    }
}

cmd中的错误包括:

class not found !java.lang.ClassNotFoundException: edu.cmu.sphinx.jsapi.JSGFGrammar
Exception in thread "AWT-EventQueue-0" Property Exception component:'flatLinguist' property:'grammar' - mandatory property is not set!
edu.cmu.sphinx.util.props.InternalConfigurationException
        at edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:291)
        at edu.cmu.sphinx.linguist.flat.FlatLinguist.newProperties(FlatLinguist.java:246)
        at edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:460)
        at edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:279)
        at edu.cmu.sphinx.decoder.search.SimpleBreadthFirstSearchManager.newProperties(SimpleBreadthFirstSearchManager.java:179)
        at edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:460)
        at edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:279)
        at edu.cmu.sphinx.decoder.AbstractDecoder.newProperties(AbstractDecoder.java:65)
        at edu.cmu.sphinx.decoder.Decoder.newProperties(Decoder.java:37)
        at edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:460)
        at edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:279)
        at edu.cmu.sphinx.recognizer.Recognizer.newProperties(Recognizer.java:90)
        at edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:460)
        at edu.cmu.sphinx.util.props.ConfigurationManager.lookup(ConfigurationManager.java:161)
        at com.ongraph.SpeechToTextOperation.voiceGet(SpeechToTextOperation.java:24)
        at com.ongraph.SpeechRecognizer$1.actionPerformed(SpeechRecognizer.java:50)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$400(Unknown Source)
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

总的来说,最好使用最新版本5Realpha和中描述的API

至于您的异常,它说找不到类。为了运行代码,您需要将该类打包到jar中。包名称也可能有所不同。最近,edu.cmu.sphinx.jsapi包被重命名为edu.cmu.sphinx.jsgf。您可能在更新时遇到问题