Librosa音频处理(二)

8 篇文章 4 订阅
2 篇文章 0 订阅

对音频信号的处理可以通过 librosa.ifgram 方法获取 stft 短时傅立叶变换的矩阵,对该矩阵进行修改搬移,再进行 istft 逆转换获得处理后的音频信号。

y, sr = librosa.load(path)
frequencies, D = librosa.ifgram(y, sr=sr)
'''
     中间对D进行处理就行了
'''
y = librosa.istft(D)

D为stft变换的矩阵,x 轴为时间序列,y轴为频率序列坐标对应frequencies,值为幅度。

由于D类型为numpy.ndarray,所以我们很方便就可以通过numpy库对矩阵处理。

 

 

  1. 回音
    D = np.repeat(D, 2, axis=1)
  2. 间断
    D[:,::2] = 0

     

  3. 音色
    D = np.roll(D, 50, axis=0)
  4. 压缩频率
    def _pool(D, poolsize):
        x = D.shape[1] // poolsize
        restsize = D.shape[1] % poolsize
        if restsize > 0:
            x += 1
            rightlist = np.zeros([ D.shape[0], poolsize-restsize])
            D = np.c_[D, rightlist]
        D = D.reshape( (-1, poolsize) )
        D = D.sum(axis=1).reshape(-1,x)
        return D
    
    def rewardshape(D, shape):
        x = shape[0] - D.shape[0]
        y = shape[1] - D.shape[1]
        if x > 0:
            bottomlist = np.zeros([x, D.shape[1]])
            D = np.r_[D, bottomlist]
        if y > 0:
            rightlist = np.zeros([ D.shape[0], y])
            D = np.c_[D, rightlist]
        return D
    
    def pool(D, size=(3,3), shapeed=False):
        _shape = D.shape
        if size[1] > 1:
            D = _pool(D, size[1])
        if size[0] > 1:
            D = _pool(D.T, size[0]).T
        if shapeed:
            D = rewardshape(D, _shape)
        return D

     

 

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值