Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using speechlib;
Using system. Windows. forms;
Namespaces yincheng01@163.com
{
Public class sprecognition
{
Public speechlib. ispeechrecogrammar isrg;
Public speechlib. spsharedrecocontextclass ssrcontex = NULL;
Public System. Windows. Forms. Control cdisplay;
Public sprecognition (string [] gh) // load keywords
{
Ssrcontex = new spsharedrecocontextclass ();
Isrg = ssrcontex. creategrammar (0 );
Speechlib. _ ispeechrecocontextevents_recognitioneventhandler rechandle =
New _ ispeechrecocontextevents_recognitioneventhandler (contexrecognition );
Ssrcontex. Recognition + = rechandle;
Speechlib. ispeechgrammarrule menurule = isrg. Rules. Add ("123", speechruleattributes. sratoplevel | speechruleattributes. sradynamic, 1 );
Object propvalue = "";
Foreach (string FF in GH)
{
Menurule. initialstate. addwordtransition (null, FF, "", speechgrammarwordtype. sglexical, FF, 1, ref propvalue, 1.0f );
}
Isrg. Rules. Commit ();
Isrg. cmdsetrulestate ("123", speechrulestate. sgdsactive );
Isrg. dictationload ("", speechloadoption. slostatic );
Isrg. dictationsetstate (speechrulestate. sgdsactive );
}
Public void beginrec (control tbresult)
{
Cdisplay = tbresult;
}
Public void closerec ()
{
Ssrcontex = NULL;
Cdisplay = NULL;
}
Private void contexrecognition (INT iindex, object OBJ, speechlib. speechrecognitiontype, speechlib. ispeechrecoresult result)
{
Cdisplay. Text = result. phraseinfo. gettext (0,-1, true );
}
}
}
Class call
Sprecognition ff;
String [] dd = {"Yin Cheng", "East China", "Yu Hui ","};
FF = new sprecognition (dd );
Ff. beginrec (richtextbox1 );
Ff. closerec ();