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