转载出处:https://blog.csdn.net/iTaacy/article/details/60141849
效果:
谱减法语音降噪的Python实现:
#!/usr/bin/env python
import numpy as np
import wave
import nextpow2
import math
# 打开WAV文档
f = wave.open("input_file.wav")
# 读取格式信息
# (nchannels, sampwidth, framerate, nframes, comptype, compname)
params = f.getparams()
nchannels, sampwidth, framerate, nframes = params[:4]
fs = framerate
# 读取波形数据
str_data = f.readframes(nframes)
f.close()
# 将波形数据转换为数组
x = np.fromstring(str_data, dtype=np.short)
# 计算参数
len_ = 20 * fs // 1000 # 样本中帧的大小
PERC = 50 # 窗口重叠占帧的百分比
len1 = len_ * PERC // 100 # 重叠窗口
len2 = len_ - len1 # 非重叠窗口
# 设置默认参数
T