我是编程的初学者,我使用Unbuntu。struct.error:解压缩需要一个长度为4的字符串参数 - 音频文件
但是现在我试图用Python来进行声音分析。
在下面的代码我用WAV包打开wav文件和结构将信息转换:
from wav import *
from struct import *
fp = wave.open(sound.wav, "rb")
total_num_samps = fp.getnframes()
num_fft = (total_num_samps/512) - 2 #for a fft lenght of 512
for i in range(num_fft):
tempb = fp.readframes(512);
tempb2 = struct.unpack('f', tempb)
print (tempb2)
所以在终端显示的信息是:
struct.error: unpack requires a string argument of length 4
请,有人可以帮我解决这个问题吗?有人对解释声音文件有其他策略的建议?
所有的最好的!
我试过你的建议,它的工作。非常感谢!但我还有一个问题。如果我想要提取分贝信息,我应该使用下面的代码吗? 'db = struct.unpack('{} h'.format(512 * channels),“%dB”%(512))' – amonte