0

I build new language model , acoustic model and dictionary. when I try to recognize wav file speech, I got

Exception in thread "main" java.lang.NullPointerException at edu.cmu.sphinx.result.Lattice.getNodeID

Here Is my code,

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);
}

My consol shows,

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)

(I removed more than 100 " =============null " lines due to space redundancy)

Tomasz Jakub Rup
  • 10,502
  • 7
  • 48
  • 49

2 Answers2

0

Your main loop is incorrect. If you take a look at the sample code you will see that AbstractSpeechRecognizer#getResult() is a state-changing call, so you cannot method it twice to get the same object. Instead, the valid loop in your case would be:

SpeechResult result;
while ((result = recognizer.getResult() != null) {
  // do something with result
}
Alexander Solovets
  • 2,447
  • 15
  • 22
  • Sorry I put this " while (true) " loop to check the result . My problem is ` recognizer.getResult() ` is null. did not take any result as output . – Suranga Premakumara Dec 08 '15 at 06:32
  • It also seems that the version of sphinx4 you use I outdated. In the latest version `an4.lm` is absent, and there is `en-us.lm.bin` instead. – Alexander Solovets Dec 08 '15 at 07:15
  • I use my self created language model,acoustic model and Dictionary. an4 .lm is name i just use to compile easily. now I convert it fo binary format and no error or warning , But recognizer.getResult() is null. https://plus.google.com/u/0/photos/albums/pr4v5mtbrntd4gs6r5r9k3djpnmfhdoua?pid=6225855586348275634&oid=104810041778367537512 – Suranga Premakumara Dec 08 '15 at 12:44
  • Probably that's because your audio is not recognized. Can you share it? – Alexander Solovets Dec 08 '15 at 19:41
  • Thank you for helping me Alexander. Here is the link for my acoustic model (ect folder contain dic and language model) https://drive.google.com/file/d/0B6VUxeXOnMe7SW03UGl5R0tLMUk/view?usp=sharing – Suranga Premakumara Dec 09 '15 at 06:39
0

You incorrectly trained your acoustic model. You trained it from stereo, audio for training must be mono.

Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87
  • I tried with Mono audios it also gives me same result. https://lh4.googleusercontent.com/-aHkYaDTa4L0/VmfK2CLfQnI/AAAAAAAABF4/AbSVM_WwlMw/w896-h216-no/adio.png – Suranga Premakumara Dec 09 '15 at 06:44