コード例 #1
0
        public override IObservable <string> ListenUntilPause()
        {
            return(Observable.Create <string>(async ob =>
            {
                var speech = new WinSpeechRecognizer();
                await speech.CompileConstraintsAsync();
                this.ListenSubject.OnNext(true);

                var handler = new TypedEventHandler <SpeechContinuousRecognitionSession, SpeechContinuousRecognitionResultGeneratedEventArgs>((sender, args) =>
                {
                    var words = args.Result.Text.Split(' ');
                    foreach (var word in words)
                    {
                        ob.OnNext(word);
                    }
                });
                speech.ContinuousRecognitionSession.ResultGenerated += handler;
                await speech.ContinuousRecognitionSession.StartAsync();

                return () =>
                {
                    speech.ContinuousRecognitionSession.StopAsync();
                    speech.ContinuousRecognitionSession.ResultGenerated -= handler;
                    this.ListenSubject.OnNext(false);
                    speech.Dispose();
                };
            }));
        }
コード例 #2
0
        public override IObservable <string> ContinuousDictation() => Observable.Create <string>(async ob =>
        {
            var speech = new WinSpeechRecognizer();
            await speech.CompileConstraintsAsync();

            var handler = new TypedEventHandler <SpeechContinuousRecognitionSession, SpeechContinuousRecognitionResultGeneratedEventArgs>((sender, args) =>
                                                                                                                                          ob.OnNext(args.Result.Text)
                                                                                                                                          );
            speech.ContinuousRecognitionSession.ResultGenerated += handler;
            await speech.ContinuousRecognitionSession.StartAsync();
            this.ListenSubject.OnNext(true);

            return(() =>
            {
                //speech.ContinuousRecognitionSession.StopAsync();
                speech.ContinuousRecognitionSession.ResultGenerated -= handler;
                this.ListenSubject.OnNext(false);
                speech.Dispose();
            });
        });
コード例 #3
0
        public override IObservable <string> ContinuousDictation()
        {
            return(Observable.Create <string>(async ob =>
            {
                var speech = new WinSpeechRecognizer();
                await speech.CompileConstraintsAsync();
                this.ListenSubject.OnNext(true);
                var result = await speech.RecognizeAsync();
                var words = result.Text.Split(' ');

                foreach (var word in words)
                {
                    ob.OnNext(word);
                }

                return () =>
                {
                    this.ListenSubject.OnNext(false);
                    speech.Dispose();
                };
            }));
        }
コード例 #4
0
 protected override void Dispose(bool disposing)
 {
     speechRecognizer.Dispose();
     base.Dispose(disposing);
 }