-8

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?

Travis
  • 2,105
  • 2
  • 26
  • 35
Jayson Tamayo
  • 2,741
  • 3
  • 49
  • 76

2 Answers2

2

Since you are using JAVA there is a library called SCANNER which you should import in your project.

import java.util.Scanner;


public static void main(String[]arguments){

char x, y, z;

 Scanner input = new Scanner (System.in);

 System.out.print("Enter a letter");
 x = input.nextChar();
 y = input.nextChar();
 z = input.nextChar();

}

You should also use a loop depending on how many letters the user should write.

2

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);
Govinda P
  • 3,261
  • 5
  • 22
  • 43
Travis
  • 2,105
  • 2
  • 26
  • 35