コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }