语音和分贝数关系

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了语音和分贝数关系相关的知识,希望对你有一定的参考价值。

语音和分贝有关系,分贝和傅里叶变换有关系,所以在语音拾取的时候降低语音的敏感度,可以通过过滤指定分贝数拾取语音,可以理解为过滤噪音

private bool IsUserfulVoice(byte[] data)
        {
            double[] wave = new double[data.Length / 2];
            int h = 0;
            for (int i = 0; i < wave.Length; i += 2)
            {
                wave[h] = (double)BitConverter.ToInt16(data, i); //采样位数为16bit
                ++h;
            }

            double[] res = VoiceTransformer.FourierTransformer.FFTDb(wave);

            double kk = 0;
            foreach (double dd in res)
            {
                kk += dd;
            }
            if (kk < 0)
            {
                kk = 0;
            }
            if ((kk / res.Length) > 42.0)
            {
                return true;
            }
            return false;
        }

public static class FourierTransformer
        {
            public static double[] FFTDb(double[] source)
            {
                int sourceLen = source.Length;
                int nu = (int)(Math.Log(sourceLen) / Math.Log(2));
                int halfSourceLen = sourceLen / 2;
                int nu1 = nu - 1;
                double[] xre = new double[sourceLen];
                double[] xim = new double[sourceLen];
                double[] decibel = new double[halfSourceLen];
                double tr, ti, p, arg, c, s;
                for (int i = 0; i < sourceLen; i++)
                {
                    xre[i] = source[i];
                    xim[i] = 0.0f;
                }
                int k = 0;
                for (int l = 1; l <= nu; l++)
                {
                    while (k < sourceLen)
                    {
                        for (int i = 1; i <= halfSourceLen; i++)
                        {
                            p = BitReverse(k >> nu1, nu);
                            arg = 2 * (double)Math.PI * p / sourceLen;
                            c = (double)Math.Cos(arg);
                            s = (double)Math.Sin(arg);
                            tr = xre[k + halfSourceLen] * c + xim[k + halfSourceLen] * s;
                            ti = xim[k + halfSourceLen] * c - xre[k + halfSourceLen] * s;
                            xre[k + halfSourceLen] = xre[k] - tr;
                            xim[k + halfSourceLen] = xim[k] - ti;
                            xre[k] += tr;
                            xim[k] += ti;
                            k++;
                        }
                        k += halfSourceLen;
                    }
                    k = 0;
                    nu1--;
                    halfSourceLen = halfSourceLen / 2;
                }
                k = 0;
                int r;
                while (k < sourceLen)
                {
                    r = BitReverse(k, nu);
                    if (r > k)
                    {
                        tr = xre[k];
                        ti = xim[k];
                        xre[k] = xre[r];
                        xim[k] = xim[r];
                        xre[r] = tr;
                        xim[r] = ti;
                    }
                    k++;
                }
                for (int i = 0; i < sourceLen / 2; i++)
                {
                    decibel[i] = 10.0 * Math.Log10((float)(Math.Sqrt((xre[i] * xre[i]) + (xim[i] * xim[i]))));
                }

                return decibel;
            }

            private static int BitReverse(int j, int nu)
            {
                int j2;
                int j1 = j;
                int k = 0;
                for (int i = 1; i <= nu; i++)
                {
                    j2 = j1 / 2;
                    k = 2 * k + j1 - 2 * j2;
                    j1 = j2;
                }
                return k;
            }
        }

  

 

 

 

 

值得注意的是,拾取语音的Byte数组要为2的N次方长度,这个由快速FFT算法决定

引用自:http://www.cnblogs.com/zhuweisky/p/3269896.html

 

以上是关于语音和分贝数关系的主要内容,如果未能解决你的问题,请参考以下文章

使用 naudio 获取 1 秒音频文件的分贝数

分贝显示器,实时显示声音强度(附源码)

变分推理,变分贝叶斯和变分EM之间的关系是什么?

分贝和百分比之间的关系

AudioRecord类获取录音音量分贝数

音乐与动漫及游戏的关系--游戏动漫音乐音效制作 分贝块