基于python的griffin语音信号重建

griffin算法是基于没有相位的线性语谱图进行重建。本文采用45ms窗宽,10ms滑动窗的语谱图进行语音信号重建。以下为python实现的griffin重建算法。基本思想:

step1: 初始化一个随机相位

step2: 短时反傅里叶变换

step3: 短时傅里叶变换,保留相位,幅度取最初的幅度

step4: 循环至停止N次迭代。

gl_iters = 120
n_fft, hop_length, win_length = 720, 160,720
def _griffin_lim(S):
    angles = np.exp(2j * np.pi * np.random.rand(*S.shape))
    S_complex = np.abs(S).astype(np.complex)
    y = _istft(S_complex * angles)
    for i in range(gl_iters):
        angles = np.exp(1j * np.angle(_stft(y)))
        y = _istft(S_complex * angles)
    return y


def _stft(y):
    
    return librosa.stft(y=y, n_fft=n_fft, hop_length=hop_length, win_length=win_length)


def _istft(y):
    return librosa.istft(y, hop_length=hop_length, win_length=win_length)

 

AudioData, sr = librosa.load(filename, sr=16000, mono=True)  # 使用文件采样率
D = librosa.stft(AudioData, n_fft=n_fft, hop_length=hop_length, win_length=win_length)
spect, phase = librosa.magphase(D)  # 语音信息域幅度和相位3密切关联
ReAudio = _griffin_lim(D)

plt.plot(AudioData)
plt.plot(ReAudio)

原始语音信号

重建一次语音信号

重建120次语音信号

 

 


版权声明:本文为q511951451原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。