Partager via


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

LoadGrammarCompletedEventArgs.Grammar Property

Gets the Grammar object that has completed loading.

Namespace:  Microsoft.Speech.Recognition
Assembly:  Microsoft.Speech (in Microsoft.Speech.dll)

Syntax

'Declaration
Public ReadOnly Property Grammar As Grammar
    Get
'Usage
Dim instance As LoadGrammarCompletedEventArgs
Dim value As Grammar

value = instance.Grammar
public Grammar Grammar { get; }

Property Value

Type: Microsoft.Speech.Recognition.Grammar
The Grammar object that has completed loading.

Remarks

The Grammar property returns the Grammar that an application specifies in a call to LoadGrammarAsync or LoadGrammarAsync(Grammar).

Examples

In the example below, a handler for SpeechRecognitionEngine.LoadGrammarCompleted uses the Grammar property to update a display of loaded Grammar objects.

//On load we update the display.
//A hash table is used to get the node information we added in AddToTree.
_recognizer.LoadGrammarCompleted +=
    delegate(object sender, LoadGrammarCompletedEventArgs eventArgs) {
        Grammar grammar = eventArgs.Grammar;
        SrgsDocument document;
        document = _grammarDocumentList[grammar] as SrgsDocument;
        if (grammar != null) {

//Should probably do a sanity check and remove node if it exists.
TreeNode grammarNode = new TreeNode(grammar.Name);
grammarNode.Checked = grammar.Enabled;
grammarNode.Tag = grammar;

if (document != null) {
    foreach (SrgsRule rule in document.Rules) {
        TreeNode ruleNode = new TreeNode(rule.Id);

        if (document.Root == rule) {
ruleNode.ForeColor = Color.Red;
        }

        ruleNode.Tag = rule;
        ruleNode.Checked = true;
        grammarNode.Nodes.Add(ruleNode);
    }
}
_grammarTreeView.Nodes.Add(grammarNode);
grammarNode.ExpandAll();
        }
    };

See Also

Reference

LoadGrammarCompletedEventArgs Class

LoadGrammarCompletedEventArgs Members

Microsoft.Speech.Recognition Namespace

Grammar

LoadGrammar

LoadGrammarAsync

LoadGrammarCompletedEventArgs