【发布时间】:2018-05-08 11:17:59
【问题描述】:
我看到 this question and answer 关于在 wav 文件上使用 fft 并尝试像这样实现它:
import matplotlib.pyplot as plt
from scipy.io import wavfile # get the api
from scipy.fftpack import fft
from pylab import *
import sys
def f(filename):
fs, data = wavfile.read(filename) # load the data
a = data.T[0] # this is a two channel soundtrack, I get the first track
b=[(ele/2**8.)*2-1 for ele in a] # this is 8-bit track, b is now normalized on [-1,1)
c = fft(b) # create a list of complex number
d = len(c)/2 # you only need half of the fft list
plt.plot(abs(c[:(d-1)]),'r')
savefig(filename+'.png',bbox_inches='tight')
files = sys.argv[1:]
for ele in files:
f(ele)
quit()
但无论何时我称呼它:
$ python fft.py 0.0/4515-11057-0058.flac.wav-16000.wav
我得到错误:
Traceback (most recent call last): File "fft.py", line 18, in <module> f(ele) File "fft.py", line 10, in f b=[(ele/2**8.)*2-1 for ele in a] # this is 8-bit track, b is now normalized on [-1,1) TypeError: 'numpy.int16' object is not iterable
如何创建一个脚本,为参数列表中的每个文件生成频率分布?
【问题讨论】:
-
看来
a只是一个整数。您确定您的曲目是两个频道吗? -
@alexblae 他们都是单频道