C# - 麦克风噪声检测 [英] C# - Microphone noise detection

查看:738
本文介绍了C# - 麦克风噪声检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用n音讯库来捕获麦克风输入。但是,我遇到了一个问题。
我现在用的是code从n音讯示例应用程序(我稍微修改)。
在codeS生成基于麦克风输入WAV文件,并呈现它作为一个浪潮。这里是code表示。

I am using nAudio Library to capture microphone input. But I have run into a problem. I am using the code(which I have modified slightly) from an nAudio sample app. The codes generates a WAV file based on mic input and renders it as a wave. Here is the code for that.

private void RenderFile()
{
        SampleAggregator.RaiseRestart();
        using (WaveFileReader reader = new WaveFileReader(this.voiceRecorderState.ActiveFile))
        {
            this.samplesPerSecond = reader.WaveFormat.SampleRate;
            SampleAggregator.NotificationCount = reader.WaveFormat.SampleRate/10;
            //Sample rate is 44100

            byte[] buffer = new byte[1024];
            WaveBuffer waveBuffer = new WaveBuffer(buffer);
            waveBuffer.ByteBufferCount = buffer.Length;
            int bytesRead;
            do
            {
                bytesRead = reader.Read(waveBuffer, 0, buffer.Length);
                int samples = bytesRead / 2;
                double sum = 0;
                for (int sample = 0; sample < samples; sample++)
                {
                    if (bytesRead > 0)
                    {
                        sampleAggregator.Add(waveBuffer.ShortBuffer[sample] / 32768f);
                        double sample1 = waveBuffer.ShortBuffer[sample] / 32768.0;
                        sum += (sample1 * sample1);

                    }
                }
                double rms = Math.Sqrt(sum / (SampleAggregator.NotificationCount));
                var decibel = 20 * Math.Log10(rms);



                System.Diagnostics.Debug.WriteLine(decibel.ToString() + " in dB");
            } while (bytesRead > 0);
            int totalSamples = (int)reader.Length / 2;
            TotalWaveFormSamples = totalSamples / sampleAggregator.NotificationCount;
            SelectAll();
        }
        audioPlayer.LoadFile(this.voiceRecorderState.ActiveFile);
 }

下面是没有声音,但只有麦克风噪音2秒WAV文件的结果有点块。

Below is a little chunk from a result of a 2second WAV file with no sound but only mic noise.

-54.089102453893以dB结果
-51.9171950072361以dB结果
-53.3478098666891以dB结果
-53.1845794096928以dB结果
-53.8851764055102以dB结果
-57.5541358628342以dB结果
-54.0121140454216以dB结果
-55.5204248291508以dB结果
-54.9012326746571以dB结果
-53.6831017096011以dB结果
-52.8728852678309以dB结果
-55.7021600863786以dB

-54.089102453893 in dB
-51.9171950072361 in dB
-53.3478098666891 in dB
-53.1845794096928 in dB
-53.8851764055102 in dB
-57.5541358628342 in dB
-54.0121140454216 in dB
-55.5204248291508 in dB
-54.9012326746571 in dB
-53.6831017096011 in dB
-52.8728852678309 in dB
-55.7021600863786 in dB

我们可以看到,DB水平徘徊在-55时,有没有输入声音,只有沉默。如果我的麦克风在一个正常的语调说:录制你好,分贝值会转到-20左右。我读的地方,一般人谈话是围绕20dB,使-3dB为-6dB是零值范围麦克风。

As we can see, the db level hovers around -55 when there is no input sound, only silence. if I record saying "Hello" in mic in a normal tone, the db value will goto -20 or so. I read somewhere that average human talk is around 20dB and -3dB to -6dB is the ZERO value range for mic.

问题:我是不是正确计算dB值? (我用别人这里提出一个公式)...为什么分贝总是负上来?我失去了一个重要的概念或机制?

Question: Am I calculating the dB value correctly? (i used a formula proposed here by someone else)...Why dB is always coming up in negative? Am i missing a crucial concept or a mechanism?

我在搜索codePLEX n音讯文件,并没有找到答案。在我的观察,文档,需要有更多的解释则只是一堆Q&放大器; A [无意冒犯n音讯:)]

I searched nAudio documentation at codeplex and didn't find an answer. In my observation, the documentation there needs to be more explanatory then just a bunch of Q&A [no offense nAudio :)]

推荐答案

如果我的理解公式正确,你计算的实际值是dBm的,这是绝对OK,因为分贝仅仅是一个衡量放大单元及可以' T为用于测量信号强度/幅度(例如,你可以说我3分贝放大的信号,但不能说我的信号强度为6dB)。

If I understood the formula correctly, the actual value you're calculating is dBm, and that's absolutely ok since dB is just a unit to measure amplification and can't be used for measuring signal strength/amplitude (i.e. you can say I amplified the signal by 3 db, but can't say my signal strength is 6 dB).

负值在那里,只是因为公式的对数转换部分的(转换瓦特/ miliWatts到DB)因为你正在处理的信号是relativly薄弱。

The negative values are there just because of the logarithmic conversion part of the formula (converting watts/miliWatts to db) and since the signals you're dealing with are relativly weak.

所以在最后,看上去,就像你所做的一切权利。
希望它帮助。

So in conclusion, looks, like you've done everything right. Hope it helps.

编辑:BTW,你可以看到,实乃〜沉默和人类语言之间的差异23-25​​dbm

BTW, as you can see, there really is ~23-25dbm difference between silence and human speech

这篇关于C# - 麦克风噪声检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆