Note
Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.
Grammar Constructor (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.
Namespace: Microsoft.Speech.Recognition
Assembly: Microsoft.Speech (in Microsoft.Speech.dll)
Syntax
'Declaration
Public Sub New ( _
path As String, _
ruleName As String, _
baseUri As Uri _
)
'Usage
Dim path As String
Dim ruleName As String
Dim baseUri As Uri
Dim instance As New Grammar(path, ruleName, _
baseUri)
public Grammar(
string path,
string ruleName,
Uri baseUri
)
Parameters
- path
Type: System.String
The path to the file that contains the grammar specification.
- ruleName
Type: System.String
The identifier of the rule to use as the entry point of the speech recognition grammar, or a null reference (Nothing in Visual Basic) to use the default root rule of the grammar description.
- baseUri
Type: System.Uri
The base URI to use to resolve any relative rule reference in the grammar description, or a null reference (Nothing in Visual Basic).
Exceptions
Exception | Condition |
---|---|
ArgumentException | Thrown when path or ruleName are invalid. Thrown when the file specified by path does not contain a valid grammar or the rule ruleName, if the root rule initialization handler requires arguments, or if it has a relative rule reference not resolvable by the default base Uri rule for grammars. |
Remarks
The path argument:
Can never be a null reference (Nothing in Visual Basic), or Empty
The file specified by path can be an ordinary file or a DLL.
- DLL must contain instances of Grammar.
All other files must contain a grammar defined by W3C Speech Recognition Grammar Specification (SRGS) Version 1.0.
The ruleName argument:
May be a null reference (Nothing in Visual Basic) or Empty.
If ruleName is not a null reference (Nothing in Visual Basic) and the rule specified is not found in the grammar being loaded, an exception is generated.
If ruleName is a null reference (Nothing in Visual Basic), and the grammar contained in the file specified does not declare a root rule, an exception is generated.
The baseUri argument:
The value of baseUri should be an absolute URI, and can be a path or a file.
If the value of baseUri is a path, be sure to append a trailing slash.
The URI provided by baseUri is not validated when the Grammar object is constructed.
Instead, if the URI is invalid or any relative references are inaccessible, the SpeechRecognitionEngine generates and exception when it loads the grammar.
The recognition engine performs the following checks on Grammar objects it is loading:
Resolves all references with absolute URIs.
Checks the XML of Grammar being loaded for correct syntax.
Resolves references with the value of baseUri if it is non-null.