Librosa音频处理(六)

8 篇文章 4 订阅
6 篇文章 9 订阅

劣质的麦克风在录音时会把电流和嗡嗡的背景声录进去,通过对噪声取样去除频率可以达到降噪的目的。

主要步骤:

1. 噪声取样

2. 统计频率

3. 移除频率

代码如下:

'''采样降噪'''
def test2(n, y, sr):

    indexs = librosa.effects.split(y, top_db=25-n)

    noicefrequencies = []
    for i in indexs:
        frequencies, D = librosa.ifgram(y[i[0]:i[1]], sr=sr, n_fft=22000)
        frequencies = frequencies.astype(int)
        noicefrequencies += frequencies.flatten().tolist()
    
    c = Counter(noicefrequencies)
    noicefrequencies = set(map(lambda x: x[0] // 2 * 2, c.most_common(400)))

    frequencies, D = librosa.ifgram(y, sr=sr)


    tempD = D.copy().astype(int)
    tempD = tempD // 2 * 2

    count = 0
    for i in range(D.shape[0]):
        for j in range(D.shape[1]):
            if tempD[i][j] in noicefrequencies:
                count += 1
                D[i][j] = 0
    print(count)
    return librosa.istft(D)

 

  • 4
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值