![Collapse image Collapse image](collapse_all.gif)
![Expand Image Expand Image](expand_all.gif)
![](collapse_all.gif)
![](expand_all.gif)
![](dropdown.gif)
![](dropdownHover.gif)
![Copy image Copy image](copycode.gif)
![CopyHover image CopyHover image](copycodeHighlight.gif)
Initializes a new instance of the Grammar class.
Overload List
Name | Description | |
---|---|---|
![]() | Grammar(Stream) | Initializes a new instance of the Grammar class from a Stream. |
![]() | Grammar(String) | Initializes a new instance of the Grammar class from a file. |
![]() | Grammar(GrammarBuilder) | Initializes a new instance of the Grammar class from a GrammarBuilder object. |
![]() | Grammar(GrammarInfo) | Creates a new instance of the Grammar class from a GrammarInfo instance. |
![]() | Grammar(SrgsDocument) | Initializes a new instance of the Grammar class from an SrgsDocument object. |
![]() | Grammar(Stream, String) | Initializes a new instance of the Grammar class from a Stream and specifies a root rule. |
![]() | Grammar(String, String) | Initializes a new instance of the Grammar class from a file and specifies a root rule. |
![]() | Grammar(SrgsDocument, String) | Initializes a new instance of a Grammar class from an SrgsDocument object and specifies a root rule. |
![]() | Grammar(Stream, String, Uri) | Initializes a new instance of the Grammar class from a stream, specifies a root rule, and defines a base Uniform Resource Identifier (URI) to resolve relative rule references. |
![]() | Grammar(String, String, Uri) | Initializes a new instance of the Grammar class from a file, specifies a root rule, and defines a base Uniform Resource Identifier (URI) to resolve relative rule references. |
![]() | Grammar(SrgsDocument, String, Uri) | Initializes a new instance of a Grammar class from an SrgsDocument object, specifies a root rule, and defines a base Uniform Resource Identifier (URI) to resolve relative rule references. |
Remarks
You can use a Grammar constructor to create a Grammar instance from a GrammarBuilder or SrgsDocument object, or from a file or a Stream that contains a description of a grammar in a supported format. Supported formats include the following:
XML-format files that conform to the W3C Speech Recognition Grammar Specification (SRGS) Version 1.0
Grammars that have been compiled to a binary file with a .cfg file extension
Grammar constructors that accept XML-format grammar files in their arguments compile the XML grammars to a binary format to optimize them for loading and consumption by a speech recognition engine. You can reduce the amount of time required to construct a Grammar object from an XML-format grammar by compiling the grammar in advance, using one of the Compile()()()() methods.
A speech recognition grammar can define a root rule. To create a Grammar object that specifies which rule to use as its root rule, use a constructor that accepts the ruleName parameter.
To create a Grammar object that specifies a base URI to resolve relative rule references, use a constructor that takes the baseUri parameter.
Specification of parameters during construction is also provided to support the inclusion of scripts in loaded grammars.
![]() |
---|
It is a best practice to verify the safety of any URI or DLL used to build a Grammar object. The Microsoft Speech Platform SDK 11 provides security for applications constructing a Grammar instance from a DLL or from a grammar that supports scripting. Scripts in Grammar objects are always run as if downloaded from a web page in the Internet Zone. The Common Language Runtime (CLR) isolates any DLL loaded to obtain a grammar definition. |