public static async Task <CommandInterpreter> CreateAsync() { var speechRecognizer = new SpeechRecognizer(); var interpreter = new CommandInterpreter(speechRecognizer, new Communicator()); var grammarCompilationResult = await interpreter.setupGrammarConstraintsAsync(); if (grammarCompilationResult.Status != SpeechRecognitionResultStatus.Success) { throw new FormatException($"Could not compile grammar constraints. Received error {grammarCompilationResult.Status}"); } return(interpreter); }
public static async Task <CommandInterpreter> CreateAsync() { var speechRecognizer = new SpeechRecognizer(); var interpreter = new CommandInterpreter(speechRecognizer, new Communicator()); var grammarCompilationResult = await interpreter.setupGrammarConstraintsAsync(); if (grammarCompilationResult.Status != SpeechRecognitionResultStatus.Success) { throw new FormatException($"Could not compile grammar constraints. Received error {grammarCompilationResult.Status}"); } // Disable unnecessary grammars SpeechConstraints.EnableGrammar(speechRecognizer.Constraints, GrammarMode.MoveCommands, true); SpeechConstraints.EnableGrammar(speechRecognizer.Constraints, GrammarMode.PieceConfirmation, false); SpeechConstraints.EnableGrammar(speechRecognizer.Constraints, GrammarMode.YesNoCommands, false); SpeechConstraints.EnableGrammar(speechRecognizer.Constraints, GrammarMode.CancelCommand, false); return(interpreter); }