private async Task <SpeechRecognitionResult> Ask(string question, int timeout = 0, IEnumerable <string> responses = null) { await Say(question); _speechRecognizer.UIOptions.AudiblePrompt = question; if (timeout != 0) { _speechRecognizer.Timeouts.InitialSilenceTimeout = new TimeSpan(0, 0, timeout); } else { // Set this timeout as Default _speechRecognizer.Timeouts.InitialSilenceTimeout = new TimeSpan(0, 0, 30); } if (responses != null) { var listConstraint = new Windows.Media.SpeechRecognition.SpeechRecognitionListConstraint(responses, "answers"); _speechRecognizer.Constraints.Clear(); _speechRecognizer.Constraints.Add(listConstraint); await _speechRecognizer.CompileConstraintsAsync(); } else if (_speechRecognizer.Constraints.Any()) { _speechRecognizer.Constraints.Clear(); await _speechRecognizer.CompileConstraintsAsync(); } var result = await _speechRecognizer.RecognizeAsync(); return(result); }
private async void MainPage_Loaded(object sender, RoutedEventArgs e) { webview.Navigate(StartURL); foreach (string item in responses) listView.Items.Add(item); var listConstraint = new Windows.Media.SpeechRecognition.SpeechRecognitionListConstraint(responses, "yesOrNo"); speechRecognizer.UIOptions.ExampleText = @"左の商品から音声で選択してください?"; speechRecognizer.Constraints.Add(listConstraint); speechRecognizer.UIOptions.ShowConfirmation = true; // Compile the constraint. await speechRecognizer.CompileConstraintsAsync(); }
private async void MainPage_Loaded(object sender, RoutedEventArgs e) { webview.Navigate(StartURL); foreach (string item in responses) { listView.Items.Add(item); } var listConstraint = new Windows.Media.SpeechRecognition.SpeechRecognitionListConstraint(responses, "yesOrNo"); speechRecognizer.UIOptions.ExampleText = @"左の商品から音声で選択してください?"; speechRecognizer.Constraints.Add(listConstraint); speechRecognizer.UIOptions.ShowConfirmation = true; // Compile the constraint. await speechRecognizer.CompileConstraintsAsync(); }
private async void SpeechButton_Click(object sender, RoutedEventArgs e) { // Create an instance of SpeechRecognizer. this.speechRecognizer = new Windows.Media.SpeechRecognition.SpeechRecognizer(); // You could create this array dynamically. string[] responses = { "Start", "Stop", "Go left", "Go right" }; // Add a list constraint to the recognizer. var listConstraint = new Windows.Media.SpeechRecognition.SpeechRecognitionListConstraint(responses, "yesOrNo"); speechRecognizer.UIOptions.ExampleText = @"Ex. 'Yes', 'No'"; speechRecognizer.Constraints.Add(listConstraint); // Compile the constraint. await speechRecognizer.CompileConstraintsAsync(); // Start recognition. Windows.Media.SpeechRecognition.SpeechRecognitionResult speechRecognitionResult = await this.speechRecognizer.RecognizeWithUIAsync(); // Do something with the recognition result. var messageDialog = new Windows.UI.Popups.MessageDialog(speechRecognitionResult.Text, "Text spoken"); await messageDialog.ShowAsync(); }
//Lancement reconnaissance vocale private async void micro_Click(object sender, RoutedEventArgs e) { var speechRecognizer = new Windows.Media.SpeechRecognition.SpeechRecognizer(); string[] responses = commandesHttp[0].ToArray(); //Ne compare que avec des commandes vocale connue var listConstraint = new Windows.Media.SpeechRecognition.SpeechRecognitionListConstraint(responses, "commandeHttp"); speechRecognizer.UIOptions.ExampleText = @"Ex. 'Yana comment vas tu ?'"; speechRecognizer.Constraints.Add(listConstraint); await speechRecognizer.CompileConstraintsAsync(); Windows.Media.SpeechRecognition.SpeechRecognitionResult speechRecognitionResult = await speechRecognizer.RecognizeWithUIAsync(); allmessages.Add(new Message { TextMessage = speechRecognitionResult.Text, Time = DateTime.Now.ToString(), Status = "Sent", tofrom = true }); var index = Array.FindIndex(responses, row => row.Contains(speechRecognitionResult.Text)); string reponse = ""; //Verification si commande http ou socket try { if (index < commandesHttp[1].Count) { reponse = await getReponseHttp(commandesHttp[1][index]); } else { getReponseSocket(speechRecognitionResult.Text); } } catch { reponse = "Une erreur est survenue"; } }