Grammar Constructor

Initializes a new instance of the Grammar class.

  NameDescription
Public method Grammar(Stream) Initializes a new instance of the Grammar class from a Stream.
Public method Grammar(String) Initializes a new instance of the Grammar class from a file.
Public method Grammar(GrammarBuilder) Initializes a new instance of the Grammar class from a GrammarBuilder object.
Public method Grammar(GrammarInfo) Creates a new instance of the Grammar class from a GrammarInfo instance.
Public method Grammar(SrgsDocument) Initializes a new instance of the Grammar class from an SrgsDocument object.
Public method Grammar(Stream, String) Initializes a new instance of the Grammar class from a Stream and specifies a root rule.
Public method Grammar(String, String) Initializes a new instance of the Grammar class from a file and specifies a root rule.
Public method Grammar(SrgsDocument, String) Initializes a new instance of a Grammar class from an SrgsDocument object and specifies a root rule.
Public method 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.
Public method 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.
Public method 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.
Top

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:

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.

NoteNote

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.

Show: