private async void SendUserReply(object obj) { if (obj is IPossibleUserReply possibleUserReply) { await SpeechRecognitionService.Stop(); await MajaConversation.QueryMajaForAnswers(possibleUserReply.Value, possibleUserReply.Text); } }
public async void StartListening() { //TODO: cancel option with cancellationtoken try { MajaConversation.MajaStatus = MajaListeningStatus.Listening; var result = await SpeechRecognitionService.RecognizeAsync(); if (result == null) { return; } if (result.Confidence == SpeechRecognitionConfidence.Medium || result.Confidence == SpeechRecognitionConfidence.High) { await MajaConversation.QueryMajaForAnswers(result.Text, addMessage : false); } else if (!string.IsNullOrEmpty(result.Text)) { MajaConversation.Messages.Add(new MajaConversationMessage("Das habe ich akustisch nicht verstanden, bitte sprich direkt in das Mikrofon")); } } catch (OperationCanceledException) { //_speechCancellationTokenSource = null; } catch (Exception ex) { //_speechCancellationTokenSource = null; if ((uint)ex.HResult == HResultPrivacyStatementDeclined) { // Show a UI link to the privacy settings. SpeechRecognitionService.ShowMessage("Please restart the program, permission of microphone denied"); await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-speechtyping")); } else { MajaConversation.Messages.Add(new MajaConversationMessage("Es kam beim Zugriff auf das Mikrofon zu einem Fehler. Bitte versuche es erneut.")); } } if (MajaConversation.MajaStatus != MajaListeningStatus.Speaking) { MajaConversation.MajaStatus = MajaListeningStatus.Idle; } }