基於python的griffin語音頻號重建

2021-09-29 20:39:52 字數 1380 閱讀 8392

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次語音頻號

基於python的爬蟲

本次初學,參考的資料見 功能主要是抓取韓寒的部落格內容,以及儲存 到 hanhan的資料夾中,執行環境實在linux下的。見 具體 如何 usr bin env python coding utf 8 import urllib import time url 60 con urllib.urlop...

基於python的opencv教程

第一次寫部落格,學習是要有輸入與輸出的,所謂教學相長。所以我想試著自己寫乙份教程,算是對自己的學習總結吧,部落格的排版比較直男,請湊合看吧。首先建議的ide是pycharm,opencv的庫直接pip安裝就好,最好大家有一定的python基礎。第一部分是關於圖象讀取和儲存。import cv2imp...

基於python的基本函式

什麼是函式?函式就是將一段 寫在一起,如果需要使用,直接呼叫即可 就是封裝一段功能 的 塊,這段 可以被多次使用 def define 定義 函式名稱命名規範 單詞全部小寫,多個單詞之間用 連線,函式名要和實現 的功能有關係,做到見名知意 def 函式名 引數列表 函式功能 def eat prin...