Example #1
0
        private async Task SetConstraintsAsync()
        {
            StorageFile roverCommandsActivationFile = await Package.Current.InstalledLocation.GetFileAsync("SRGS\\RoverCommandsActivation.grxml");
            StorageFile roverCommandsFile = await Package.Current.InstalledLocation.GetFileAsync("SRGS\\RoverCommands.grxml");
            _enableSpeechConstraint = new SR.SpeechRecognitionGrammarFileConstraint(
                                roverCommandsActivationFile,
                                "EnableCommanding");

            _commandingConstraint = new SR.SpeechRecognitionGrammarFileConstraint(
                                roverCommandsFile,
                                "Commands");

            Debug.WriteLine($"Activation file path: {roverCommandsActivationFile.Path}");
            Debug.WriteLine($"Commands file path: {roverCommandsFile.Path}");

            _speechRecognizer.Constraints.Add(_enableSpeechConstraint);
            _speechRecognizer.Constraints.Add(_commandingConstraint);
            _commandingConstraint.IsEnabled = false;
            var status = await _speechRecognizer.CompileConstraintsAsync();
            Debug.WriteLine($"Compilation ended with: {status.Status}");
        }
        private async Task SetConstraintsAsync()
        {
            StorageFile roverCommandsActivationFile = await Package.Current.InstalledLocation.GetFileAsync("SRGS\\RoverCommandsActivation.grxml");

            StorageFile roverCommandsFile = await Package.Current.InstalledLocation.GetFileAsync("SRGS\\RoverCommands.grxml");

            _enableSpeechConstraint = new SR.SpeechRecognitionGrammarFileConstraint(
                roverCommandsActivationFile,
                "EnableCommanding");

            _commandingConstraint = new SR.SpeechRecognitionGrammarFileConstraint(
                roverCommandsFile,
                "Commands");

            Debug.WriteLine($"Activation file path: {roverCommandsActivationFile.Path}");
            Debug.WriteLine($"Commands file path: {roverCommandsFile.Path}");

            _speechRecognizer.Constraints.Add(_enableSpeechConstraint);
            _speechRecognizer.Constraints.Add(_commandingConstraint);
            _commandingConstraint.IsEnabled = false;
            var status = await _speechRecognizer.CompileConstraintsAsync();

            Debug.WriteLine($"Compilation ended with: {status.Status}");
        }