-1

I want to create a speech recognition project in java and I try to use sphinx cmu. I use this code for recognition of speech but don't give me a good response. How I can fix this?

import java.io.IOException;
import java.net.URL;

import edu.cmu.sphinx.api.Configuration;
import edu.cmu.sphinx.api.Context;
import edu.cmu.sphinx.api.LiveSpeechRecognizer;
import edu.cmu.sphinx.api.SpeechResult; 
import edu.cmu.sphinx.api.StreamSpeechRecognizer;
import edu.cmu.sphinx.result.WordResult;

public class App 
{
    public static void main( String[] args ) throws IOException
    {
        Configuration configuration = new Configuration();

        // Set path to acoustic model.
        configuration
            .setAcousticModelPath("resource:/WSJ_8gau_13dCep_8kHz_31mel_200Hz_3500Hz");
        // Set path to dictionary.
        configuration
            .setDictionaryPath("resource:/WSJ_8gau_13dCep_8kHz_31mel_200Hz_3500Hz/dict/cmudict.0.6d");
        // Set language model.
        configuration.setLanguageModelPath("resource:/edu/cmu/sphinx/models/language/en-us.lm.dmp");

        LiveSpeechRecognizer recognizer = new LiveSpeechRecognizer(configuration);
        // Start recognition process pruning previously cached data.
         recognizer.startRecognition(true);
         SpeechResult result = recognizer.getResult();
         while ((result = recognizer.getResult()) != null) {
             System.out.println(result.getHypothesis());
         }
         recognizer.stopRecognition();
    }
}
barryhunter
  • 20,886
  • 3
  • 30
  • 43
Dorin
  • 2,167
  • 4
  • 20
  • 32

1 Answers1

0

I'm not sure what do you mean by "not good response".

If you want to decode 8khz files you need to call configuration.setSampleRate(8000) to configure decoder for 8khz. You also need to use en-us-8khz model available from downloads for best results.

If you want to recognize 16khz audio from microphone you need to use 16khz model, not 8khz model.

Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87