Пример #1
0
 public void StopListening()
 {
     if (ListeningState == ListeningState.Active)
     {
         ListeningState = ListeningState.Inactive;
         _timer.Stop();
     }
 }
Пример #2
0
 public void StartListening()
 {
     if (ListeningState == ListeningState.Inactive)
     {
         ListeningState   = ListeningState.Active;
         _timer.AutoReset = true;
         _timer.Interval  = 10; //ms
         _timer.Elapsed  += _timer_Elapsed;
         _timer.Start();
     }
 }
Пример #3
0
        private async Task changeStateAsync(ListeningState state)
        {
            if (listeningState != state)
            {
                System.Diagnostics.Debug.WriteLine($"Changing CommandInterpreter listening state to {state}");

                if (state == ListeningState.Hypothesis)
                {
                    preHypothesisListeningState = listeningState;
                }

                listeningState = state;

                await listener.StopListeningAsync();

                switch (state)
                {
                case ListeningState.Move:
                    SpeechConstraints.EnableGrammar(recognizer.Constraints, GrammarMode.MoveCommands, true);
                    SpeechConstraints.EnableGrammar(recognizer.Constraints, GrammarMode.PieceConfirmation, false);
                    SpeechConstraints.EnableGrammar(recognizer.Constraints, GrammarMode.YesNoCommands, false);
                    SpeechConstraints.EnableGrammar(recognizer.Constraints, GrammarMode.CancelCommand, false);
                    break;

                case ListeningState.PieceConfirmation:
                    SpeechConstraints.EnableGrammar(recognizer.Constraints, GrammarMode.PieceConfirmation, true);
                    SpeechConstraints.EnableGrammar(recognizer.Constraints, GrammarMode.MoveCommands, false);
                    SpeechConstraints.EnableGrammar(recognizer.Constraints, GrammarMode.YesNoCommands, false);
                    SpeechConstraints.EnableGrammar(recognizer.Constraints, GrammarMode.CancelCommand, true);
                    break;

                case ListeningState.Hypothesis:
                    SpeechConstraints.EnableGrammar(recognizer.Constraints, GrammarMode.YesNoCommands, true);
                    SpeechConstraints.EnableGrammar(recognizer.Constraints, GrammarMode.MoveCommands, false);
                    SpeechConstraints.EnableGrammar(recognizer.Constraints, GrammarMode.PieceConfirmation, false);
                    SpeechConstraints.EnableGrammar(recognizer.Constraints, GrammarMode.CancelCommand, true);
                    break;

                default:
                    await listener.StartListeningAsync();

                    throw new Exception("Tried to change CommandInterpreter state to an unknown listening state");
                }

                await listener.StartListeningAsync();
            }
        }
        private void _speechRecognitionEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            if (e.Result.Confidence < _configuration.ConfidenceLevel)
            {
                Console.WriteLine($"Confidence level not reached ({e.Result.Confidence})");
                return;
            }

            if (ListeningState == ListeningState.Passive)
            {
                ListeningState = ListeningState.Active;
                Console.WriteLine($"Listening State changed to Active");

                LoadActiveGrammar();
            }

            // Must be in Active state

            Command       command       = Command.Get(e.Result.Text);
            CommandResult commandResult = command.Execute();

            Console.WriteLine($"Speech Recognised= {e.Result.Text}; Confidence={e.Result.Confidence}");
        }