C #3.0 example of SRGs Speech Recognition definition fuzzy syntax based on speech. Recognition

Source: Internet
Author: User

Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using system. speech;
Using system. Speech. recognition;
Using system. Speech. synthesis;
Using system. Speech. audioformat;
Using system. Speech. Recognition. srgsgrammar;

Namespace voice
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}

Private void form1_load (Object sender, eventargs E)
{

// load the custom XML file
/*
speechrecognizer recognizer = new speechrecognizer ();
srgsdocument Doc = new srgsdocument ("gaarmmar. XML ");
recognizer. loadgrammar (new grammar (DOC);
*/

// example of loading in-memory sgrs syntax file
/*
speechrecognizer recognizer = new speechrecognizer ();
srgsdocument Doc = new srgsdocument ();
srgsrule command = new srgsrule ("command", new srgsoneof ("Yin Cheng is a Eldest Brother", "Yin Cheng is a second brother", "Yin Cheng is a third brother "));
Doc. rules. add (command);
Doc. root = command;
recognizer. loadgrammar (new grammar (DOC);
*/

// Example of complex syntax file Definition

Speechrecognizer recognizer = new speechrecognizer ();
Srgsdocument Doc = new srgsdocument ();
Srgsrule command = new srgsrule ("command ");
Srgsrule Rank = new srgsrule ("rank ");
Srgsitem of = new srgsitem ("");
Srgsrule suit = new srgsrule ("Suit ");
Srgsitem card = new srgsitem (New srgsruleref (rank), of, new srgsruleref (suit ));
Command. Add (card );
Rank. add (New srgsoneof ("1", "2", "3", "4", "5", "6", "7", "8 ", "9 "));
Of. setrepeat (0, 1 );
Suit. Add (New srgsoneof ("Yamada", "Yamada", "times "));
Doc. Rules. Add (command, rank, suit );
Doc. Root = command;
Recognizer. loadgrammar (new grammar (DOC ));

 

 

}
}
}
If you need source code, leave an email

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.