2

我想创建一个通过麦克风拍手后收听的软件..

我的第一个实现是尝试让软件在我听到高音量声音时发出警告。

但我想知道是否有人可以帮助我朝着正确的方向前进?

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;
        }
    }
}
4

1 回答 1

0

假设您正在录制 16 位音频(这是默认设置),那么 e.Buffer 的内容可以这样解释:

for (int n = 0; n < e.BytesRecorded; n += 2)
{
    short sampleValue = BitConverter.ToInt16(e.Buffer, n);        
}

然后你可以寻找 Math.Abs​​(sampleValue) 的高值。

于 2011-07-01T05:52:02.437 回答