A general speech recognition Class Based on speech api5.1

Source: Internet
Author: User

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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.