C# CSCore stop recording when user stops talking

Viewed 581

I am currently trying to record audio via WasapiCapture and WaveWriter (CSCore package), and want to stop the recording after the user stops talking. Can anyone help me out?

What came to my mind is that I could potentially create a RecordingVolumeHandler, that triggers when the Volume is below a certain threshold for 1 or 2 seconds. How can i do this? Is there a method to get the volume from the audio input that is currently being recorded?

The following code is for the two functions that I have for starting the recording and stopping it.

    private WasapiCapture capture;
    private WaveWriter writer;

        private void startRecording()
    {
        capture = new WasapiCapture();
        capture.Initialize();
        writer = new WaveWriter("file.wav", capture.WaveFormat);
        capture.DataAvailable += (s, capData) =>
        {
            writer.Write(capData.Data, capData.Offset, capData.ByteCount);
        };
        capture.Start();
    }

    private void stopRecording()
    {
        if (writer != null && capture != null)
        {
            capture.Stop();
            writer.Dispose();
            capture.Dispose();
        }
    }

Thank you in advance!

1 Answers
Related