Grammar Authoring Processes (Microsoft.Speech)
You can author grammars for applications based on Microsoft.Speech using any of the following processes:
Create Dynamic Grammars Programmatically
Create Static Grammars as Files
Use XML to create grammar documents that conform to the Speech Recognition Grammar Specification (SRGS) Version 1.0, the W3C standard for speech recognition grammars.
Use the following to create grammars within the code of your speech application.
GrammarBuilder and Choices
The GrammarBuilder and Choices classes in the Microsoft.Speech.Recognition namespace provide methods for programmatically creating grammar definitions that do not rely on or conform to the SRGS specification. This lightweight, programmatic approach to authoring grammars will efficiently accomplish many common tasks for grammar creation. Authoring with GrammarBuilder is best suited to grammars that have a single rule containing lists, or perhaps lists of lists. See Create Grammars Using GrammarBuilder (Microsoft.Speech).
To programmatically build grammars that have multiple rules, or that need to make internal rule references, use the classes of the Microsoft.Speech.Recognition.SrgsGrammar namespace.
The classes of the Microsoft.Speech.Recognition.SrgsGrammar namespace map closely to the elements and attributes defined by the SRGS specification. Using members of the Microsoft.Speech.Recognition.SrgsGrammar namespace, you can programmatically create SRGS-compliant grammars and even write the results to an XML file. In addition, you can build a grammar in the Microsoft.Speech.Recognition.SrgsGrammar namespace from an XML-format grammar document or from a GrammarBuilder object. See Create Grammars Using SrgsGrammar (Microsoft.Speech).
Use the following to create grammars as static files, external to your speech application's code. Your speech application can load external grammar files at runtime.
SRGS XML Format
The SRGS specification defines the structure of grammars and grammar rules that use XML markup. Using a text editor, you can add XML elements, XML attributes, and plain text to define the content and sequence of the spoken input or dial tones that the grammar will recognize. A typical use for static grammars is to store lists of data that does not change frequently, for example lists of cities or grammars that process phone numbers. See Create Grammars Using SRGS XML (Microsoft.Speech) and SRGS Grammar XML Reference (Microsoft.Speech).