private void OnSpeechRecognitionAndSentimentProcessed(object sender, SpeechRecognitionAndSentimentResult e) { if (this.currentRecommendation != null) { string alternativeUrl = null; // See if there is an alternative result based on keywords in the spoken text if (this.currentRecommendation.SpeechKeywordBehavior != null) { BehaviorAction behaviorAction = this.currentRecommendation.SpeechKeywordBehavior.FirstOrDefault(behavior => e.SpeechRecognitionText.IndexOf(behavior.Key, StringComparison.OrdinalIgnoreCase) != -1); if (behaviorAction != null) { alternativeUrl = behaviorAction.Url; } } // If we didn't find an alternative based on keywords see if we have a generic one based on the sentiment of the spoken text if (string.IsNullOrEmpty(alternativeUrl) && this.currentRecommendation.SpeechSentimentBehavior != null) { BehaviorAction behaviorAction = null; if (e.TextAnalysisSentiment <= 0.33) { // look for an override for negative sentiment behaviorAction = this.currentRecommendation.SpeechSentimentBehavior.FirstOrDefault(behavior => string.Compare(behavior.Key, "Negative", true) == 0); } else if (e.TextAnalysisSentiment >= 0.66) { // look for an override for positive sentiment behaviorAction = this.currentRecommendation.SpeechSentimentBehavior.FirstOrDefault(behavior => string.Compare(behavior.Key, "Positive", true) == 0); } if (behaviorAction != null) { alternativeUrl = behaviorAction.Url; } } if (!string.IsNullOrEmpty(alternativeUrl)) { webView.Navigate(new Uri(alternativeUrl)); } } }
private void OnSpeechRecognitionAndSentimentProcessed(object sender, SpeechRecognitionAndSentimentResult e) { this.DetectedLanguageBox.Text = e.DetectedLanguage; this.CallerTextBox.Text = e.TranslatedText; }