我建立了新的语言模型、声学模型和字典。当我尝试识别 wav 文件语音时,我得到了
edu.cmu.sphinx.result.Lattice.getNodeID 处的线程“主”java.lang.NullPointerException 中的异常
这是我的代码,
try {
Configuration configuration = new Configuration();
configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
configuration.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/an4.lm");
configuration.setSampleRate(16000);
StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(configuration);
InputStream stream = new FileInputStream(new File("E:\\Level4\\finalpjt\\mytesting\\Audiorecording\\Sachini_New\\1-39\\SentNum_13.wav"));
recognizer.startRecognition(stream);
startRecognition(false).
while (true) {
System.out.println("=============" + recognizer.getResult());
SpeechResult result = recognizer.getResult();
if (result != null) {
System.out.println(result.getHypothesis());
}
}
} catch (IOException ex) {
Logger.getLogger(SpeechTest.class.getName()).log(Level.SEVERE, null, ex);
System.out.println(ex);
}
我的控制台显示,
23:44:14.069 INFO unitManager CI Unit: th
23:44:14.069 INFO unitManager CI Unit: u
23:44:14.069 INFO unitManager CI Unit: uu
23:44:14.070 INFO unitManager CI Unit: v
23:44:14.070 INFO unitManager CI Unit: y
23:44:14.074 INFO autoCepstrum Cepstrum component auto-configured as follows: autoCepstrum {MelFrequencyFilterBank, Denoise, DiscreteCosineTransform2, Lifter}
23:44:14.084 INFO dictionary Loading dictionary from: jar:file:/C:/Users/Suranga/Downloads/sphinx4-data-5prealpha-20151205.160456-3-sources.jar!/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict
23:44:14.092 INFO dictionary Loading filler dictionary from: jar:file:/C:/Users/Suranga/Downloads/sphinx4-data-5prealpha-20151205.160456-3-sources.jar!/edu/cmu/sphinx/models/en-us/en-us/noisedict
23:44:14.093 INFO acousticModelLoader Loading tied-state acoustic model from: jar:file:/C:/Users/Suranga/Downloads/sphinx4-data-5prealpha-20151205.160456-3-sources.jar!/edu/cmu/sphinx/models/en-us/en-us
23:44:14.093 INFO acousticModelLoader Pool means Entries: 126
23:44:14.093 INFO acousticModelLoader Pool variances Entries: 126
23:44:14.093 INFO acousticModelLoader Pool transition_matrices Entries: 42
23:44:14.093 INFO acousticModelLoader Pool senones Entries: 126
23:44:14.093 INFO acousticModelLoader Gaussian weights: mixture_weights. Entries: 126
23:44:14.093 INFO acousticModelLoader Pool senones Entries: 126
23:44:14.094 INFO acousticModelLoader Context Independent Unit Entries: 42
23:44:14.094 INFO acousticModelLoader HMM Manager: 42 hmms
23:44:14.094 INFO acousticModel CompositeSenoneSequences: 0
23:44:14.520 INFO lexTreeLinguist Max CI Units 43
23:44:14.520 INFO lexTreeLinguist Unit table size 79507
23:44:14.523 INFO speedTracker # ----------------------------- Timers----------------------------------------
23:44:14.523 INFO speedTracker # Name Count CurTime MinTime MaxTime AvgTime TotTime
23:44:14.524 INFO speedTracker Load Dictionary 1 0.0100s 0.0100s 0.0100s 0.0100s 0.0100s
23:44:14.525 INFO speedTracker Compile 1 0.3580s 0.3580s 0.3580s 0.3580s 0.3580s
23:44:14.525 INFO speedTracker Load AM 1 0.0270s 0.0270s 0.0270s 0.0270s 0.0270s
=============null
23:44:14.665 INFO liveCMN 32.76 20.66 12.53 -1.97 8.54 -9.36 7.33 4.56 1.57 -4.28 -1.49 -5.17 -4.31
=============null
23:44:14.707 INFO liveCMN 32.86 20.80 12.57 -2.03 8.65 -9.69 7.31 4.69 1.67 -4.50 -1.42 -5.07 -4.33
=============null
23:44:14.725 INFO speedTracker This Time Audio: 3.41s Proc: 0.11s Speed: 0.03 X real time
23:44:14.726 INFO speedTracker Total Time Audio: 3.41s Proc: 0.11s 0.03 X real time
23:44:14.726 INFO memoryTracker Mem Total: 200.50 Mb Free: 154.22 Mb
23:44:14.726 INFO memoryTracker Used: This: 46.28 Mb Avg: 46.28 Mb Max: 46.28 Mb
=============null
23:44:14.754 INFO liveCMN 34.64 22.84 11.95 -3.18 14.37 -9.93 9.45 7.52 6.26 -7.74 -1.53 -6.11 -5.65
=============null
23:44:14.779 INFO speedTracker This Time Audio: 0.99s Proc: 0.04s Speed: 0.04 X real time
23:44:14.780 INFO speedTracker Total Time Audio: 4.40s Proc: 0.15s 0.03 X real time
23:44:14.781 INFO memoryTracker Mem Total: 200.50 Mb Free: 129.66 Mb
23:44:14.782 INFO memoryTracker Used: This: 70.84 Mb Avg: 58.56 Mb Max: 70.84 Mb
Exception in thread "main" java.lang.NullPointerException
at edu.cmu.sphinx.result.Lattice.getNodeID(Lattice.java:330)
at edu.cmu.sphinx.result.Lattice.<init>(Lattice.java:171)
at edu.cmu.sphinx.api.SpeechResult.<init>(SpeechResult.java:38)
at edu.cmu.sphinx.api.AbstractSpeechRecognizer.getResult(AbstractSpeechRecognizer.java:61)
at etypes.SpeechTest.main(SpeechTest.java:42)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
(由于空间冗余,我删除了 100 多个“ =============null ”行)