The System.Speech.Recognition..::.Grammar class provides run time objects that allow an application to specify a specific combination of words, choices of words, and other speech elements that the Speech platform uses to identify meaningful phrases.
The Grammar object fully supports the W3C Speech Recognition Grammar Specification (SRGS) and Context Free Grammar (CFG) specifications. For more information, see SpeechRecognitionGrammarSpecification.
Grammars may be precise word phrases, such as "Turn the computer off," or provide choices, semantic lookup tables or wildcards, such as "Change color to" and a look up table of acceptable values.
An application's recognition engine, as managed by instances of SpeechRecognizer or [T:System.Speech.Recognition.SpeechRecognitionEngine,] may create and load one or more instances Grammar, independently enabling or disabling particular grammars instance, and set Grammar properties such as priorities (Priority and weight (Weight)
The grammar a Grammar object manages can be loaded from
SRGS and CFG formats allow the inclusion of multiple grammar rules, so on construction applications can specify which rule to load as the grammar's entry point or root. Support for the inclusion of handler methods (for recognition, initialization, parsing and errors), scripts and executables in a loaded grammar is provided by allowing the specification of parameters during Grammar construction. When constructing a grammar using tags avoid using duplicate key names, as each key/value pair element is stored in a DictionaryEntry object and each pair must have contain a unique key.
Because grammar formats allow for references to other grammar objects as both relative and fully qualified URIs, a base URI can be specified during construction of a Grammar object.
Note: |
|---|
It is a best practice to verify the safety of any URI or DLL used to load a Grammar. Windows and the Speech platform provide security for applications loading a Grammar from a DLL or working with a Grammar that supports scripting. Scripts in Grammar objects are always run as if downloaded from a web page in the [Internet][Zone], and the Common Language Runtime (CLR) isolates any DLL loaded to obtain a Grammar. |