【问题标题】:I think Librosa.effect.split has some problem?我认为 Librosa.effect.split 有问题?
【发布时间】:2019-11-13 16:03:22
【问题描述】:

首先,此功能是消除音频的静音。 这是官方的描述:

https://librosa.github.io/librosa/generated/librosa.effects.split.html

librosa.effects.split(y, top_db=10, *kargs)

将音频信号分成非静音间隔。

top_db:number > 0 低于参考的阈值(以分贝为单位)视为静音

return: 间隔:np.ndarray, shape=(m, 2) 间隔[i] == (start_i, end_i) 是非静音的开始和结束时间(以样本为单位)区间 i。

所以这很简单,对于任何低于 10dB 的声音,将其视为静音并从音频中删除。它会返回给我一个间隔列表,这些间隔是音频中的非静音片段。

所以我做了一个非常简单的例子,结果让我很困惑: 我在这里加载的音频是 3 秒的人类说话,非常正常的说话。

y, sr = librosa.load(file_list[0]) #load the data
print(y.shape) -> (87495,)

intervals = librosa.effects.split(y, top_db=100)
intervals -> array([[0, 87495]])

#if i change 100 to 10
intervals = librosa.effects.split(y, top_db=10)
intervals -> array([[19456, 23040],
                    [27136, 31232],
                    [55296, 58880],
                    [64512, 67072]])

这怎么可能……

我告诉 librosa,好的,对于任何低于 100dB 的声音,将其视为静音。 在此设置下,整个音频应被视为静音,并且根据文档,它应该给我 array[[0,0]] 一些东西...因为删除静音后,什么都没有了...

但似乎 librosa 将静音部分返回给我,而不是非静音部分。

【问题讨论】:

    标签: python librosa


    【解决方案1】:

    librosa.effects.split() 它在文档中说它返回一个 numpy 数组,其中包含 包含非静音音频的间隔。这些间隔当然取决于您分配给参数top_db 的值。 它不返回任何音频,只返回波形非静音片段的起点和终点

    在您的情况下,即使您设置 top_db = 100,它也不会将整个音频视为静音,因为他们在文档中声明他们使用 The reference power. By default, it uses **np.max** and compares to the peak power in the signal. 所以将您的 top_db 设置为高于音频中存在的最大值实际上会导致 top_db 没有任何效果。 这是一个例子:

    import librosa
    import numpy as np
    import matplotlib.pyplot as plt
    
    # create a hypothetical waveform with 1000 noisy samples and 1000 silent samples
    nonsilent = np.random.randint(11, 100, 1000) * 100
    silent = np.zeros(1000)
    wave = np.concatenate((nonsilent, silent))
    # look at it
    print(wave.shape)
    plt.plot(wave)
    plt.show()
    
    # get the noisy interval
    non_silent_interval = librosa.effects.split(wave, top_db=0.1, hop_length=1000)
    print(non_silent_interval)
    
    # plot only the noisy chunk of the waveform
    plt.plot(wave[non_silent_interval[0][0]:non_silent_interval[0][1]])
    plt.show()
    
    # now set top_db higher than anything in your audio
    non_silent_interval = librosa.effects.split(wave, top_db=1000, hop_length=1000)
    print(non_silent_interval)
    
    # and you'll get the entire audio again
    plt.plot(wave[non_silent_interval[0][0]:non_silent_interval[0][1]])
    plt.show()
    

    您可以看到非静音音频是从 0 到 1000,静音音频是从 1000 到 2000 个样本:

    这里它只为我们提供了我们创建的波的嘈杂部分:

    这里的 top_db 设置为 1000:

    这意味着 librosa 做了它在文档中承诺的一切。希望这会有所帮助。

    【讨论】:

    • 嗨,谢谢你的回答......我仍然感到困惑,我在下面发布了我的例子,你能帮我看看吗?真的很感谢
    • 嗨,根据您的建议,我刚刚创建了另一个线程。链接:stackoverflow.com/questions/58951102/…。你能帮我解决这个问题吗?
    猜你喜欢
    • 2014-12-26
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 2013-12-26
    • 2012-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多