gpt4 book ai didi

python - 我认为 Librosa.effect.split 有问题?

转载 作者:行者123 更新时间:2023-12-01 06:55:16 35 4
gpt4 key购买 nike

首先,该功能是消除音频的静音。这是官方的说明:

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

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

Split an audio signal into non-silent intervals.

top_db:number > 0 The threshold (in decibels) below reference to consider as silence

return: intervals:np.ndarray, shape=(m, 2) intervals[i] == (start_i, end_i) are the start and end time (in samples) of non-silent interval 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 似乎返回给我的是沉默部分而不是非沉默部分。

最佳答案

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

在您的情况下,即使您设置 top_db = 100,它也不会将整个音频视为静音,因为它们在文档中声明它们使用引用功率。默认情况下,它使用 **np.max** 并与信号中的峰值功率进行比较。 因此,将 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个样本: enter image description here

这里它只提供了我们创建的波的噪声 block : enter image description here

这是 top_db 设置为 1000 的情况: enter image description here

这意味着 librosa 做了它在文档中 promise 的所有事情。希望这会有所帮助。

关于python - 我认为 Librosa.effect.split 有问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58841039/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com