Create Clapper software with Naudio
I'd like to create a software that listens after claps thru microphone..
my first implementation will be to try to get the software to warn when i hears high volume sound.
but i was wondering if someone could help me in the right direction?
public partial class ClapperForm : Form
{
WaveIn waveInStream;
public ClapperForm()
{
InitializeComponent();
}
private void btnStart_Click(object sender, EventArgs e)
{
//start the streaming
waveInStream = new WaveIn();
waveInStream.DataAvailable += new EventHandler<WaveInEventArgs>(waveInStream_DataAvailable);
waveInStream.StartRecording();
}
void waveInStream_DataAvailable(object sender, WaveInEventArgs e)
{
开发者_如何转开发 //check out what volume it is
}
private void btnStop_Click(object sender, EventArgs e)
{
if (waveInStream != null)
{
//Stop streaming
waveInStream.StopRecording();
waveInStream.Dispose();
waveInStream = null;
}
}
}
Assuming you are recording 16 bit audio (which is the default), then the contents of e.Buffer can be interpreted like this:
for (int n = 0; n < e.BytesRecorded; n += 2)
{
short sampleValue = BitConverter.ToInt16(e.Buffer, n);
}
Then you can look for high values of Math.Abs(sampleValue).
精彩评论