private void Start() { try { Capturer = new WasapiLoopbackCapture(); TargetFormat = new WaveFormat(16000, 8, 1); SendTimer = Stopwatch.StartNew(); Capturer.DataAvailable += (aud, args) => { try { if (args.BytesRecorded > 0) { lock (TempBuffer) { if (!SendTimer.IsRunning) { SendTimer.Restart(); } TempBuffer.AddRange(args.Buffer.Take(args.BytesRecorded)); if (TempBuffer.Count > 200000) { SendTimer.Reset(); SendTempBuffer(); } else if (SendTimer.Elapsed.TotalMilliseconds > 1000) { SendTimer.Reset(); SendTempBuffer(); } } } } catch { } }; Capturer.StartRecording(); } catch { } }
private void Stop() { Capturer?.StopRecording(); SendTimer?.Reset(); }