Question

I have a bit of a problem with Sphinx 4 in java. I Implemented the code bellow:

package test.ionut;

import edu.cmu.sphinx.frontend.util.Microphone;
import edu.cmu.sphinx.recognizer.Recognizer;
import edu.cmu.sphinx.result.Result;
import edu.cmu.sphinx.util.props.ConfigurationManager;


public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        ConfigurationManager manager;

        if(args.length > 0){  
            manager=new ConfigurationManager(args[0]);
            }else{

            manager=new ConfigurationManager(Test.class.getResource("test.config.xml"));

        }

        Recognizer recognizer=(Recognizer)manager.lookup("recognizer");
        recognizer.allocate();
        Microphone mic=(Microphone)manager.lookup("microphone");
        if(!mic.startRecording()){

            System.out.println("Mic not identified.");
            recognizer.deallocate();
            System.out.println(1);

            System.out.println("Say: (Good morning | Hello | Hi | Welcome) (Dipayan | Paul | Philip | Rita | Will )");

            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((new StringBuilder()).append("You said: ").append(resultText).append('\n').toString());
                System.out.println("You said: "+resultText+"...");
                } else {
                System.out.println("I can't hear what you said.\n");
                }
                }

        }


    }

}

this is the grammar file:

***#JSGF V1.0;***

***grammar hello;***

***public <greet>= (Good morning | Hello | Hi | Welcome) ( Paul | Philip | Rita | Will );***

and in the xml file i have modified so that the program knows what to do with the gram file.



Bellow is the part of the code where i modified the xml:

    <!-- ******************************************************** -->
    <!-- The Grammar  configuration                               -->
    <!-- ******************************************************** -->

    <component name="jsgfGrammar" type="edu.cmu.sphinx.jsgf.JSGFGrammar">
        <property name="dictionary" value="dictionary"/>
        <property name="grammarLocation"
             value="resource:/test/ionut/"/>
        <property name="grammarName" value="mydict"/>
    <property name="logMath" value="logMath"/>
    </component>


Any help is appreciated.

The problem is that when i compile the code, i get no error, but the console doesn't show anything, not even the first print. If i modify the gram file by adding a word that is not in the dictionary and then hit run, the console shows me an error that the word is a known word in the dictionary. After removing the word, hit run, and again: the console shows me nothing. Also i have added additional heap memory with the -mx256m argument.

I've been trying all day with this, since i want to implement words from my own language with sphinx 4. But right now i'm just doing some test, getting used with it.

Was it helpful?

Solution

Are you speaking through the microphone, those words you put in the grammer file? Or just uttering random words. the system can recognize only those words which are in the Grammer file as well as in the dictionary. remember that, the .gram file is subset of the. DIC file .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top