NAudio icon indicating copy to clipboard operation
NAudio copied to clipboard

How to check volume when use WaveIn or WaveInEvent

Open xclw2000 opened this issue 3 years ago • 1 comments

I want to use the WaveIn or WaveInEvent class to record voice.

var _waveIn = new WaveInEvent();
_waveIn.DataAvailable += OnDataAvailable;
_waveIn.StartRecording();

And save voice data into a buffer in OnDataAvailable event

void OnDataAvailable(object sender, WaveInEventArgs e)
{
     if(volume is low for 5 seconds)
     {
          //stop recording
     }
     else
     {
          // save voice data to a buffer
     }
}

If there is no voice or low volume for a while(for example: 5S), I'll stop recording. But how can I determine there is no voice or low volume? The WaveInEventArgs class has no such a property.

xclw2000 avatar Jul 07 '22 01:07 xclw2000

there is nothing built in to do this I'm afraid. You have to examine the samples themselves (which are available in the Buffer property) and determine whether or not the level is low or not.

markheath avatar Jul 23 '22 20:07 markheath