SpeechRecognitionEngine.Grammars Property
Read-only property returning a list of all Grammar objects loaded into the current instance of the SpeechRecognitionEngine.
Assembly: System.Speech (in System.Speech.dll)
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();
}
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
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.