我的目标是将 pyaudio 提供的字符串正确解包到 int16 以进行一些修改,然后再次打包以进行播放。
这是我到目前为止得到的(从其他帖子复制的代码):
#data contains my string of interleaved int16 data
#this code should unpack it accordingly
# 1 short out of each 2 chars in data
count = len(data)/2
format = "%dh"%(count) #results in '2048h' as format: 2048 short
shorts = struct.unpack(format, data)
#here some modifications will take place but are left out to test packing
#now i need to pack my short data back to pyaudio compliant string
#i have tried the following with no success. just random noise
struct.pack(str(len(shorts)*2) + "s", str(shorts))
现在我的问题:
- 将
struct.pack
我的数据恢复为 pyaudio 字符串的正确参数是什么?