gpt4 book ai didi

python - 如何将Butterworth过滤器应用于我的代码?

转载 作者:行者123 更新时间:2023-12-03 01:52:34 26 4
gpt4 key购买 nike

我想过滤掉录音中的噪音并将其归一化。目前,我正在努力使用Butterworth带通滤波器。

如何在我的代码中应用它? (我是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)

非常感谢!

最佳答案

您可能首先要检查是否已安装numpy,pydub,scikits和scipy。然后,您可以使用此代码创建一个函数,并将音频文件作为输入。

关于python - 如何将Butterworth过滤器应用于我的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38419117/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com