NAudio
NAudio copied to clipboard
How to check volume when use WaveIn or WaveInEvent
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.
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.