0

When I try and filter a noisy file with a filter and try and play it again, it is just a mess. I found a solution that worked here, but why do i have to save it like this, and why cant i just play it in python, Can someone explain this?

Here is the code that i used.

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

vegiv
  • 124
  • 1
  • 9

0 Answers0