1

I've created a gramma

#JSGF V1.0;

/**
 * JSGF Grammar 
 */

grammar grammar;

public <number> = ( zero | one | two | three | four | five | six | seven | nine | ten
                   | eleven | twelve | thirteen | fourteen | fifteen | sixteen | seventeen | eighteen | nineteen | twenty 
                   | thirty | forty | fifty | sixty | seventy | eighty | ninety |
                    hundred | thousand | million | billion)+;                   
public <operation> = <number>{1} (plus | minus | multiply | division){1} <number>{1};
public <greet> = ( hello | hey | hi )* world;
public <sport> = (football | tennis);
public <program> = (notepad | calculator);
public <run> = (run | open | start) <program>;

I'm using it in simple Sphinx4 speech recognizer and I'm about to create basic logic for program answers.

That' how program recognizes words (fragments of code):

Configuration configuration = new Configuration();
        //SetVoice
        textToSpeech.setVoice("cmu-bdl-hsmm");
        // Load model from the jar
        configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
        configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
        configuration.setGrammarPath("resource:/grammars");
        configuration.setGrammarName("grammar");
        configuration.setUseGrammar(true);

try {
            recognizer = new LiveSpeechRecognizer(configuration);
        } catch (IOException ex) {
            logger.log(Level.SEVERE, null, ex);
        }

        // Start recognition process pruning previously cached data.
        recognizer.startRecognition(true);

        SpeechResult speechResult = recognizer.getResult();
                    if (speechResult != null) {

                        result = speechResult.getHypothesis();
                        System.out.println("You said: [" + result + "]\n");

Is there a way to obtain recognized grammar rule name? Regards

Adrian
  • 96
  • 5

1 Answers1

0

There is no way to do that. If you want to perform semantic analysis, you can simply parse the speech recognizer output with a regular expressions. See also

How do you retrieve tags from JSGF grammars using sphinx?

Why tags are not supported in pocketsphinx?

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