How to tell speech recognizer to start recognition?

566 Views Asked by At

I am working on a c# application that uses the SAPI COM component. In the following code snippe, how can I tell the recognizer to start recognition based on the grammar and the wav file? Thanks.

ISpRecognizer sre = new SpInprocRecognizerClass();
ISpRecoContext context = null;
sre.CreateRecoContext(out context);
ISpRecoGrammar grammar = null;
context.CreateGrammar(1, out grammar);
grammar.LoadCmdFromFile(@"c:\grammar", SPLOADOPTIONS.SPLO_STATIC);
grammar.SetGrammarState(SPGRAMMARSTATE.SPGS_ENABLED);
SpFileStreamClass fs = new SpFileStreamClass();
fs.Open(@"c:\1.wav", SpeechStreamFileMode.SSFMOpenForRead, false);
((SpInprocRecognizerClass)sre).AudioInputStream = fs;
1

There are 1 best solutions below

0
On

You're almost there.

sre.SetRecoState(SPRECOSTATE.SPRST_ACTIVE);

should do the trick.