I recorded a wav file using Audacity for testing transcriber demo from Sphinx-4, I followed the instruction in this post: Sphinx4 speech recognition trasncribe demo not working accurately for short wav file
especially in this answer:
It must be 16khz 16bit mono little-endian file.
I even reduced the noise afterward. But I get the null error when I try to print the hypothesis which mean there was a problem with my recording:
Loading models...
Exception in thread "main" java.lang.NullPointerException
at transcriber.Transcriber.main(Transcriber.java:41)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 minutes 14 seconds)
Line 41 where I print the hypothesis. what can I do to get it work? Thanks
Edit: The code is:
package transcriber;
import java.net.URL;
import edu.cmu.sphinx.api.Configuration;
import edu.cmu.sphinx.api.SpeechResult;
import edu.cmu.sphinx.api.StreamSpeechRecognizer;
import edu.cmu.sphinx.result.WordResult;
/**
*
* @author ha
*/
public class Transcriber {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
System.out.println("Loading models...");
Configuration configuration = new Configuration();
// Load model from the jar
configuration.setAcousticModelPath("resource:/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz");
configuration.setDictionaryPath("resource:/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz/dict/cmudict.0.6d");
configuration.setLanguageModelPath("models/language/en-us.lm.dmp");
StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(configuration);
URL audioUrl = new URL("file:WAV/Hello.wav");
recognizer.startRecognition(audioUrl.openStream());
SpeechResult result = recognizer.getResult();
System.out.println(recognizer.getResult().getHypothesis());
while ((result = recognizer.getResult()) != null) {
System.out.format("Hypothesis: %s\n",
result.getHypothesis());
}
System.out.println("Stop Recognition..");
recognizer.stopRecognition();
}
}