示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SpeechCommand"/> class.
        /// </summary>
        /// <param name="result">
        /// The speech recognition result.
        /// </param>
        /// <param name="expectedPhraseKeys">
        /// The expected phrase keys.
        /// </param>
        public SpeechCommand(SpeechRecognitionResult result, IEnumerable <string> expectedPhraseKeys)
        {
            if (result == null)
            {
                throw new ArgumentNullException(nameof(result));
            }

            this.CommandName = result.RulePath[0];
            this.TextSpoken  = result.Text;
            this.CommandMode = result.GetSemanticInterpretationProperty("commandMode");
            this.Phrases     = result.GetPhraseResults(expectedPhraseKeys);
        }
        /// <summary>
        /// Retrieves a collection of phrase key and corresponding results from a <see cref="SpeechRecognitionResult"/>.
        /// </summary>
        /// <param name="result">
        /// The speech result.
        /// </param>
        /// <param name="phraseKeys">
        /// The phrase keys to retrieve.
        /// </param>
        /// <returns>
        /// Returns a Dictionary of key value pairs containing the phrase key and spoken phrase.
        /// </returns>
        public static Dictionary <string, string> GetPhraseResults(
            this SpeechRecognitionResult result,
            IEnumerable <string> phraseKeys)
        {
            var phrases = new Dictionary <string, string>();

            if (phraseKeys != null)
            {
                foreach (var phraseKey in phraseKeys)
                {
                    var phraseResult = result.GetSemanticInterpretationProperty(phraseKey);
                    phrases.Add(phraseKey, phraseResult);
                }
            }

            return(phrases);
        }