public MainPage() { NavigationPage.SetHasNavigationBar(this, false); BindingContext = ARModel.GetInstance; // populate picker with available colors //foreach (string colorName in colorDict.Keys) //{ // settingsColorPicker.Items.Add(colorName); //} InitializeComponent(); // Ugly way to update UI, this is work-around to avoid update of ObservableCollection on Async Task // Device.StartTimer(TimeSpan.FromMilliseconds(500), UpdateView); switch (Device.RuntimePlatform) { case Device.UWP: speech = CrossSpeechRecognition.Current; listener = speech.ListenUntilPause(); Device.StartTimer(TimeSpan.FromMilliseconds(10), ListenPhrase); break; default: break; } }
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; } }); }
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); } } }); }