public GrammarBuilder(Choices alternateChoices) : this() { Append(alternateChoices); }
// Append one-of public void Append(Choices alternateChoices) { Helpers.ThrowIfNull(alternateChoices, nameof(alternateChoices)); AddItem(alternateChoices.OneOf); }
private void SpeechToText() { // Configure the input to the recognizer. sre.SetInputToDefaultAudioDevice(); // Create a simple grammar that recognizes "red", "green", or "blue". recog.Choices queries = new recog.Choices(); queries.Add(dictionary); // Create a GrammarBuilder object and append the Choices object. recog.GrammarBuilder gb = new recog.GrammarBuilder(); gb.Append(queries); // Create the Grammar instance and load it into the speech recognition engine. recog.Grammar g = new recog.Grammar(gb); sre.LoadGrammar(g); // Register a handler for the SpeechRecognized event. sre.SpeechRecognized += new EventHandler<recog.SpeechRecognizedEventArgs>(sre_SpeechRecognized); // Start recognition. sre.Recognize(); }
private sp.Grammar GeneratePauseGrammar() { sp.Choices choices = new sp.Choices(); foreach (string pausePhrase in this.currentProfile.PauseRecognitionPhrases) { sp.SemanticResultValue temp = new sp.SemanticResultValue(pausePhrase, "PauseVoiceRecognitionCommand"); choices.Add(temp); } foreach (string unpausePhrase in this.currentProfile.UnpauseRecognitionPhrases) { sp.SemanticResultValue temp = new sp.SemanticResultValue(unpausePhrase, "UnpauseVoiceRecognitionCommand"); choices.Add(temp); } sp.GrammarBuilder builder = new sp.GrammarBuilder(); builder.Append(new sp.SemanticResultKey("command", choices)); sp.Grammar grammar = new sp.Grammar(builder); grammar.Name = "PauseCommands"; return grammar; }
public sp.Grammar UpdateGrammar() { bool atLeastOnePhrase = false; sp.Choices choices = new sp.Choices(); foreach (Action action in this.Actions) { foreach (string phrase in action.Phrases) { sp.SemanticResultValue temp = new sp.SemanticResultValue(phrase, action.ActionName); choices.Add(temp); atLeastOnePhrase = true; } } if (atLeastOnePhrase) { sp.GrammarBuilder builder = new sp.GrammarBuilder(); builder.Append(new sp.SemanticResultKey("command", choices)); this.Grammar = new sp.Grammar(builder); this.Grammar.Name = this.ProfileName; return this.Grammar; } else return null; }
public sp.Grammar UpdateGrammar() { sp.GrammarBuilder commands = new sp.GrammarBuilder(); sp.Choices choices = new sp.Choices(); foreach (Action action in this.Actions) { foreach (string phrase in action.Phrases) { sp.SemanticResultValue temp = new sp.SemanticResultValue(phrase, action.ActionName); choices.Add(temp); commands.Append(temp); } } commands.Append(choices); sp.GrammarBuilder builder = new sp.GrammarBuilder(); builder.Append(new sp.SemanticResultKey("command", choices)); this.Grammar = new sp.Grammar(builder); this.Grammar.Name = this.ProfileName; return this.Grammar; }