我已经从http://cmusphinx.sourceforge.net/wiki/tutorialsphinx4
运行了StreamSpeechRecognizer示例但得到以下错误:
Exception in thread "main" java.lang.IllegalStateException: Expected state READY actual state DEALLOCATED
at edu.cmu.sphinx.recognizer.Recognizer.checkState(Recognizer.java:137)
at edu.cmu.sphinx.recognizer.Recognizer.recognize(Recognizer.java:106)
at edu.cmu.sphinx.recognizer.Recognizer.recognize(Recognizer.java:125)
at edu.cmu.sphinx.api.AbstractSpeechRecognizer.getResult(AbstractSpeechRecognizer.java:50)
at com.mbi.ciolab.vpa.speech.sphinx4.StreamSpeechRecognizerTest.main(StreamSpeechRecognizerTest.java:37)
代码如下:
public static void main(String[] args) throws IOException {
Configuration configuration = new Configuration();
// Set path to acoustic model.
//configuration.setAcousticModelPath("resource:/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz");
// Set path to dictionary.
//configuration.setDictionaryPath("resource:/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz/dict/cmudict.0.6d");
// Set language model.
// Set path to acoustic model.
configuration.setAcousticModelPath("models/acoustic/wsj_8kHz");
// Set path to dictionary.
configuration.setDictionaryPath("models/acoustic/wsj_8kHz/dict/cmudict.0.6d");
configuration.setLanguageModelPath("models/language/en-us.lm.dmp");
StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(configuration);
recognizer.startRecognition(new FileInputStream(new File("data/test.wav")));
//recognizer.startRecognition(new FileInputStream(new File("speech.wav")));
SpeechResult result = recognizer.getResult();
recognizer.stopRecognition();
while ((result = recognizer.getResult()) != null) {
System.out.println(result.getHypothesis());
}
}