SpeechRecognitionEngine.Grammars Property

Read-only property returning a list of all Grammar objects loaded into the current instance of the SpeechRecognitionEngine.

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

Syntax

'Declaration

Property Value

Returns an list of the Grammar objects loaded into the current instance of the SpeechRecognitionEngine.

Example

In the example below, a recognizer is queried for a list of Grammar objects it has loaded, and the information displayed in a TreeView.

public void UpdateGrammarTree(TreeView grammarTreeView, SpeechRecognitionEngine recognizer){
    grammarTreeView.Nodes.Clear(); //clean up tree and repopulate
    foreach ( Grammar grammar in recognizer.Grammars ) {
//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;
grammarNode.ForeColor = Color.Red;
//Add rule name as next layer
if (grammar.RuleName != null) {
TreeNode ruleNode = new TreeNode(grammar.RuleName);
ruleNode.Tag = grammar.RuleName;
ruleNode.Checked = grammarNode.Checked;
grammarNode.Nodes.Add(ruleNode);
}
grammarTreeView.Nodes.Add(grammarNode);
grammarNode.ExpandAll();
    }
    grammarTreeView.ExpandAll();
    grammarTreeView.Show();
}

Thread Safety

All public static (Shared in Visual Basic) members of this type are thread-safe. Instance members are not guaranteed to be thread-safe.

Platforms

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition

Target Platforms

See Also

Reference

SpeechRecognitionEngine Class
SpeechRecognitionEngine Members
Microsoft.Speech.Recognition Namespace
Grammar Class
ReadOnlyCollection
SpeechRecognizer