private async Task RecognizeSpeechAsync() { activityIndicator.IsRunning = true; Debug.WriteLine("Sending record file to server"); var speechResult = await bingSpeechService.RecognizeSpeechAsync(Constants.AudioFilename); activityIndicator.IsRunning = false; Debug.WriteLine("Name: " + speechResult.DisplayText); Debug.WriteLine("Recognition Status: " + speechResult.RecognitionStatus); if (!string.IsNullOrWhiteSpace(speechResult.DisplayText)) { if (speechResult.RecognitionStatus == "Success") { string formatedResult = char.ToUpper(speechResult.DisplayText[0]) + speechResult.DisplayText.Substring(1); string location = GetLocationFromText(formatedResult); speechLabel.Text = "Navigating to:" + location; await NavigateToAsync(location); } else { textToSpeechService.Speak($"{speechResult.RecognitionStatus}"); await DisplayAlert("Sorry failed to recognize", $"{speechResult.RecognitionStatus}", "OK, I will try again"); } } }
async void OnRecognizeSpeechButtonClicked(object sender, EventArgs e) { try { var audioRecordingService = DependencyService.Get <IAudioRecorderService>(); if (!isRecording) { audioRecordingService.StartRecording(); ((Button)sender).Image = "recording.png"; IsProcessing = true; } else { audioRecordingService.StopRecording(); } isRecording = !isRecording; if (!isRecording) { var speechResult = await bingSpeechService.RecognizeSpeechAsync(Constants.AudioFilename); if (speechResult.Name.ToUpper().Equals(this.reteived.Name.ToUpper())) { DisplayAlert("Great !!!!", "Let's try another one !", "OK"); } else { DisplayAlert("Oupps", "It's " + this.reteived.Name + " not " + speechResult.Name, "Let's try again !"); } Debug.WriteLine("Name: " + speechResult.Name); Debug.WriteLine("Confidence: " + speechResult.Confidence); if (!string.IsNullOrWhiteSpace(speechResult.Name)) { TodoItem.Name = char.ToUpper(speechResult.Name[0]) + speechResult.Name.Substring(1); OnPropertyChanged("TodoItem"); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { if (!isRecording) { ((Button)sender).Image = "record.png"; IsProcessing = false; } } }
async void OnRecognizeSpeechButtonClicked(object sender, EventArgs e) { try { var audioRecordingService = DependencyService.Get <IAudioRecorderService>(); if (!isRecording) { audioRecordingService.StartRecording(); Status = "Listening..."; ((Button)sender).Image = "microphone_on.png"; IsProcessing = true; } else { audioRecordingService.StopRecording(); } isRecording = !isRecording; if (!isRecording) { Status = "Converting to text..."; var speechResult = await bingSpeechService.RecognizeSpeechAsync(Constants.AudioFilename); Debug.WriteLine("Name: " + speechResult.Name); Debug.WriteLine("Confidence: " + speechResult.Confidence); if (!string.IsNullOrWhiteSpace(speechResult.Name)) { PatientNotesItem.Name = char.ToUpper(speechResult.Name[0]) + speechResult.Name.Substring(1); OnPropertyChanged("PatientNotesItem"); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { if (!isRecording) { Status = ""; ((Button)sender).Image = "microphone_off.png"; IsProcessing = false; } } }
async void OnRecognizeSpeechButtonClicked(object sender, EventArgs e) { try { var audioRecordingService = DependencyService.Get <IAudioRecorderService>(); if (!isRecording) { audioRecordingService.StartRecording(); ((Button)sender).Image = "microphone.png"; IsProcessing = true; } else { audioRecordingService.StopRecording(); } isRecording = !isRecording; if (!isRecording) { Debug.WriteLine("This is where"); string speechResult = await bingSpeechService.RecognizeSpeechAsync(Constants.AudioFilename); Debug.WriteLine("Result: " + speechResult); DisplayResult.Text += speechResult; /*Debug.WriteLine("Confidence: " + speechResult.Confidence);*/ /*if (!string.IsNullOrWhiteSpace(speechResult.Name)) * { * StudyBlock.Reason = char.ToUpper(speechResult.Name[0]) + speechResult.Name.Substring(1); * OnPropertyChanged("StudyBlock"); * }*/ } } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { if (!isRecording) { ((Button)sender).Image = "microphone.png"; IsProcessing = false; } } }
async void OnRecognizeSpeechButtonClicked(object sender, EventArgs e) { try { var audioRecordingService = DependencyService.Get <IAudioRecorderService>(); if (!isRecording) { audioRecordingService.StartRecording(); ((Button)sender).ImageSource = "recording.png"; IsProcessing = true; } else { audioRecordingService.StopRecording(); } isRecording = !isRecording; if (!isRecording) { var speechResult = await bingSpeechService.RecognizeSpeechAsync(Constants.AudioFilename); Debug.WriteLine("Name: " + speechResult.DisplayText); Debug.WriteLine("Recognition Status: " + speechResult.RecognitionStatus); if (!string.IsNullOrWhiteSpace(speechResult.DisplayText)) { MeetingAssistantItem.Name = char.ToUpper(speechResult.DisplayText[0]) + speechResult.DisplayText.Substring(1); OnPropertyChanged("MeetingAssistantItem"); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { if (!isRecording) { ((Button)sender).ImageSource = "record.png"; IsProcessing = false; } } }
private async void OnRecognizeSpeechButtonClicked(object sender, EventArgs e) { try { var audioRecordingService = DependencyService.Get <IAudioRecorderService>(); if (!isRecording) { audioRecordingService.StartRecording(); ((Button)sender).Image = "recording.png"; IsProcessing = true; } else { audioRecordingService.StopRecording(); } isRecording = !isRecording; if (!isRecording) { var speechResult = await bingSpeechService.RecognizeSpeechAsync(Constants.AudioFilename); Debug.WriteLine($"Name: {speechResult.DisplayText}"); Debug.WriteLine($"Recognition status: {speechResult.RecognitionStatus}"); if (!string.IsNullOrWhiteSpace(speechResult.DisplayText)) { txtOutput.Text = speechResult.DisplayText; } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { if (!isRecording) { ((Button)sender).Image = "record.png"; IsProcessing = false; } } }
private async void speech() { try { IsBusy = true; var audioRecordingService = _dependencyService.Get <IAudioRecorderService>(); if (!isRecording) { audioRecordingService.StartRecording(); ButtonText = "Stop"; } else { ButtonText = "Start"; audioRecordingService.StopRecording(); } isRecording = !isRecording; if (!isRecording) { var speechResult = await bingSpeechService.RecognizeSpeechAsync(Constants.AudioFilename); Debug.WriteLine("Name: " + speechResult.Name); Debug.WriteLine("Confidence: " + speechResult.Confidence); Title = speechResult.Name; //if (!string.IsNullOrWhiteSpace(speechResult.Name)) //{ // TodoItem.Name = char.ToUpper(speechResult.Name[0]) + speechResult.Name.Substring(1); // OnPropertyChanged("TodoItem"); //} } } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { IsBusy = false; } }
async void Record_OnClick() { try { var audioRecordingService = DependencyService.Get <IAudioRecorderService>(); if (!isRecording) { recording.IsVisible = true; record.IsVisible = false; audioRecordingService.StartRecording(); // IsProcessing = true; } else { recording.IsVisible = false; record.IsVisible = true; audioRecordingService.StopRecording(); } isRecording = !isRecording; if (!isRecording) { speechResult = await bingSpeechService.RecognizeSpeechAsync(Constants.AudioFilename); if (!string.IsNullOrWhiteSpace(speechResult.DisplayText)) { var result = new SpeechItem(); result.SpeechText = speechResult.DisplayText; result.Speaker = " - "; ProcessResponse(result); } } } catch (Exception ex) { return; //Debug.WriteLine(ex.Message); } finally { } }
private async void OnRecognizeSpeechAsync() { try { if (Device.OS == TargetPlatform.iOS) { var speechService = DependencyService.Get <ISpeechService>(); speechService.OnMessageFired += (sender, args) => { var argument = args as SpeechEventArgs; if (argument != null) { Description.Value = argument.Message; } }; if (IsRecording) { speechService.StartRecording(); } else { speechService.StopRecording(); } } else { var audioRecordingService = DependencyService.Get <IAudioRecorderService>(); if (IsRecording) { audioRecordingService.StartRecording(); } else { audioRecordingService.StopRecording(); } if (!IsRecording) { var speechResult = await _bingSpeechService.RecognizeSpeechAsync(GlobalSettings.AudioFilename); Debug.WriteLine("Name: " + speechResult.Name); Debug.WriteLine("Confidence: " + speechResult.Confidence); if (!string.IsNullOrWhiteSpace(speechResult.Name)) { Description.Value = char.ToUpper(speechResult.Name[0]) + speechResult.Name.Substring(1); } } } } catch (Exception ex) { Debug.WriteLine(ex.Message); await DialogService.ShowAlertAsync("Can't detect speech!", "Audio record failure", "Try again"); } }
void OnRecognizeSpeechButtonClicked(object sender, EventArgs e) { var x = audioRecordingService; Device.BeginInvokeOnMainThread(async() => { try { Task <string> audioRecordTask = null; if (!audioRecordingService.IsRecording) { audioRecordTask = await audioRecordingService.StartRecording(); activityIndicator.IsVisible = true; spellsheckButton.IsEnabled = false; translationButton.IsEnabled = false; ((Button)sender).Image = "record.png"; } else { await audioRecordingService.StopRecording(); ((Button)sender).Image = "recording.png"; } //isRecording = !isRecording; if (!audioRecordingService.IsRecording) { var audioFile = await audioRecordTask; if (audioFile == null) { return; } var speechResult = await bingSpeechService.RecognizeSpeechAsync(audioFile, Constants.TextTranslatorApiKey); Debug.WriteLine("Name: " + speechResult.DisplayText); Debug.WriteLine("Recognition Status: " + speechResult.RecognitionStatus); if (!string.IsNullOrWhiteSpace(speechResult.DisplayText)) { Context.Item.Description = char.ToUpper(speechResult.DisplayText[0]) + speechResult.DisplayText.Substring(1); OnPropertyChanged("TodoItem"); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { if (!audioRecordingService.IsRecording) { //((Button)sender).Image = "record.png"; activityIndicator.IsVisible = false; spellsheckButton.IsEnabled = true; translationButton.IsEnabled = true; } } }); }