### 傅里叶加窗消除高频类微电流唦唦声
import matplotlib.pyplot as plt
from scipy import signal
from scipy.io import wavfile
import librosa
import numpy as np
import soundfile as sf
y, sr = librosa.load('hello.wav')
#S = librosa.stft(y, n_fft=2048, window="hann")
#S = librosa.stft(y, n_fft=2048, window=filterXY[:,1]/400) # 使用折线 y 作为窗,得到颤音
#S = librosa.stft(y, n_fft=2048, window=filterXY[:,0]/400) # 使用折线 x 作为窗,抹出高频音频
windowdata = []
sep = 1.05/2048
for i in range(2048):
#windowdata.append(math.fabs(1024-i)*sep)
windowdata.append((2048-i)*sep)
S = librosa.stft(y, n_fft=2048, window=np.asarray(windowdata))
#print(type(S), len(S), S, S.shape)
for i in range(350,1025):
for j in range(len(S[i])):
S[i][j] = 0.0
for i in range(350):
S[i] = S[i] * 1.33
# 加高频静音不会消除微沙电流音,添加后音频会变调
#zeros = np.zeros(shape=(1,len(S[0])))
#for i in range(200):
# S = np.append(S, zeros, axis=0)
print(S, S.shape)
D = S
y_inv = librosa.istft(D)
#y_inv = y_inv * 1.33
sf.write('hello-output_file.wav', y_inv, sr)