javasphinx4

Sphinx 4 terrible accuracy


I am trying to get sphinx 4 to work with my desktop application and it gets it right 0% of the time also I'm using the default language models and all that stuff from the sphinx4 data.jar

code:

import edu.cmu.sphinx.api.Configuration;
import edu.cmu.sphinx.api.Microphone;
import edu.cmu.sphinx.api.SpeechResult;
import edu.cmu.sphinx.api.StreamSpeechRecognizer;
public class Speechy {
public static void main(String[] args) throws Exception {

    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/en-us.lm.bin");
    Microphone micro = new Microphone(8000, 16, true, false);
    micro.startRecording();
    StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(configuration);
 // Start recognition process pruning previously cached data.
    recognizer.startRecognition(micro.getStream());
 while(true){
 SpeechResult result = recognizer.getResult();
 System.out.println(result.getHypothesis());
 }
}
}

Solution

  • Microphone micro = new Microphone(8000, 16, true, false);
    

    Default acoustic model requires 16khz audio, your configuration 8000 is wrong.

    See also the tutorial

    The top reasons of the bad accuracy are:

    The mismatch of the sample rate/no. of channels of the incoming audio or the mismatch of the incoming audio bandwidth. It must be 16kHz (or 8kHz, depending on the training data) 16bit Mono (= single channel) Little-Endian file. You need to fix sample rate of the source with resampling (only if its rate is higher than that of the training data). You should not upsample a file and decode it with acoustic models trained on higher sampling rate audio. Audio file format (sampling rate, number of channels) can be verified using below command sox --i /path/to/audio/file. Find more information here: What is sample rate