Beispiel #1
0
            /// <summary>
            /// Initializes a new instance of the RecognizedSpeechMessage class.
            /// </summary>
            /// <param name="args">Event arguments.</param>
            internal RecognizedSpeechMessage(SpeechRecognizedEventArgs args)
            {
                this.category  = SpeechStreamHandler.SpeechEventCategory;
                this.eventType = "recognized";

                SpeechSemanticValue semanticValue = null;

                try
                {
                    semanticValue = new SpeechSemanticValue(args.Result.Semantics);
                }
                catch (InvalidOperationException)
                {
                    // Failed to parse semantics, leave it empty.
                }

                this.recognized = new MessageArgs
                {
                    grammar    = args.Result.Grammar.Name,
                    text       = args.Result.Text,
                    confidence = args.Result.Confidence,
                    semantics  = semanticValue,
                    alternates = SpeechRecognizedPhrase.CreateArray(args.Result.Alternates),
                    words      = SpeechWord.CreateArray(args.Result.Words)
                };
            }
Beispiel #2
0
            public static SpeechWord[] CreateArray(ICollection <RecognizedWordUnit> words)
            {
                var array = new SpeechWord[words.Count];
                int i     = 0;

                foreach (var word in words)
                {
                    array[i++] = new SpeechWord()
                    {
                        lexical = word.LexicalForm,
                        text    = word.Text
                    };
                }

                return(array);
            }
Beispiel #3
0
            /// <summary>
            /// Initializes a new instance of the Speech RecognizedPhrase class.
            /// </summary>
            /// <param name="phrase"></param>
            public SpeechRecognizedPhrase(RecognizedPhrase phrase)
            {
                SpeechSemanticValue semanticValue = null;

                try
                {
                    semanticValue = new SpeechSemanticValue(phrase.Semantics);
                }
                catch (InvalidOperationException)
                {
                    // Failed to parse semantics, leave it empty.
                }

                this.text       = phrase.Text;
                this.confidence = phrase.Confidence;
                this.grammar    = phrase.Grammar.Name;
                this.semantics  = semanticValue;
                this.words      = SpeechWord.CreateArray(phrase.Words);
            }