我试图通过剖析配置文件来熟悉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");
}
}
}
}
答案 0 :(得分:0)
此行上的识别器为空:
Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
recognizer.allocate(); //Where error occurs
因为config xml文件中缺少名为“Recognizer”的组件。更新XML文件时,请检查代码是否同步。
有关详细信息,请参阅原始讨论:
https://sourceforge.net/p/cmusphinx/discussion/sphinx4/thread/91efe5b7/?limit=25#52da