2024-05-29 10:31:39 发布
网友
我已经用python生成了音频。但它的结局是:
所以我想知道如何使用pythonlibrosa/pydub删除如此响亮的随机noize
换句话说,如何检测噪声开始和结束的位置。我们知道录制结束时会有杂音,所以问题是如何找到杂音的起始位置,并在python中删除杂音
在您的情况下,似乎一个简单的阈值将起作用。为了确保不会过早剪辑,我们将要求在截断音频之前至少k值超过阈值
k
import librosa import numpy as np def first_occ_index(w, n): # Borrowed from https://stackoverflow.com/questions/49693770/get-index-of-the-first-block-of-at-least-n-consecutive-false-values-in-boolean-a idx = np.flatnonzero(np.r_[True, w, True]) lens = np.diff(idx) - 1 return idx[(lens >= n).argmax()] X, fs = librosa.load('your.audio') threshold = 3 * X.std() # or e.g. 0.6 * X.max() - play with it X_th = np.abs(X) < threshold k = 20 # we require 20 consecutive values above the threshold idx_to_cut = first_occ_index(X_th, k) my_audio = X[:idx_to_cut] garbage = X[idx_to_cut:]
在您的情况下,似乎一个简单的阈值将起作用。为了确保不会过早剪辑,我们将要求在截断音频之前至少
k
值超过阈值相关问题 更多 >
编程相关推荐