Java SaxLoader中的Sphinx4异常
我正在尝试用Java实现语音识别。我一直在遵循教程,并在代码中添加了所需的jar文件和库,但它不起作用。它显示了错误。下面是我的代码Java SaxLoader中的Sphinx4异常,java,cmusphinx,sphinx4,Java,Cmusphinx,Sphinx4,我正在尝试用Java实现语音识别。我一直在遵循教程,并在代码中添加了所需的jar文件和库,但它不起作用。它显示了错误。下面是我的代码 package demo.sphinx.helloworld; import edu.cmu.sphinx.frontend.util.Microphone; import edu.cmu.sphinx.recognizer.Recognizer; import edu.cmu.sphinx.result.Result; import edu.cmu.sphin
package demo.sphinx.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;
import edu.cmu.sphinx.util.props.PropertyException;
import java.io.File;
import java.io.IOException;
import java.net.URL;
/**
* A simple HelloWorld demo showing a simple speech application
* built using Sphinx-4. This application uses the Sphinx-4 endpointer,
* which automatically segments incoming audio into utterances and silences.
*/
public class HelloWorld {
/**
* Main method for running the HelloWorld demo.
* @param args
*/
public static void main(String[] args) {
try {
URL url;
if (args.length > 0) {
url = new File(args[0]).toURI().toURL();
} else {
url = HelloWorld.class.getResource("helloworld.config.xml");
}
System.out.println("Loading...");
ConfigurationManager cm = new ConfigurationManager(url);
Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
Microphone microphone = (Microphone) cm.lookup("microphone");
/* allocate the resource necessary for the recognizer */
recognizer.allocate();
/* the microphone will keep recording until the program exits */
if (microphone.startRecording()) {
System.out.println
("Say: (Good morning | Hello) " +
"( Bhiksha | Evandro | Paul | Philip | Rita | Will )");
while (true) {
System.out.println
("Start speaking. Press Ctrl-C to quit.\n");
/*
* This method will return when the end of speech
* is reached. Note that the endpointer will determine
* the end of speech.
*/
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");
}
}
} else {
System.out.println("Cannot start microphone.");
recognizer.deallocate();
System.exit(1);
}
} catch (IOException e) {
System.err.println("Problem when loading HelloWorld: " + e);
e.printStackTrace();
} catch (PropertyException e) {
System.err.println("Problem configuring HelloWorld: " + e);
e.printStackTrace();
} catch (InstantiationException e) {
System.err.println("Problem creating HelloWorld: " + e);
e.printStackTrace();
}
}
}
我收到的错误消息如下
Exception in thread "main" java.lang.NullPointerException
at edu.cmu.sphinx.util.props.SaxLoader.load(SaxLoader.java:64)
at edu.cmu.sphinx.util.props.ConfigurationManager.loader(ConfigurationManager.java:369)
at edu.cmu.sphinx.util.props.ConfigurationManager.<init>(ConfigurationManager.java:115)
at demo.sphinx.helloworld.HelloWorld.main(HelloWorld.java:48)
线程“main”java.lang.NullPointerException中的异常
位于edu.cmu.sphinx.util.props.SaxLoader.load(SaxLoader.java:64)
位于edu.cmu.sphinx.util.props.ConfigurationManager.loader(ConfigurationManager.java:369)
位于edu.cmu.sphinx.util.props.ConfigurationManager。(ConfigurationManager.java:115)
位于demo.sphinx.helloworld.helloworld.main(helloworld.java:48)
Java结果:1假设您没有给出任何参数。文件
helloworld.config.xml
是否与helloworld
类位置存在于同一文件夹中?假设您没有给出任何参数,下面是正确的教程。文件helloworld.config.xml
是否与helloworld
类位置位于同一文件夹中?下面是正确的教程