void DoConversation()
 {
     try
     {
         if (token == null)
         {
             //if (this.useContinuous)
             //{
             token = speechReconizer
                     .ContinuousDictation()
                     .Catch <string, Exception>(ex => Observable.Return(ex.ToString()))
                     .Subscribe(x => this.TextSpeech += " " + x);
             //}
             //else
             //{
             //token = speechReconizer
             //    .ListenUntilPause()
             //    .Subscribe(x => this.Text += " " + x);
             //}
         }
         else
         {
             token.Dispose();
             token           = null;
             this.ListenText = "";
         }
     }
     catch (Exception ex)
     {
     }
 }
Пример #2
0
        public DictationViewModel(ISpeechRecognizer speech, IUserDialogs dialogs)
        {
            IDisposable token = null;

            speech
            .WhenListeningStatusChanged()
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x => this.ListenText = x
                    ? "Stop Listening"
                    : "Start Dictation"
                       );


            this.ToggleListen = ReactiveCommand.Create(() =>
            {
                if (token == null)
                {
                    if (this.UseContinuous)
                    {
                        token = speech
                                .ContinuousDictation()
                                .ObserveOn(RxApp.MainThreadScheduler)
                                .Subscribe(
                            x => this.Text += " " + x,
                            ex => dialogs.Alert(ex.ToString())
                            );
                    }
                    else
                    {
                        token = speech
                                .ListenUntilPause()
                                .ObserveOn(RxApp.MainThreadScheduler)
                                .Subscribe(
                            x => this.Text = x,
                            ex => dialogs.Alert(ex.ToString())
                            );
                    }
                }
                else
                {
                    token.Dispose();
                    token = null;
                }
            });
        }
Пример #3
0
 /// <summary>
 /// Optimal observable for taking command (yes/no/maybe/go away/etc)
 /// </summary>
 /// <param name="keywords"></param>
 /// <returns></returns>
 public static IObservable <string> ListenForFirstKeyword(this ISpeechRecognizer speechRecognizer, params string[] keywords)
 => speechRecognizer
 .ContinuousDictation()
 .Select(x =>
 {
     var values = x.Split(' ');
     foreach (var value in values)
     {
         foreach (var keyword in keywords)
         {
             if (value.Equals(keyword, StringComparison.OrdinalIgnoreCase))
             {
                 return(value);
             }
         }
     }
     return(null);
 })
 .Where(x => x != null)
 .Take(1);
Пример #4
0
        public DictationViewModel(ISpeechRecognizer speech)
        {
            IDisposable token = null;

            speech
            .WhenListeningStatusChanged()
            .Subscribe(x => this.ListenText = x
                    ? "Stop Listening"
                    : "Start Dictation"
                       );

            this.ToggleListen = new Command(async() =>
            {
                if (speech.Status != SpeechRecognizerStatus.Available)
                {
                    this.ListenText = "Problem with speech recognition engine - " + speech.Status;
                    return;
                }

                var granted = await speech.RequestPermission();
                if (!granted)
                {
                    this.ListenText = "Invalid Permissions";
                    return;
                }
                if (token == null)
                {
                    token = speech
                            .ContinuousDictation()
                            //.Catch<string, Exception>(ex => Observable.Return(ex.ToString()))
                            .Subscribe(x => this.Text += " " + x);
                }
                else
                {
                    token.Dispose();
                    token = null;
                }
            });
        }
Пример #5
0
        public DictationViewModel(ISpeechRecognizer speech, IDialogs dialogs)
        {
            speech
            .WhenListeningStatusChanged()
            .SubOnMainThread(x => this.IsListening = x);


            this.ToggleListen = ReactiveCommand.Create(() =>
            {
                if (this.IsListening)
                {
                    this.Deactivate();
                }
                else
                {
                    if (this.UseContinuous)
                    {
                        speech
                        .ContinuousDictation()
                        .SubOnMainThread(
                            x => this.Text += " " + x,
                            ex => dialogs.Alert(ex.ToString())
                            )
                        .DisposedBy(this.DeactivateWith);
                    }
                    else
                    {
                        speech
                        .ListenUntilPause()
                        .SubOnMainThread(
                            x => this.Text = x,
                            ex => dialogs.Alert(ex.ToString())
                            )
                        .DisposedBy(this.DeactivateWith);
                    }
                }
            });
        }