简体   繁体   中英

How to apply Butterworth filter to my code?

I want to filter out noises from a voicerecording and normalize it. Currently I am struggeling with a Butterworth bandpass filter.

How do I apply this in my code? (I'm new to Python)

from numpy import nditer
from pydub.audio_segment import AudioSegment
from scikits.audiolab import wavread

from scipy import signal

# Stereo to mono
stereo_sound = AudioSegment.from_wav('voice.wav')
mono_sound = stereo_sound.set_channels(1)
mono_sound.export('voice_mono.wav', format='wav')

podcast = wavread('voice.wav')

for frame in podcast:
    print(frame)

print("\n")
print("\n")


# Read mono file
podcast = wavread('voice_mono.wav')
frames = podcast[0]
max_iter = 2000
i = 0
for frame in nditer(frames):
    i += 1
    if i < max_iter:
        print(frame)


# Apply Butterworth filter

# Do Butterworth filter and save as new wav
b, a = signal.butter(4, 100, 'bandpass', analog=True)

Thanks alot!

You may first want to check that you have numpy, pydub, scikits and scipy installed. You could then create a function with this code and put your audio file as the input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM