javacmusphinxpocketsphinx-android

What Grammar to use when recognizing letters


Using speech recognition I want to create a spelling game in which a user says the letter. For example, the user says "S" "T" "A" "C" "K".

I am using PocketSphinx to accomplish this. Here is my code:

File modelsDir = new File(assetsDir, "models");
        recognizer = defaultSetup()
                .setAcousticModel(new File(modelsDir, "hmm/en-us-semi"))
                .setDictionary(new File(modelsDir, "dict/cmu07a.dic"))
                .setRawLogDir(assetsDir).setKeywordThreshold(1e-20f)
                .getRecognizer();
        recognizer.addListener(this);

        // Create keyword-activation search.
        recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);
        // Create grammar-based searches.
        File menuGrammar = new File(modelsDir, "grammar/menu.gram");
        recognizer.addGrammarSearch(MENU_SEARCH, menuGrammar);
        File digitsGrammar = new File(modelsDir, "grammar/digits.gram");
        recognizer.addGrammarSearch(DIGITS_SEARCH, digitsGrammar);
        // Create language model search.
        File languageModel = new File(modelsDir, "lm/weather.dmp");
        recognizer.addNgramSearch(FORECAST_SEARCH, languageModel);

How do I recognize the letters that the user say?

Or is there any library that I can use to accomplish this?


Solution

  • You are currently loading two grammers into your recognizer. I believe digits.gram contains numbers.

    File menuGrammar = new File(modelsDir, "grammar/menu.gram");
    recognizer.addGrammarSearch(MENU_SEARCH, menuGrammar);
    File digitsGrammar = new File(modelsDir, "grammar/digits.gram");
    

    So I think what you could do is make a file letter.gram and load it into your program

    #JSGF V1.0;
    grammar speech;
    public <speech> = A |
                      B | 
                      C; 
    

    Code:

    File letterGrammar = new File(PUT CORRECT PATH WITH FILE NAME);
    recognizer.addGrammarSearch("speech", letterGrammar);