我正在嘗試在python中處理音頻文件並應用低通濾波器來移除一些背景噪音。目前我能夠成功地加載文件,併產生一個陣列,它的數據值:解釋.WAV文件[Python]
class AudioModule:
def __init__(self, fname=""):
self.stream = wave.open(fname, 'r')
self.frames = []
def build(self):
self.stream.rewind()
for x in range(self.stream.getnframes()):
self.frames.append(struct.unpack('B',self.stream.readframes(1)))
我用struct.unpack(「B」 ..)對於該特定文件。加載音頻文件輸出以下規格:
nchannels: 1
sampwidth: 1
framerate: 6000
我知道sampwidth指定由每個readframes(1)調用返回的字節的寬度。在加載它包含如圖值的陣列(範圍從128至180遍佈):
>>> r.frames[6000:6025]
[(127,), (127,), (127,), (127,), (128,), (128,), (128,), (128,), (128,), (128,), (128,), (128,), (128,), (128,), (128,), (128,), (128,), (128,), (128,), (128,), (128,), (128,), (128,), (128,), (128,)]
問題: 什麼這些數字代表什麼?其他具有較大采樣寬度的音頻文件會提供完全不同的數字。我的目標是修剪音頻文件中的某些頻率,不幸的是我對這一點知之甚少,並不知道這些值如何與頻率相關。
刪除某個頻率閾值以上的所有值的最佳方法是什麼?
def store(self, fout=""):
out = wave.open(fout, 'w')
nchannels = self.stream.getnchannels()
sampwidth = self.stream.getsampwidth()
framerate = self.stream.getframerate()
nframes = len(self.frames)
comptype = "NONE"
compname = "not compressed"
out.setparams((nchannels, sampwidth, framerate, nframes,
comptype, compname))
if nchannels == 1:
for f in self.frames:
data = struct.pack('B', f[0])
out.writeframes(data)
elif nchannels == 2:
for f in self.frames:
data = struct.pack('BB', f[0], f[1])
out.writeframes(data)
out.close()
這些值是時域中的壓力幅度值。您應該使用FFT將信號轉換爲頻域,執行濾波器,然後再將FFT轉換爲時域。 – OregonTrail