我将 24 位单声道音频 .wav 文件读入 <i4
类型的数组中( <i3
不存在)
data = numpy.fromfile(fid, dtype=`<i4`, count=size//3)
为了正确获取音频样本,我应该做什么?我应该交换这样的字节顺序吗?
最佳答案
这是读取 24 位文件的解决方案(感谢 Warren Weckesser 的要点 https://gist.github.com/WarrenWeckesser/7461781 ):
data = numpy.fromfile(fid, dtype='u1', count=size) # first read byte per byte
a = numpy.empty((len(data)/3, 4), dtype=`u1`)
a[:, :3] = data.reshape((-1, 3))
a[:, 3:] = (a[:, 3 - 1:3] >> 7) * 255
data = a.view('<i4').reshape(a.shape[:-1])
这可以直接插入到def _read_data_chunk(fid, noc, bits):
(scipy\io\wavfile.py
)中。
关于python - 将 24 位音频样本放入 int32 数组中(小端 WAV 文件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20434978/