async Task <bool> AskQuestionMethodAsync(string question) { bool result = false; await TextToSpeechService.SpeakAsync(question, false).ConfigureAwait(false); await TextToSpeechService.SpeakAsync("Please, answer after the signal", false).ConfigureAwait(false); UIApplication.SharedApplication.InvokeOnMainThread(() => { AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.Playback); AVAudioSession.SharedInstance().SetActive(true); _audioPlayer = AVAudioPlayer.FromUrl(NSUrl.FromFilename(Path.Combine("Sounds", "tap.aif"))); _audioPlayer.PrepareToPlay(); _audioPlayer.Play(); }); StartListening(); var intRes = Task.WaitAny(new[] { _voiceRecognitionTCS.Task }, TimeSpan.FromSeconds(10)); if (intRes == -1) { throw new TaskCanceledException(); } result = await _voiceRecognitionTCS.Task; return(result); }
async Task <bool> AskQuestionMethodAsync(string question) { bool result = false; if (_speechRecognizer != null) { CancelDialog(); } _isMusicRunning = platformService.IsMusicRunning; if (_isMusicRunning) { platformService.PauseMusic(); } _handler = new Handler(Application.Context.MainLooper); await textToSpeechService.SpeakAsync(question, false); await textToSpeechService.SpeakAsync("Please, answer yes or no after the tone", false); Question = question; StartSpeechRecognition(); var intRes = Task.WaitAny(new[] { _voiceRecognitionTCS.Task }, TimeSpan.FromSeconds(repeatTimeoutSeconts)); if (intRes == -1) { throw new TaskCanceledException(); } result = await _voiceRecognitionTCS.Task; return(result); }
public async Task NotifyAsync(string title, string message, bool textToSpeech) { if (textToSpeech) { await _textToSpeechService.SpeakAsync(message); } await _dialogService.DisplayAlertAsync(title, message, "OK"); }
public async virtual Task NotifyAsync(string message) { if (!_platform.IsAppInForeground) { _notificationSender.SendLocalNotification("Toll Minder", message); } await _textToSpeech.SpeakAsync(message); }
async void OnSpeakButtonClicked(object sender, EventArgs e) { ITextToSpeechService service = DependencyService.Get <ITextToSpeechService>(DependencyFetchTarget.NewInstance); using (service as IDisposable) { await service.SpeakAsync("Hello world"); } }
private void Speak() { _textToSpeech.SpeakAsync(TextToSay); }