使用 Naudio 创建 Clapper 软件

发布于 2024-11-18 06:05:08 字数 934 浏览 3 评论 0原文

我想创建一个在通过麦克风鼓掌后收听的软件。

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

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

潇烟暮雨 2024-11-25 06:05:08

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

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

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

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文