Listing 4: Creating or retrieving an existing rule named "CommandRule."
private ISpeechGrammarRule CommandsRule; CommandsRule = Grammar.Rules.Add("CommandsRule", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1); CommandsRule.Clear(); foreach (System.Data.DataRow theRow in ds.Tables["BackChat"].Rows) { object dummy = 0; string sCommand = theRow["Command"].ToString(); CommandsRule.InitialState.AddWordTransition(null, Command," ",SpeechGrammarWordType.SGLexical,null,0, ref dummy,0); } Grammar.Rules.Commit(); Grammar.CmdSetRuleState("CommandsRule", SpeechRuleState.SGDSActive);