c# - Create Clapper software with Naudio -
i'd create software listens after claps thru microphone..
my first implementation try software warn when hears high volume sound.
but wondering if me in right direction?
public partial class clapperform : form { wavein waveinstream; public clapperform() { initializecomponent(); } private void btnstart_click(object sender, eventargs e) { //start streaming waveinstream = new wavein(); waveinstream.dataavailable += new eventhandler<waveineventargs>(waveinstream_dataavailable); waveinstream.startrecording(); } void waveinstream_dataavailable(object sender, waveineventargs e) { //check out volume } private void btnstop_click(object sender, eventargs e) { if (waveinstream != null) { //stop streaming waveinstream.stoprecording(); waveinstream.dispose(); waveinstream = null; } } }
assuming recording 16 bit audio (which default), contents of e.buffer can interpreted this:
for (int n = 0; n < e.bytesrecorded; n += 2) { short samplevalue = bitconverter.toint16(e.buffer, n); }
then can high values of math.abs(samplevalue).
Comments
Post a Comment