cmusphinx / sphinx4

Pure Java speech recognition library
cmusphinx.sourceforge.net
Other
1.4k stars 586 forks source link

linguist/acoustic/tiedstate/tiedmixture/MixtureComponentSet.java #73

Closed rpereira-dev closed 6 years ago

rpereira-dev commented 6 years ago

In file /linguist/acoustic/tiedstate/tiedmixture/MixtureComponentSet.java , l. 90, in method:

private void insertTopComponent(PrunableMixtureComponent[] topComponents, PrunableMixtureComponent component)

In my program, the for loop, the if condition is entered on first loop iteration (having i = 0), which is causing a crash of my application:

Caused by: java.lang.ArrayIndexOutOfBoundsException: -1 at edu.cmu.sphinx.linguist.acoustic.tiedstate.tiedmixture.MixtureComponentSet.insertTopComponent(MixtureComponentSet.java:94)

Though, I'm not sure that this behaviour was supposed to happen (maybe I did something wrong when using the API)

The code causing the crash:



ConfigurationManager configurationManager = new ConfigurationManager("./res/sphinx4/fr/config.xml");

Recognizer recognizer = (Recognizer) configurationManager.lookup("recognizer");
recognizer.allocate();

// start the microphone or exit if the programm if this is not possible
Microphone microphone = (Microphone) configurationManager.lookup("microphone");
if (!microphone.startRecording()) {
    System.out.println("Cannot start microphone.");
    recognizer.deallocate();
    System.exit(1);
}

System.out.println("Say: ( bonjour | salut ) ( romain | will )");

// loop the recognition until the programm exits.
while (true) {
    System.out.println("Start speaking. Press Ctrl-C to quit.\n");

    Result result = recognizer.recognize();

    if (result != null) {
        String resultText = result.getBestFinalResultNoFiller();
        System.out.println("You said: " + resultText + '\n');
    } else {
        System.out.println("I can't hear what you said.\n");
    }
}`
nshmyrev commented 6 years ago

You are using some outdated sources and code. Follow our tutorial

http://cmusphinx.github.io/wiki/tutorialsphinx4

rpereira-dev commented 6 years ago

My sources weren't outdated (as I'm using gradle and latest maven's version)

However, changing my code this way solved the issue:



            Configuration configuration = new Configuration();

            configuration.setAcousticModelPath("./res/sphinx4/fr/model");
            configuration.setDictionaryPath("./res/sphinx4/fr/fr.dict");
            configuration.setUseGrammar(true);
            configuration.setGrammarPath("./res/sphinx4/fr/");
            configuration.setGrammarName("fr");

            LiveSpeechRecognizer jsgfRecognizer = new LiveSpeechRecognizer(configuration);

            jsgfRecognizer.startRecognition(true);
            while (true) {
                String utterance = jsgfRecognizer.getResult().getHypothesis();
                System.out.println(utterance);
            }`

Is ConfigurationManager class deprecated?
nshmyrev commented 6 years ago

It is not deprecated but private.