protected override void OnActivityResult(int requestCode, Result resultVal, Intent data) { if (requestCode == VOICE) { if (resultVal == Result.Ok) { var matches = data.GetStringArrayListExtra(RecognizerIntent.ExtraResults); if (matches.Count != 0) { string search = matches[0]; // limit the output to 500 characters if (search.Length > 500) { search = search.Substring(0, 500); } Request result = WitAiComm.SendRequest(search); tvSearch.Text = result.Search; tvResult.Text = result.Result; } else { tvSearch.Text = "No speech was recognised"; } // change the text back on the button recButton.Text = "Start Recording"; isRecording = !isRecording; } } base.OnActivityResult(requestCode, resultVal, data); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); progress = new ProgressDialog(this); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button btnRecord = FindViewById <Button>(Resource.Id.btnRecord); TextView tvSearch = FindViewById <TextView>(Resource.Id.tvSearch); TextView tvResult = FindViewById <TextView>(Resource.Id.tvResult); audioBuffer = new byte[200000]; InitializeAudioRecorder(); btnRecord.Click += async(o, i) => { isRecording = !isRecording; if (isRecording) { btnRecord.Text = Resources.GetString(Resource.String.stopRecording); await RecordAudioAsync(); } else { btnRecord.Text = Resources.GetString(Resource.String.startRecording); byte[] d = await ReadWavFileAsync(); progress.SetMessage("Plesase wait, processing request..."); progress.SetCancelable(false); progress.Show(); Request r = await WitAiComm.PostVoiceAsync(d); tvSearch.Text = r.Search; tvResult.Text = r.Result; progress.Hide(); } }; }
private void Button_Click(object sender, RoutedEventArgs e) { Request req = WitAiComm.SendRequest(tbTxt); ViewModel.Requests.Add(req); }