This topic has not yet been rated - Rate this topic

SpeechRecognitionEngine.Grammars Property

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

Namespace:  System.Speech.Recognition
Assembly:  System.Speech (in System.Speech.dll)
public ReadOnlyCollection<Grammar> Grammars { get; }

Property Value

Type: System.Collections.ObjectModel.ReadOnlyCollection<Grammar>
Returns an list of the Grammar objects loaded into the current instance of the SpeechRecognizer.

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();
}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ