简体   繁体   English

统一获取基本音频频谱数据

[英]Get Basic audio spectrum data in unity

I want to visualize if an audio clip has sound or not. 我想可视化音频片段是否有声音。 The microphone and the audiosource is working correctly but I am stuck with its visualizing part. 麦克风和音频源正常工作,但我停留在其可视化部分。 I have hard time understanding the official document and I want a solution. 我很难理解正式文件,因此需要解决方案。

I tried the following code: 我尝试了以下代码:

    void Update () {

    AnalyzeSound();

    text1.text = "sound!\n"+ " rmsValue : " + rmsValue ;
}


void AnalyzeSound()
{
    audio.GetOutputData(samples, 0);

    //GetComponent rms

    int i = 0;
    float sum = 0;

    for (; i < SAMPLE_SIZE; i++)
    {
        sum = samples[i] * samples[i];
    }

    rmsValue = Mathf.Sqrt(sum / SAMPLE_SIZE);

    //get the dbValue
    dbValue = 20 * Mathf.Log10(rmsValue / 0.1f);
   }

Can I take rmsValue as the input of sound on microphone? 我可以将rmsValue用作麦克风上的声音输入吗? or should I take the dbValue? 还是应该使用dbValue? what should be the threshold value? 阈值应该是多少? in a few words, When can I say the microphone has sound? 简而言之,我什么时候可以说麦克风有声音?

There is no hard and fast definition that would separate noise from silence in all cases. 在所有情况下,都没有一个硬性和快速性的定义可以将噪声与静音区分开。 It really depends on how loud the background noise is. 这实际上取决于背景噪声的音量。 Compare for example, silence recorded in an anechoic chamber vs silence recorded next to an HVAC system. 例如,比较在消声室内记录的静音与在HVAC系统旁记录的静音。 The easiest thing to try is to experiment with different dB threshold values below which you consider the signal as noise and above which it is considered signal. 最简单的尝试是尝试使用不同的dB阈值,低于该阈值则将信号视为噪声,而高于该阈值则将其视为信号。 Then adjust the threshold value up or down to suit your needs. 然后向上或向下调整阈值以适合您的需求。 Depending on the nature of the signal (eg music vs. speech) you could look into other techniques such as Voice Activity Detection ( https://en.wikipedia.org/wiki/Voice_activity_detection ) or a convolutional neural network to segment speech and music 根据信号的性质(例如音乐与语音),您可以研究其他技术,例如语音活动检测( https://en.wikipedia.org/wiki/Voice_activity_detection )或卷积神经网络来分割语音和音乐

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM