Exemple #1
0
 public ChatPageViewModel(MajaConversation majaConversation, SpeechRecognitionService service)
 {
     MajaConversation             = majaConversation;
     SpeechRecognitionService     = service;
     UserReplyCommand             = new Command(SendUserReply);
     service.HypothesisGenerated += Service_HypothesisGenerated;
 }
Exemple #2
0
        private async void SendUserReply(object obj)
        {
            if (obj is IPossibleUserReply possibleUserReply)
            {
                await SpeechRecognitionService.Stop();

                await MajaConversation.QueryMajaForAnswers(possibleUserReply.Value, possibleUserReply.Text);
            }
        }
Exemple #3
0
        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;
            }
        }
Exemple #4
0
 private void Service_HypothesisGenerated(object sender, SpeechRecognitionHypothesisGeneratedEventArgs e)
 {
     MajaConversation.SetUserText(e.Hypothesis.Text.ToLower());
 }