private void ContinuousRecognitionSession_ResultGenerated(SR.SpeechContinuousRecognitionSession sender, SR.SpeechContinuousRecognitionResultGeneratedEventArgs args)
        {
            if (args.Result.Status == SR.SpeechRecognitionResultStatus.Success)
            {
                Debug.WriteLine("Result Text:{0}, Confidence:{1}({2:F4}), Constraint:{3})",
                                args.Result.Text,
                                args.Result.Confidence,
                                args.Result.RawConfidence,
                                (args.Result.Constraint != null) ? args.Result.Constraint.Tag : "<No tag>");
                if (
                    (args.Result.Confidence == SR.SpeechRecognitionConfidence.High) || 
                    (args.Result.Confidence == SR.SpeechRecognitionConfidence.Medium))
                    {
                        switch (args.Result.Constraint.Tag)
                        {
                            case "EnableCommanding":
                                ProcessSpeechStatusChangeCommand(args.Result);
                                break;

                            case "Commands":
                                ProcessSpeechCommand(args.Result);
                                break;

                            default:
                                Debug.WriteLine($"**** Unknown constraint '{args.Result.Constraint.Tag}'");
                                break;
                        }
                    }
            }
            else
            {
                Debug.WriteLine("Result: status({0})", args.Result.Status);
            }
        }
 private void SpeechRecognizer_StateChanged(SR.SpeechRecognizer sender, SR.SpeechRecognizerStateChangedEventArgs args)
 {
     Debug.WriteLine($"- {args.State}");
 }
 private void SpeechRecognizer_RecognitionQualityDegrading(SR.SpeechRecognizer sender, SR.SpeechRecognitionQualityDegradingEventArgs args)
 {
     Debug.WriteLine($"- Speech quality: {args.Problem}");
 }
 private void ContinuousRecognitionSession_Completed(SR.SpeechContinuousRecognitionSession sender, SR.SpeechContinuousRecognitionCompletedEventArgs args)
 {
     Debug.WriteLine($"--> Speech reco session completed: {args.Status}");
     if (IsActive)
     {
         IsActive = false;
         Activated(this, IsActive);
     }
 }
 private void ProcessSpeechCommand(SR.SpeechRecognitionResult result)
 {
     if (result.SemanticInterpretation.Properties.Keys.Contains("action"))
     {
         var intentArgs = new SpeechIntentArgs(result.SemanticInterpretation.Properties["action"][0]);
         Debug.WriteLine($"--> Voice reco intent: {intentArgs.Intent}");
         // Execute the event
         SpeechCommandTriggered(this, intentArgs);
     }
 }
        private void ProcessSpeechStatusChangeCommand(SR.SpeechRecognitionResult result)
        {
            bool activationStatus = IsActive;
            if (result.SemanticInterpretation.Properties.Keys.Contains("action"))
            {
                var intent = result.SemanticInterpretation.Properties["action"][0];
                Debug.WriteLine($"--> Voice reco status change request: {intent}");

                switch (intent)
                {
                    case "ActivateSpeechReco":
                        IsActive = true;
                        break;

                    case "StopSpeechReco":
                        IsActive = false;
                        break;


                    default:
                        break;
                }

                if (activationStatus != IsActive)
                {
                    _commandingConstraint.IsEnabled = IsActive;

                    // Rise the event
                    Activated(this, IsActive);
                }
            }
        }