コード例 #1
0
ファイル: SpeechEngine.cs プロジェクト: arrebagrove/Mirror
        /// <summary>
        /// Handle events fired when a result is generated. This may include a garbage rule that fires when general room noise
        /// or side-talk is captured (this will have a confidence of Rejected typically, but may occasionally match a rule with
        /// low confidence).
        /// </summary>
        void OnContinuousRecognitionSessionResultGenerated(
            SpeechContinuousRecognitionSession sender,
            SpeechContinuousRecognitionResultGeneratedEventArgs args)
        {
            if (args.Result.Status != SpeechRecognitionResultStatus.Success)
            {
                return;
            }

            // Unpack event arg data.
            bool   hasConstraint = args.Result.Constraint != null;
            var    confidence    = args.Result.Confidence;
            string phrase        = args.Result.Text;

            // The garbage rule doesn't have a tag associated with it, and
            // the other rules return a string matching the tag provided
            // when the grammar was compiled.
            string tag = hasConstraint ? args.Result.Constraint.Tag : "unknown";

            if (tag == "unknown")
            {
                return;
            }

            if (hasConstraint && args.Result.Constraint.Type == SpeechRecognitionConstraintType.List)
            {
                // The List constraint type represents speech from
                // a compiled grammar of commands.
                var command = _intentInterpreter.GetPhraseIntent(phrase);

                // You may decide to use per-phrase confidence levels in order to
                // tune the behavior of your grammar based on testing.
                if (confidence == SpeechRecognitionConfidence.Medium ||
                    confidence == SpeechRecognitionConfidence.High)
                {
                    OnPhraseRecognized(new PhraseRecognizedEventArgs(phrase,
                                                                     command,
                                                                     args));
                }
            }
            else if (hasConstraint && args.Result.Constraint.Type == SpeechRecognitionConstraintType.Topic)
            {
                // The Topic constraint type represents speech from dictation.
                OnPhraseRecognized(new PhraseRecognizedEventArgs(phrase,
                                                                 Command.Dictation,
                                                                 args));
            }
        }