当我尝试使用过滤器过滤嘈杂的文件并尝试再次播放时,它只是一团糟。我找到了一个在这里工作的解决方案,但是为什么我必须像这样保存它,为什么我不能在 python 中播放它,有人可以解释一下吗?
这是我使用的代码。
import numpy as np
import matplotlib.pyplot as plt
import scipy.signal as sg
from scipy.io import wavfile
import soundfile as sf
import sounddevice as sd
import pandas as pd
path = 'hammingfilter_1.csv'
b = np.genfromtxt(path, delimiter=',')
Fs, data = wavfile.read('pianoise.wav')
sd.play(data, blocking=True) #plays the sound
lfilt = sg.lfilter(b,1,data) #just tried to different ways, shouldnt matter much
y = sg.filtfilt(b,1,data)#
wavfile.write('LPF_filttered.wav', Fs, np.int16(y/np.max(np.abs(y)) * 32767)) # this is the solution im wondering about. This works and the sound is nice and filtered
sd.play(y,Fs,blocking=True)#this sounds totally shit