Grammar 构造函数
定义
重载
| Grammar() |
初始化 Grammar 类的新实例。Initializes a new instance of the Grammar class. |
| Grammar(SrgsDocument, String, Uri, Object[]) |
初始化来自 Grammar 的实例的 SrgsDocument 类的新实例,并指定成为语法入口的规则的名称及一个基 URI 来解析相对引用。Initializes a new instance of the Grammar class from an instance of SrgsDocument, and specifies the name of a rule to be the entry point to the grammar and a base URI to resolve relative references. |
| Grammar(Stream, String, Uri, Object[]) |
初始化 Grammar 类的新实例 Stream 并指定根规则和基 URI 来解析相对引用。Initializes a new instance of the Grammar class a Stream and specifies a root rule and a base URI to resolve relative references. |
| Grammar(SrgsDocument, String, Uri) |
初始化来自 Grammar 对象的 SrgsDocument 类的新实例,指定一个根规则,并定义一个基统一资源标识符(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. |
| Grammar(SrgsDocument, String, Object[]) |
初始化来自 Grammar 的实例的 SrgsDocument 类的新实例,并指定成为语法入口点的规则的名称。Initializes a new instance of the Grammar class from an instance of SrgsDocument, and specifies the name of a rule to be the entry point to the grammar. |
| Grammar(Stream, String, Uri) |
初始化来自流的 Grammar 类的新实例,指定根规则并定义一个基统一资源字符识别(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(Stream, String, Object[]) |
从 Grammar 和指定根规则中来初始化 Stream 类的新实例。Initializes a new instance of the Grammar class from a Stream and specifies a root rule. |
| Grammar(String, String, Object[]) |
初始化来自包含语法定义的文件的 Grammar 类的新实例并指定成为语法入口的规则的名称。Initializes a new instance of the Grammar class from a file that contains a grammar definition, and specifies the name of a rule to be the entry point to the grammar. |
| Grammar(SrgsDocument, String) |
初始化来自 Grammar 对象的 SrgsDocument 类的新实例并指定一个根规则。Initializes a new instance of a Grammar class from an SrgsDocument object and specifies a root rule. |
| Grammar(Stream, String) |
从 Grammar 和指定根规则中来初始化 Stream 类的新实例。Initializes a new instance of the Grammar class from a Stream and specifies a root rule. |
| Grammar(String) |
从文件中初始化 Grammar 类的新实例。Initializes a new instance of the Grammar class from a file. |
| Grammar(SrgsDocument) |
从 Grammar 对象初始化 SrgsDocument 类的新实例。Initializes a new instance of a Grammar class from an SrgsDocument object. |
| Grammar(String, String) |
初始化 Grammar 类的新实例并指定根规则。Initializes a new instance of the Grammar class from a file and specifies a root rule. |
| Grammar(GrammarBuilder) |
从 Grammar 对象初始化 GrammarBuilder 类的新实例。Initializes a new instance of the Grammar class from a GrammarBuilder object. |
| Grammar(Stream) |
从 Grammar 初始化 Stream 类的新实例。Initializes a new instance of the Grammar class from a Stream. |
注解
可以使用 Grammar 构造函数 Grammar 从 GrammarBuilder 或对象创建实例,也可以使用 SrgsDocument Stream 包含受支持格式的语法说明的文件或来创建实例。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:
符合 W3C语音识别语法规范 (SRGS) 版本 1.0的 XML 格式文件XML-format files that conform to the W3C Speech Recognition Grammar Specification (SRGS) Version 1.0
已编译为带有 cfg 文件扩展名的二进制文件的语法Grammars that have been compiled to a binary file with a .cfg file extension
在其参数中接受 XML 格式语法文件的语法构造函数将 XML 语法编译为二进制格式,以优化语音识别引擎的加载和使用。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. 您可以 Grammar 通过使用其中一种方法预先编译语法来减少从 XML 格式语法构造对象所需的时间 Compile 。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. 若要创建一个 Grammar 指定要用作其根规则的规则的对象,请使用接受参数的构造函数 ruleName 。To create a Grammar object that specifies which rule to use as its root rule, use a constructor that accepts the ruleName parameter.
若要创建一个 Grammar 指定基 URI 以解析相对规则引用的对象,请使用采用参数的构造函数 baseUri 。To create a Grammar object that specifies a base URI to resolve relative rule references, use a constructor that takes the baseUri parameter.
Grammar()
Grammar(SrgsDocument, String, Uri, Object[])
初始化来自 Grammar 的实例的 SrgsDocument 类的新实例,并指定成为语法入口的规则的名称及一个基 URI 来解析相对引用。Initializes a new instance of the Grammar class from an instance of SrgsDocument, and specifies the name of a rule to be the entry point to the grammar and a base URI to resolve relative references.
public:
Grammar(System::Speech::Recognition::SrgsGrammar::SrgsDocument ^ srgsDocument, System::String ^ ruleName, Uri ^ baseUri, cli::array <System::Object ^> ^ parameters);
public Grammar (System.Speech.Recognition.SrgsGrammar.SrgsDocument srgsDocument, string ruleName, Uri baseUri, object[] parameters);
new System.Speech.Recognition.Grammar : System.Speech.Recognition.SrgsGrammar.SrgsDocument * string * Uri * obj[] -> System.Speech.Recognition.Grammar
Public Sub New (srgsDocument As SrgsDocument, ruleName As String, baseUri As Uri, parameters As Object())
参数
- srgsDocument
- SrgsDocument
包含语音识别语法的约束的 SrgsDocument 的实例。An instance of SrgsDocument that contains the constraints for the speech recognition grammar.
- ruleName
- String
用作语音识别语法的入口点的规则标识符,或以使用语法说明的默认根规则 null 。The identifier of the rule to use as the entry point of the speech recognition grammar, or null to use the default root rule of the grammar description.
- baseUri
- Uri
使用的基 URI 解决所有在语法描述中的任何相关规则 null引用,或The base URI to use to resolve any relative rule reference in the grammar description, or null.
- parameters
- Object[]
通过入口点或创建的根规则的属性指定设置为指定的 OnInit 参数要传递至的 Grammar 初始化处理程序。Parameters to be passed to the initialization handler specified by the OnInit property for the entry point or the root rule of the Grammar to be created. 此参数可以为 null。This parameter may be null.
例外
- 包含无效值的任何参数。- Any of the parameters contain an invalid value.
- srgsDocument 不包含 SrgsDocument 指定的规则 ruleName 的指定中。- The SrgsDocument specified by srgsDocument does not contain the rule specified in ruleName.
- 数组参数的内容与初始化处理程序的任何规则的参数不匹配。- The contents of the array parameters do not match the arguments of any of the rule's initialization handlers.
- 语法具有无法由语法的默认基或baseUri提供的 URI Uri 解决的相对规则引用。- The grammar has a relative rule reference that cannot be resolved by the default base Uri rule for grammars or the URI supplied by baseUri.
注解
还可以指定初始化处理程序的参数。Parameters for an initialization handler may also be specified.
适用于
Grammar(Stream, String, Uri, Object[])
public:
Grammar(System::IO::Stream ^ stream, System::String ^ ruleName, Uri ^ baseUri, cli::array <System::Object ^> ^ parameters);
public Grammar (System.IO.Stream stream, string ruleName, Uri baseUri, object[] parameters);
new System.Speech.Recognition.Grammar : System.IO.Stream * string * Uri * obj[] -> System.Speech.Recognition.Grammar
Public Sub New (stream As Stream, ruleName As String, baseUri As Uri, parameters As Object())
参数
- stream
- Stream
连接到包含语法规范的输入 / 输出对象(包括文件、VisualStudio 资源和 DLL)的 Stream。A Stream connected to an input/output object (including files, VisualStudio Resources, and DLLs) that contains a grammar specification.
- ruleName
- String
用作语音识别语法的入口点的规则标识符,或以使用语法说明的默认根规则 null 。The identifier of the rule to use as the entry point of the speech recognition grammar, or null to use the default root rule of the grammar description.
- baseUri
- Uri
使用的基 URI 解决所有在语法描述中的任何相关规则 null引用,或The base URI to use to resolve any relative rule reference in the grammar description, or null.
- parameters
- Object[]
通过入口点或创建的根规则的属性指定设置为指定的 OnInit 参数要传递至的 Grammar 初始化处理程序。Parameters to be passed to the initialization handler specified by the OnInit property for the entry point or the root rule of the Grammar to be created. 此参数可以为 null。This parameter may be null.
例外
- 包含无效值的任何参数。- Any of the parameters contain an invalid value.
- stream 连接到不包含 ruleName 指定规则的语法。- The stream is connected to a grammar that does not contain the rule specified by ruleName.
- 数组参数的内容与初始化处理程序的任何规则的参数不匹配。- The contents of the array parameters do not match the arguments of any of the rule's initialization handlers.
- 语法包含无法由语法的默认基或 baseUri提供的 URI Uri 解决的相对规则引用。- The grammar contains a relative rule reference that cannot be resolved by the default base Uri rule for grammars or the URI supplied by baseUri.
注解
还可以指定初始化处理程序的参数。Parameters for an initialization handler may also be specified.
适用于
Grammar(SrgsDocument, String, Uri)
初始化来自 Grammar 对象的 SrgsDocument 类的新实例,指定一个根规则,并定义一个基统一资源标识符(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.
public:
Grammar(System::Speech::Recognition::SrgsGrammar::SrgsDocument ^ srgsDocument, System::String ^ ruleName, Uri ^ baseUri);
public Grammar (System.Speech.Recognition.SrgsGrammar.SrgsDocument srgsDocument, string ruleName, Uri baseUri);
new System.Speech.Recognition.Grammar : System.Speech.Recognition.SrgsGrammar.SrgsDocument * string * Uri -> System.Speech.Recognition.Grammar
Public Sub New (srgsDocument As SrgsDocument, ruleName As String, baseUri As Uri)
参数
- srgsDocument
- SrgsDocument
语音识别语法的约束。The constraints for the speech recognition grammar.
- ruleName
- String
规则标识符作为语音识别语法的入口点,按 SrgsDocument默认根规则使用 null 。The identifier of the rule to use as the entry point of the speech recognition grammar, or null to use the default root rule of the SrgsDocument.
- baseUri
- Uri
SrgsDocument或者 null中使用的基 URI 解决所有在语法描述中的任何相关规则引用,或The base URI to use to resolve any relative rule reference in the SrgsDocument, or null.
例外
ruleName 无法解析或非公共,或者 ruleName 为 null,并且 srgsDocument 不包含根规则。ruleName cannot be resolved or is not public, or ruleName is null and srgsDocument does not contain a root rule.
srgsDocument 为 null。srgsDocument is null.
srgsDocument 包含无法解析的规则引用。srgsDocument contains a rule reference that cannot be resolved.
示例
下面的示例在中创建一个语音识别语法, SrgsDocument 其中包含对 cities.xml 文件的相对规则引用,并指定要用于解析规则引用的 URI。The following example creates a speech recognition grammar in an SrgsDocument that contains a relative rule reference to the cities.xml file, and specifies a URI to use to resolve the rule reference. cities.xml 文件的内容将显示在遵循 c # 示例的 XML 示例中。The content of the cities.xml file appears in the XML example that follows the C# example.
private static Grammar CreateSrgsDocumentGrammar3()
{
// Create the SrgsDocument.
SrgsDocument document = new SrgsDocument();
// Create the Main rule and add it to the document.
SrgsRule mainRule = new SrgsRule("Main");
mainRule.Scope = SrgsRuleScope.Public;
SrgsItem item = new SrgsItem("Can I get a shuttle in");
// Create a relative URI for the cities rule.
Uri ruleUri = new Uri("cities.xml#Cities", UriKind.Relative);
item.Add(new SrgsRuleRef(ruleUri));
mainRule.Add(item);
document.Rules.Add(mainRule);
// Set the root rule.
document.Root = mainRule;
// Create the grammar.
Uri baseUri = new Uri(@"file://c:\temp\");
Grammar citiesGrammar = new Grammar(document, null, baseUri);
citiesGrammar.Name = "SrgsDocument Cities Grammar 3";
return citiesGrammar;
}
<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
tag-format="semantics/1.0" root="Main">
<!-- cities.xml:
Defines an SRGS grammar for requesting a flight. This grammar includes
a Cities rule that lists the cities that can be used for departures
and destinations. -->
<rule id="Main">
<item>
I would like to fly from <ruleref uri="#Cities"/>
to <ruleref uri="#Cities"/>
</item>
</rule>
<rule id="Cities" scope="public">
<one-of>
<item>Seattle</item>
<item>Los Angeles</item>
<item>New York</item>
<item>Miami</item>
</one-of>
</rule>
</grammar>
注解
此构造函数不会将任何参数传递给初始化处理程序,并且 SrgsDocument 不应包含需要参数的初始化处理程序。This constructor does not pass any parameters to the initialization handler, and the SrgsDocument should not contain an initialization handler that requires arguments.
此构造函数不会进行验证 baseUri 。This constructor does not validate baseUri. 但是, LoadGrammar SpeechRecognitionEngine 如果或对象的方法 SpeechRecognizer 无法解析语法说明中的所有规则引用,则会引发异常。However, the LoadGrammar method of a SpeechRecognitionEngine or SpeechRecognizer object throws an exception if it cannot resolve all of the rule references in the grammar description. 如果不 baseUri 为 null ,则此 LoadGrammar 方法使用 URI 来解析不能以其他方式解析的规则引用。If baseUri is not null, the LoadGrammar method uses the URI to resolve any rule references that it cannot otherwise resolve. 如果 baseUri 表示文件,则此 LoadGrammar 方法在尝试解析相对规则引用时使用指定的文件和文件的目录。If baseUri represents a file, then the LoadGrammar method uses both the designated file and the file's directory when it attempts to resolve relative rule references.
另请参阅
- System.Speech.Recognition.SrgsGrammar
- SrgsDocument
- SpeechRecognitionEngine
- SpeechRecognizer
- 语音识别语法规范Speech Recognition Grammar Specification
适用于
Grammar(SrgsDocument, String, Object[])
初始化来自 Grammar 的实例的 SrgsDocument 类的新实例,并指定成为语法入口点的规则的名称。Initializes a new instance of the Grammar class from an instance of SrgsDocument, and specifies the name of a rule to be the entry point to the grammar.
public:
Grammar(System::Speech::Recognition::SrgsGrammar::SrgsDocument ^ srgsDocument, System::String ^ ruleName, cli::array <System::Object ^> ^ parameters);
public Grammar (System.Speech.Recognition.SrgsGrammar.SrgsDocument srgsDocument, string ruleName, object[] parameters);
new System.Speech.Recognition.Grammar : System.Speech.Recognition.SrgsGrammar.SrgsDocument * string * obj[] -> System.Speech.Recognition.Grammar
Public Sub New (srgsDocument As SrgsDocument, ruleName As String, parameters As Object())
参数
- srgsDocument
- SrgsDocument
包含语音识别语法的约束的 SrgsDocument 的实例。An instance of SrgsDocument that contains the constraints for the speech recognition grammar.
- ruleName
- String
用作语音识别语法的入口点的规则标识符,或以使用语法说明的默认根规则 null 。The identifier of the rule to use as the entry point of the speech recognition grammar, or null to use the default root rule of the grammar description.
- parameters
- Object[]
通过入口点或创建的根规则的属性指定设置为指定的 OnInit 参数要传递至的 Grammar 初始化处理程序。Parameters to be passed to the initialization handler specified by the OnInit property for the entry point or the root rule of the Grammar to be created. 此参数可以为 null。This parameter may be null.
例外
- 包含无效值的任何参数。- Any of the parameters contain an invalid value.
- srgsDocument 指定的 SrgsDocument 不包含 ruleName 指定的规则。- The SrgsDocument specified by srgsDocument does not contain the rule specified by ruleName.
- 数组参数的内容与初始化处理程序的任何规则的参数不匹配。- The contents of the array parameters do not match the arguments of any of the rule's initialization handlers.
注解
还可以指定初始化处理程序的参数。Parameters for an initialization handler may also be specified.
适用于
Grammar(Stream, String, Uri)
public:
Grammar(System::IO::Stream ^ stream, System::String ^ ruleName, Uri ^ baseUri);
public Grammar (System.IO.Stream stream, string ruleName, Uri baseUri);
new System.Speech.Recognition.Grammar : System.IO.Stream * string * Uri -> System.Speech.Recognition.Grammar
Public Sub New (stream As Stream, ruleName As String, baseUri As Uri)
参数
- stream
- Stream
以受支持的格式描述语音识别语法的流。A stream that describes a speech recognition grammar in a supported format.
- ruleName
- String
用作语音识别语法的入口点的规则标识符,或以使用语法说明的默认根规则 null 。The identifier of the rule to use as the entry point of the speech recognition grammar, or null to use the default root rule of the grammar description.
- baseUri
- Uri
使用的基 URI 解决所有在语法描述中的任何相关规则 null引用,或The base URI to use to resolve any relative rule reference in the grammar description, or null.
例外
ruleName 无法解析或非公共,或者 ruleName 为 null,并且语法说明不定义根规则。ruleName cannot be resolved or is not public, or ruleName is null and the grammar description does not define a root rule.
stream 为 null。stream is null.
流不包含有效的说明,也不描述包含一个规则引用无法解析的语法。The stream does not contain a valid description or describes a grammar that contains a rule reference that cannot be resolved.
示例
下面的示例从文件流加载本地 SRGS 文件 (shuttle.xml) 。The following example loads a local SRGS file (shuttle.xml) from a file stream. 文件包含对 cities.xml 文件中规则的相对规则引用,并指定要用于解析规则引用的基 URI。The file contains a relative rule reference to a rule in the cities.xml file, and specifies a base URI to use to resolve the rule reference. shuttle.xml 和 cities.xml 文件的内容将显示在遵循 c # 示例的 XML 示例中。The content of the shuttle.xml and cities.xml files appears in the XML examples that follow the C# example.
private static Grammar CreateGrammarFromStream3()
{
FileInfo file = new FileInfo(@".\shuttle.xml");
Uri baseUri = new Uri(@"file://c:\temp\");
Grammar citiesGrammar = new Grammar(file.OpenRead(), null, baseUri);
citiesGrammar.Name = "Stream Cities Grammar 3";
return citiesGrammar;
}
<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
tag-format="semantics/1.0" root="Main">
<!-- shuttle.xml:
Defines an SRGS grammar for asking about a shuttle service. This grammar
references a Cities rule that is defined in the cities.xml grammar. -->
<rule id="Main">
<item>
Can I get a shuttle in
<ruleref uri="cities.xml#Cities"/>
</item>
</rule>
</grammar>
<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
tag-format="semantics/1.0" root="Main">
<!-- cities.xml:
Defines an SRGS grammar for requesting a flight. This grammar includes
a Cities rule that lists the cities that can be used for departures
and destinations. -->
<rule id="Main">
<item>
I would like to fly from <ruleref uri="#Cities"/>
to <ruleref uri="#Cities"/>
</item>
</rule>
<rule id="Cities" scope="public">
<one-of>
<item>Seattle</item>
<item>Los Angeles</item>
<item>New York</item>
<item>Miami</item>
</one-of>
</rule>
</grammar>
注解
此构造函数不会将任何参数传递给初始化处理程序,并且说明不应定义需要参数的初始化处理程序。This constructor does not pass any parameters to the initialization handler, and the description should not define an initialization handler that requires arguments.
此构造函数可以创建 Grammar 以下格式的实例:This constructor can create a Grammar instance from the following formats:
符合 W3C语音识别语法规范 (SRGS) 版本 1.0的 XML 格式文件XML-format files that conform to the W3C Speech Recognition Grammar Specification (SRGS) Version 1.0
已编译为带有 cfg 文件扩展名的二进制文件的语法Grammars that have been compiled to a binary file with a .cfg file extension
此构造函数将 XML 格式语法文件编译为二进制格式,以优化语音识别引擎的加载和使用。This constructor compiles XML-format grammar files to a binary format to optimize them for loading and consumption by a speech recognition engine. 您可以 Grammar 通过使用其中一种方法预先编译语法来减少从 XML 格式语法构造对象所需的时间 Compile 。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.
此构造函数不会进行验证 baseUri 。This constructor does not validate baseUri. 但是, LoadGrammar SpeechRecognitionEngine 如果或对象的方法 SpeechRecognizer 无法解析语法说明中的所有规则引用,则会引发异常。However, the LoadGrammar method of a SpeechRecognitionEngine or SpeechRecognizer object throws an exception if it cannot resolve all of the rule references in the grammar description. 如果不 baseUri 为 null ,则此 LoadGrammar 方法使用 URI 来解析不能以其他方式解析的规则引用。If baseUri is not null, the LoadGrammar method uses the URI to resolve any rule references that it cannot otherwise resolve. 如果 baseUri 表示文件,则在 LoadGrammar 尝试解析相对规则引用时,使用指定的文件和文件的目录。If baseUri represents a file, then the LoadGrammar uses both the designated file and the file's directory when it attempts to resolve relative rule references.
另请参阅
适用于
Grammar(Stream, String, Object[])
public:
Grammar(System::IO::Stream ^ stream, System::String ^ ruleName, cli::array <System::Object ^> ^ parameters);
public Grammar (System.IO.Stream stream, string ruleName, object[] parameters);
new System.Speech.Recognition.Grammar : System.IO.Stream * string * obj[] -> System.Speech.Recognition.Grammar
Public Sub New (stream As Stream, ruleName As String, parameters As Object())
参数
- stream
- Stream
连接到包含语法规范的输入 / 输出对象(包括文件、VisualStudio 资源和 DLL)的 Stream。A Stream connected to an input/output object (including files, VisualStudio Resources, and DLLs) that contains a grammar specification.
- ruleName
- String
用作语音识别语法的入口点的规则标识符,或以使用语法说明的默认根规则 null 。The identifier of the rule to use as the entry point of the speech recognition grammar, or null to use the default root rule of the grammar description.
- parameters
- Object[]
通过入口点或创建的根规则的属性指定设置为指定的 OnInit 参数要传递至的 Grammar 初始化处理程序。Parameters to be passed to the initialization handler specified by the OnInit property for the entry point or the root rule of the Grammar to be created. 此参数可以为 null。This parameter may be null.
例外
stream 连接到该语法:stream is connected to a grammar that:
- 不包含 ruleName 中指定的规则- Does not contain the rule specified in ruleName
- 需要与 parameters 中指定的那些不同的初始化参数- Requires initialization parameters different from those specified in parameters
- 包含无法由语法的默认基 Uri 规则解决的相对规则引用- Contains a relative rule reference that cannot be resolved by the default base Uri rule for grammars
注解
还可以指定初始化处理程序的参数。Parameters for an initialization handler may also be specified.
适用于
Grammar(String, String, Object[])
public:
Grammar(System::String ^ path, System::String ^ ruleName, cli::array <System::Object ^> ^ parameters);
public Grammar (string path, string ruleName, object[] parameters);
new System.Speech.Recognition.Grammar : string * string * obj[] -> System.Speech.Recognition.Grammar
Public Sub New (path As String, ruleName As String, parameters As Object())
参数
- path
- String
一个文件的路径,包括 DLL,包含语法规范。The path to a file, including DLLs, that contains a grammar specification.
- ruleName
- String
用作语音识别语法的入口点的规则标识符,或以使用语法说明的默认根规则 null 。The identifier of the rule to use as the entry point of the speech recognition grammar, or null to use the default root rule of the grammar description.
- parameters
- Object[]
通过入口点或创建的根规则的属性指定设置为指定的 OnInit 参数要传递至的 Grammar 初始化处理程序。Parameters to be passed to the initialization handler specified by the OnInit property for the entry point or the root rule of the Grammar to be created. 此参数可以为 null。This parameter may be null.
例外
- 包含无效值的任何参数。- Any of the parameters contain an invalid value.
- path 指定的文件不包含在 ruleName 有效语法或规则指定的。- The file specified by path does not contain a valid grammar or the rule specified in ruleName.
- 数组参数的内容与初始化处理程序的任何规则的参数不匹配。- The contents of the array parameters do not match the arguments of any of the rule's initialization handlers.
- 语法具有无法由语法的默认基 Uri 规则解决的相对规则引用。- The grammar has a relative rule reference that cannot be resolved by the default base Uri rule for grammars.
注解
还可以指定初始化处理程序的参数。Parameters for an initialization handler may also be specified.
适用于
Grammar(SrgsDocument, String)
初始化来自 Grammar 对象的 SrgsDocument 类的新实例并指定一个根规则。Initializes a new instance of a Grammar class from an SrgsDocument object and specifies a root rule.
public:
Grammar(System::Speech::Recognition::SrgsGrammar::SrgsDocument ^ srgsDocument, System::String ^ ruleName);
public Grammar (System.Speech.Recognition.SrgsGrammar.SrgsDocument srgsDocument, string ruleName);
new System.Speech.Recognition.Grammar : System.Speech.Recognition.SrgsGrammar.SrgsDocument * string -> System.Speech.Recognition.Grammar
Public Sub New (srgsDocument As SrgsDocument, ruleName As String)
参数
- srgsDocument
- SrgsDocument
语音识别语法的约束。The constraints for the speech recognition grammar.
- ruleName
- String
规则标识符作为语音识别语法的入口点,按 SrgsDocument默认根规则使用 null 。The identifier of the rule to use as the entry point of the speech recognition grammar, or null to use the default root rule of the SrgsDocument.
例外
ruleName 无法解析或非公共,或者 ruleName 为 null,并且 srgsDocument 不包含根规则。ruleName cannot be resolved or is not public, or ruleName is null and srgsDocument does not contain a root rule.
srgsDocument 为 null。srgsDocument is null.
srgsDocument 包含无法解析的规则引用。srgsDocument contains a rule reference that cannot be resolved.
示例
下面的示例在实例中创建语音识别语法 SrgsDocument ,并指定要用作语法的根规则的规则。The following example creates a speech recognition grammar in an SrgsDocument instance and specifies a rule to use as the root rule of the grammar. 该示例 Grammar 从实例构造对象 SrgsDocument 并将其加载到语音识别引擎。The example constructs a Grammar object from the SrgsDocument instance and loads it into the speech recognition engine.
using System;
using System.Speech.Recognition;
using System.Speech.Recognition.SrgsGrammar;
namespace SampleRecognition
{
class Program
{
static void Main(string[] args)
// Initialize an in-process speech recognition engine.
{
using (SpeechRecognitionEngine recognizer =
new SpeechRecognitionEngine())
{
// Create the SrgsDocument.
SrgsDocument document = new SrgsDocument();
// Create the Cities rule and add it to the document.
SrgsRule citiesRule = new SrgsRule("Cities");
citiesRule.Scope = SrgsRuleScope.Public;
SrgsOneOf cityChoice = new SrgsOneOf();
cityChoice.Add(new SrgsItem("Seattle"));
cityChoice.Add(new SrgsItem("Los Angeles"));
cityChoice.Add(new SrgsItem("New York"));
cityChoice.Add(new SrgsItem("Miami"));
citiesRule.Add(cityChoice);
document.Rules.Add(citiesRule);
// Create the Main rule and add it to the document.
SrgsRule mainRule = new SrgsRule("Main");
mainRule.Scope = SrgsRuleScope.Public;
mainRule.Add(new SrgsItem("I would like to fly from"));
mainRule.Add(new SrgsRuleRef(citiesRule));
mainRule.Add(new SrgsItem("to"));
mainRule.Add(new SrgsRuleRef(citiesRule));
document.Rules.Add(mainRule);
// Create the Grammar object and specify which rule to use as the root.
Grammar citiesGrammar = new Grammar(document,"Main");
// Load the grammar object to the recognizer.
recognizer.LoadGrammarAsync(citiesGrammar);
// Attach a handler for the SpeechRecognized event.
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
// Set the input to the recognizer.
recognizer.SetInputToDefaultAudioDevice();
// Start recognition.
recognizer.RecognizeAsync();
Console.WriteLine("Starting asynchronous recognition...");
// Keep the console window open.
Console.ReadLine();
}
}
// Handle the SpeechRecognized event.
static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
Console.WriteLine(" Speech recognized: " + e.Result.Text);
}
}
}
注解
此构造函数不会将任何参数传递给初始化处理程序,并且 SrgsDocument 不应包含需要参数的初始化处理程序。This constructor does not pass any parameters to the initialization handler, and the SrgsDocument should not contain an initialization handler that requires arguments.
若要 Grammar 从创建对象 SrgsDocument 并指定要使用的基 URI 来解析相对规则引用,请使用 Grammar 构造函数。To create a Grammar object from a SrgsDocument and specify a base URI to use to resolve relative rule references, use the Grammar constructor.
另请参阅
- System.Speech.Recognition.SrgsGrammar
- SrgsDocument
- SpeechRecognizer
- SpeechRecognitionEngine
- 语音识别语法规范Speech Recognition Grammar Specification
适用于
Grammar(Stream, String)
public:
Grammar(System::IO::Stream ^ stream, System::String ^ ruleName);
public Grammar (System.IO.Stream stream, string ruleName);
new System.Speech.Recognition.Grammar : System.IO.Stream * string -> System.Speech.Recognition.Grammar
Public Sub New (stream As Stream, ruleName As String)
参数
- stream
- Stream
以受支持的格式描述语音识别语法的流。A stream that describes a speech recognition grammar in a supported format.
- ruleName
- String
用作语音识别语法的入口点的规则标识符,或以使用语法说明的默认根规则 null 。The identifier of the rule to use as the entry point of the speech recognition grammar, or null to use the default root rule of the grammar description.
例外
ruleName 无法解析或非公共,或者 ruleName 为 null,并且语法说明不定义根规则。ruleName cannot be resolved or is not public, or ruleName is null and the grammar description does not define a root rule.
stream 为 null。stream is null.
流不包含有效的说明,也不描述包含一个规则引用无法解析的语法。The stream does not contain a valid description or describes a grammar that contains a rule reference that cannot be resolved.
示例
下面的示例从文件流加载本地 SRGS 文件 (cities.xml) ,并指定要用作语法的根的规则。The following example loads a local SRGS file (cities.xml) from a file stream and specifies a rule to use as the root of the grammar. cities.xml 文件的内容将显示在遵循 c # 示例的 XML 示例中。The content of the cities.xml file appears in the XML example that follows the C# example.
// Load a cities grammar from an I/O stream, use a specific
// rule as the root of the grammar, and return the new grammar.
private static Grammar CreateGrammarFromStream2()
{
FileInfo file = new FileInfo(@"c:\temp\cities.xml");
Grammar citiesGrammar = new Grammar(file.OpenRead(), "Main");
citiesGrammar.Name = "Stream Cities Grammar 2";
return citiesGrammar;
}
<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
tag-format="semantics/1.0" root="Main">
<!-- cities.xml:
Defines an SRGS grammar for requesting a flight. This grammar includes
a Cities rule that lists the cities that can be used for departures
and destinations. -->
<rule id="Main">
<item>
I would like to fly from <ruleref uri="#Cities"/>
to <ruleref uri="#Cities"/>
</item>
</rule>
<rule id="Cities" scope="public">
<one-of>
<item>Seattle</item>
<item>Los Angeles</item>
<item>New York</item>
<item>Miami</item>
</one-of>
</rule>
</grammar>
注解
此构造函数不会将任何参数传递给初始化处理程序,并且说明不应定义需要参数的初始化处理程序。This constructor does not pass any parameters to the initialization handler, and the description should not define an initialization handler that requires arguments.
此构造函数可以创建 Grammar 以下格式的实例:This constructor can create a Grammar instance from the following formats:
符合 W3C语音识别语法规范 (SRGS) 版本 1.0的 XML 格式文件XML-format files that conform to the W3C Speech Recognition Grammar Specification (SRGS) Version 1.0
已编译为带有 cfg 文件扩展名的二进制文件的语法Grammars that have been compiled to a binary file with a .cfg file extension
此构造函数将 XML 格式语法文件编译为二进制格式,以优化语音识别引擎的加载和使用。This constructor compiles XML-format grammar files to a binary format to optimize them for loading and consumption by a speech recognition engine. 您可以 Grammar 通过使用其中一种方法预先编译语法来减少从 XML 格式语法构造对象所需的时间 Compile 。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.
若要 Grammar 从流创建,并指定要使用的基 URI 来解析相对规则引用,请使用 Grammar 构造函数。To create a Grammar from a stream and specify a base URI to use to resolve relative rule references, use the Grammar constructor.
另请参阅
适用于
Grammar(String)
public:
Grammar(System::String ^ path);
public Grammar (string path);
new System.Speech.Recognition.Grammar : string -> System.Speech.Recognition.Grammar
Public Sub New (path As String)
参数
- path
- String
以受支持的格式描述语音识别语法的文件路径。The path of the file that describes a speech recognition grammar in a supported format.
例外
path 包含了空字符串 (""),或该文件对不包含根规则的语法进行了介绍。path contains the empty string (""), or the file describes a grammar that does not contain a root rule.
path 为 null。path is null.
文件不包含有效的说明,也不描述包含一个规则引用无法解析的语法。The file does not contain a valid description, or describes a grammar that contains a rule reference that cannot be resolved.
示例
下面的示例从本地 SRGS 文件加载语音识别语法,以生成 Grammar 对象。The following example loads a speech recognition grammar from a local SRGS file to build a Grammar object. cities.xml 文件的内容将显示在遵循 c # 示例的 XML 示例中。The content of the cities.xml file appears in the XML example that follows the C# example.
// Load a cities grammar from a local file and
// return the new grammar.
private static Grammar CreateGrammarFromFile()
{
Grammar citiesGrammar = new Grammar(@"c:\temp\cities.xml");
citiesGrammar.Name = "SRGS File Cities Grammar";
return citiesGrammar;
}
<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
tag-format="semantics/1.0" root="Main">
<!-- cities.xml:
Defines an SRGS grammar for requesting a flight. This grammar includes
a Cities rule that lists the cities that can be used for departures
and destinations. -->
<rule id="Main">
<item>
I would like to fly from <ruleref uri="#Cities"/>
to <ruleref uri="#Cities"/>
</item>
</rule>
<rule id="Cities" scope="public">
<one-of>
<item>Seattle</item>
<item>Los Angeles</item>
<item>New York</item>
<item>Miami</item>
</one-of>
</rule>
</grammar>
注解
此构造函数不会将任何参数传递给初始化处理程序,并且说明不应定义需要参数的初始化处理程序。This constructor does not pass any parameters to the initialization handler, and the description should not define an initialization handler that requires arguments.
此构造函数可以创建 Grammar 以下格式的实例:This constructor can create a Grammar instance from the following formats:
符合 W3C语音识别语法规范 (SRGS) 版本 1.0的 XML 格式文件XML-format files that conform to the W3C Speech Recognition Grammar Specification (SRGS) Version 1.0
已编译为带有 cfg 文件扩展名的二进制文件的语法Grammars that have been compiled to a binary file with a .cfg file extension
此构造函数将 XML 格式语法文件编译为二进制格式,以优化语音识别引擎的加载和使用。This constructor compiles XML-format grammar files to a binary format to optimize them for loading and consumption by a speech recognition engine. 您可以 Grammar 通过使用其中一种方法预先编译语法来减少从 XML 格式语法构造对象所需的时间 Compile 。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.
SRGS 语法可以定义根规则。An SRGS grammar can define a root rule. 若要 Grammar 通过字符串创建对象并指定根规则,请使用 Grammar 构造函数。To create a Grammar object from a string and specify a root rule, use the Grammar constructor.
若要创建一个 Grammar 对象,该对象指定用于解析相对规则引用的基本 URI,请在文件流中打开该文件,并使用 Grammar.Grammar 构造函数。To create a Grammar object that specifies a base URI to use to resolve relative rule references, open the file in a file stream and use the Grammar.Grammar constructor.
另请参阅
适用于
Grammar(SrgsDocument)
从 Grammar 对象初始化 SrgsDocument 类的新实例。Initializes a new instance of a Grammar class from an SrgsDocument object.
public:
Grammar(System::Speech::Recognition::SrgsGrammar::SrgsDocument ^ srgsDocument);
public Grammar (System.Speech.Recognition.SrgsGrammar.SrgsDocument srgsDocument);
new System.Speech.Recognition.Grammar : System.Speech.Recognition.SrgsGrammar.SrgsDocument -> System.Speech.Recognition.Grammar
Public Sub New (srgsDocument As SrgsDocument)
参数
- srgsDocument
- SrgsDocument
语音识别语法的约束。The constraints for the speech recognition grammar.
例外
srgsDocument 不包含根规则。srgsDocument does not contain a root rule.
srgsDocument 为 null。srgsDocument is null.
srgsDocument 包含无法解析的规则引用。srgsDocument contains a rule reference that cannot be resolved.
示例
下面的示例在实例中创建语音识别语法 SrgsDocument ,然后使用该语法构造 Grammar 对象。The following example creates a speech recognition grammar in an SrgsDocument instance, which is then used to construct a Grammar object.
private static Grammar CreateSrgsDocumentGrammar()
{
// Create the SrgsDocument.
SrgsDocument document = new SrgsDocument();
// Create the Cities rule and add it to the document.
SrgsRule citiesRule = new SrgsRule("Cities");
SrgsOneOf cityChoice = new SrgsOneOf();
cityChoice.Add(new SrgsItem("Seattle"));
cityChoice.Add(new SrgsItem("Los Angeles"));
cityChoice.Add(new SrgsItem("New York"));
cityChoice.Add(new SrgsItem("Miami"));
citiesRule.Add(cityChoice);
document.Rules.Add(citiesRule);
// Create the Main rule and add it to the document.
SrgsRule mainRule = new SrgsRule("Main");
mainRule.Scope = SrgsRuleScope.Public;
SrgsItem item = new SrgsItem("I would like to fly from");
item.Add(new SrgsRuleRef(citiesRule));
item.Add(new SrgsText("to"));
item.Add(new SrgsRuleRef(citiesRule));
mainRule.Add(item);
document.Rules.Add(mainRule);
// Set the root rule.
document.Root = mainRule;
// Create the Grammar object.
Grammar citiesGrammar = new Grammar(document);
citiesGrammar.Name = "SrgsDocument Cities Grammar";
return citiesGrammar;
}
注解
此构造函数不会将任何参数传递给初始化处理程序,并且 SrgsDocument 不应包含需要参数的初始化处理程序。This constructor does not pass any parameters to the initialization handler, and the SrgsDocument should not contain an initialization handler that requires arguments.
SrgsDocument可以具有根规则。A SrgsDocument can have a root rule. 若要创建 Grammar 指定根规则的对象,请使用 Grammar 或 Grammar 构造函数。To create a Grammar object that specifies a root rule, use the Grammar or Grammar constructor.
若要从创建语音识别 Grammar SrgsDocument ,并指定要用于解析相对规则引用的基本 URI,请使用 Grammar 构造函数。To create a speech recognition Grammar from an SrgsDocument and specify a base URI to use to resolve relative rule references, use the Grammar constructor.
另请参阅
- System.Speech.Recognition.SrgsGrammar
- SrgsDocument
- SpeechRecognizer
- SpeechRecognitionEngine
- 语音识别语法规范Speech Recognition Grammar Specification
适用于
Grammar(String, String)
public:
Grammar(System::String ^ path, System::String ^ ruleName);
public Grammar (string path, string ruleName);
new System.Speech.Recognition.Grammar : string * string -> System.Speech.Recognition.Grammar
Public Sub New (path As String, ruleName As String)
参数
- path
- String
以受支持的格式描述语音识别语法的文件路径。The path of the file that describes a speech recognition grammar in a supported format.
- ruleName
- String
用作语音识别语法的入口点的规则标识符,或以使用语法说明的默认根规则 null 。The identifier of the rule to use as the entry point of the speech recognition grammar, or null to use the default root rule of the grammar description.
例外
ruleName 无法解析或非公共,path 为空字符串 (""),或者 ruleName 为 null,并且语法说明不定义根规则。ruleName cannot be resolved or is not public, path is the empty string (""), or ruleName is null and the grammar description does not define a root rule.
path 为 null。path is null.
文件不包含有效的说明,也不描述包含一个规则引用无法解析的语法。The file does not contain a valid description or describes a grammar that contains a rule reference that cannot be resolved.
示例
下面的示例从文件中加载本地 SRGS 文件 (cities.xml) ,并指定要用作语法的根的规则。The following example loads a local SRGS file (cities.xml) from a file and specifies a rule to use as the root of the grammar. cities.xml 文件的内容将显示在遵循 c # 示例的 XML 示例中。The content of the cities.xml file appears in the XML example that follows the C# example.
// Load a cities grammar from a local file, use a specific
// rule as the root of the grammar, and return the new grammar.
private static Grammar CreateGrammarFromFile2()
{
Grammar citiesGrammar = new Grammar(@"c:\temp\cities.xml", "Main");
citiesGrammar.Name = "SRGS File Cities Grammar 2";
return citiesGrammar;
}
<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
tag-format="semantics/1.0" root="Main">
<!-- cities.xml:
Defines an SRGS grammar for requesting a flight. This grammar includes
a Cities rule that lists the cities that can be used for departures
and destinations. -->
<rule id="Main">
<item>
I would like to fly from <ruleref uri="#Cities"/>
to <ruleref uri="#Cities"/>
</item>
</rule>
<rule id="Cities" scope="public">
<one-of>
<item>Seattle</item>
<item>Los Angeles</item>
<item>New York</item>
<item>Miami</item>
</one-of>
</rule>
</grammar>
注解
此构造函数不会将任何参数传递给初始化处理程序,并且说明不应定义需要参数的初始化处理程序。This constructor does not pass any parameters to the initialization handler, and the description should not define an initialization handler that requires arguments.
此构造函数可以创建 Grammar 以下格式的实例:This constructor can create a Grammar instance from the following formats:
符合 W3C语音识别语法规范 (SRGS) 版本 1.0的 XML 格式文件XML-format files that conform to the W3C Speech Recognition Grammar Specification (SRGS) Version 1.0
已编译为带有 cfg 文件扩展名的二进制文件的语法Grammars that have been compiled to a binary file with a .cfg file extension
此构造函数将 XML 格式语法文件编译为二进制格式,以优化语音识别引擎的加载和使用。This constructor compiles XML-format grammar files to a binary format to optimize them for loading and consumption by a speech recognition engine. 您可以 Grammar 通过使用其中一种方法预先编译语法来减少从 XML 格式语法构造对象所需的时间 Compile 。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.
若要创建一个 Grammar 指定要用于解析相对规则引用的基 URI 的,请打开该文件的文件流并使用 Grammar 构造函数。To create a Grammar that specifies a base URI to use to resolve relative rule references, open a file stream for the file and use the Grammar constructor.
另请参阅
适用于
Grammar(GrammarBuilder)
从 Grammar 对象初始化 GrammarBuilder 类的新实例。Initializes a new instance of the Grammar class from a GrammarBuilder object.
public:
Grammar(System::Speech::Recognition::GrammarBuilder ^ builder);
public Grammar (System.Speech.Recognition.GrammarBuilder builder);
new System.Speech.Recognition.Grammar : System.Speech.Recognition.GrammarBuilder -> System.Speech.Recognition.Grammar
Public Sub New (builder As GrammarBuilder)
参数
- builder
- GrammarBuilder
包含语音识别语法的约束的 GrammarBuilder 的实例。An instance of GrammarBuilder that contains the constraints for the speech recognition grammar.
示例
下面的示例使用和对象创建语音识别 Choices 语法 GrammarBuilder 。The following example creates a speech recognition grammar using Choices and GrammarBuilder objects. Grammar构造函数 Grammar 从对象中创建对象 GrammarBuilder 。The Grammar constructor creates a Grammar object from the GrammarBuilder object.
// Create a grammar using a GrammarBuilder and return the new grammar.
private static Grammar CreateGrammarBuilderGrammar()
{
GrammarBuilder builder = new GrammarBuilder();
Choices cityChoice = new Choices (new string[]
{"Seattle", "New York", "Miami", "Los Angeles"});
builder.Append("I would like to fly from");
builder.Append(cityChoice);
builder.Append("to");
builder.Append(cityChoice);
Grammar citiesGrammar = new Grammar(builder);
citiesGrammar.Name = "GrammarBuilder Cities Grammar";
return citiesGrammar;
}
另请参阅
适用于
Grammar(Stream)
public:
Grammar(System::IO::Stream ^ stream);
public Grammar (System.IO.Stream stream);
new System.Speech.Recognition.Grammar : System.IO.Stream -> System.Speech.Recognition.Grammar
Public Sub New (stream As Stream)
参数
- stream
- Stream
以受支持的格式描述语音识别语法的流。A stream that describes a speech recognition grammar in a supported format.
例外
stream 描述未包含根规则的语法。stream describes a grammar that does not contain a root rule.
stream 为 null。stream is null.
流不包含有效的语法说明,也不描述包含一个规则引用无法解析的语法。The stream does not contain a valid description of a grammar, or describes a grammar that contains a rule reference that cannot be resolved.
示例
下面的示例通过使用文件流 (cities.xml) 在本地 SRGS 文件中创建语音识别语法。The following example creates a speech recognition grammar from a local SRGS file (cities.xml) using a file stream. 下面的 c # 示例将显示 cities.xml 文件的内容。The content of the cities.xml file appears following C# example.
// Load a cities grammar from an I/O stream and
// return the new grammar.
private static Grammar CreateGrammarFromStream()
{
string fileName = @"c:\temp\cities.xml";
Grammar citiesGrammar =
new Grammar(new FileStream(fileName, FileMode.Open));
citiesGrammar.Name = "Stream Cities Grammar";
return citiesGrammar;
}
<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
tag-format="semantics/1.0" root="Main">
<!-- cities.xml:
Defines an SRGS grammar for requesting a flight. This grammar includes
a Cities rule that lists the cities that can be used for departures
and destinations. -->
<rule id="Main">
<item>
I would like to fly from <ruleref uri="#Cities"/>
to <ruleref uri="#Cities"/>
</item>
</rule>
<rule id="Cities" scope="public">
<one-of>
<item>Seattle</item>
<item>Los Angeles</item>
<item>New York</item>
<item>Miami</item>
</one-of>
</rule>
</grammar>
注解
此构造函数不会将任何参数传递给初始化处理程序,并且说明不应定义需要参数的初始化处理程序。This constructor does not pass any parameters to the initialization handler, and the description should not define an initialization handler that requires arguments.
此构造函数可以创建 Grammar 以下格式的实例:This constructor can create a Grammar instance from the following formats:
符合 W3C语音识别语法规范 (SRGS) 版本 1.0的 XML 格式文件XML-format files that conform to the W3C Speech Recognition Grammar Specification (SRGS) Version 1.0
已编译为带有 cfg 文件扩展名的二进制文件的语法Grammars that have been compiled to a binary file with a .cfg file extension
此构造函数将 XML 格式语法文件编译为二进制格式,以优化语音识别引擎的加载和使用。This constructor compiles XML-format grammar files to a binary format to optimize them for loading and consumption by a speech recognition engine. 您可以 Grammar 通过使用其中一种方法预先编译语法来减少从 XML 格式语法构造对象所需的时间 Compile 。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.
SRGS 语法可以定义根规则。An SRGS grammar can define a root rule. 若要 Grammar 从流创建对象并指定根规则,请使用 Grammar 或 Grammar 构造函数。To create a Grammar object from a stream and specify a root rule, use the Grammar or Grammar constructor.
若要 Grammar 从流创建对象并指定要使用的基 URI 来解析相对规则引用,请使用 Grammar 构造函数。To create a Grammar object from a stream and specify a base URI to use to resolve relative rule references, use the Grammar constructor.