void Update() { if (Input.GetKeyDown(KeyCode.R)) { if (!recording.IsRecording) { recording.StartRecording(); } else { recording.StopRecording(); } } bool connected = recording.requestCtrl.IsConnected; text.text = connected ? "Connected" : "Not connected"; if (connected) { text.text += "\n\nPress R to Start/Stop the recording."; var status = recording.IsRecording ? "recording" : "not recording"; text.text += $"\n\nStatus: {status}"; } }
private async Task StartIdentifying() { finished = false; int seconds = 7; try { seconds = int.Parse(SecondsEntry.Text); } catch (Exception e) { Debug.WriteLine("Failed parse int"); } count = 0; while (recording) { var filename = string.Format("audio{0}", count); Device.BeginInvokeOnMainThread(() => recorder.StartRecording(filename, seconds)); AudioFile file = new AudioFile { Seconds = seconds, FileName = filename, CreatedAt = new DateTimeOffset(DateTime.Now), }; await Task.Delay(seconds * 1000); recorder.StopRecording(); file.FinishedAt = new DateTimeOffset(DateTime.Now); while (recorder.audio.IsRecording) { } processFile(file); count++; } finished = true; }
void Enroll(object sender, EventArgs a) { enroling = !enroling; if (!enroling || string.IsNullOrEmpty(person.Name)) { return; } ProgressIndicator.IsVisible = true; var startTime = DateTime.Now; recorder.StartRecording(person.Name); AudioFile file = new AudioFile { CreatedAt = new DateTimeOffset(DateTime.Now), FileName = person.Name, }; Task.Run(async() => { while (enroling) { var timespan = (DateTime.Now - startTime).Seconds; Device.BeginInvokeOnMainThread(() => { EnrollButton.Text = timespan + " seconds"; }); } recorder.StopRecording(); while (recorder.audio.IsRecording) { } file.FinishedAt = DateTime.Now; file.Seconds = (DateTime.Now - startTime).Seconds; if (await network.EnrolProfile(person, file)) { callback.Invoke(true); await PopupNavigation.PopAsync(); recorder = null; } Device.BeginInvokeOnMainThread(() => { ProgressIndicator.IsVisible = false; }); }); }
public void StopRecording() { recording = false; recorder.StopRecording(); }