python - 将 24 位音频样本放入 int32 数组中(小端 WAV 文件)

标签 python audio numpy int endianness

我将 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/

相关文章:

python - 我试图在Visual Studio代码上运行Python,但遇到未找到文件的错误

python - Selenium Extraction…需要提取CSS Selector定位的元素的文本

python - 获取在 Python 表达式中调用的函数

Python-使用 vlc 命令行播放 mp3 音频时出错

python - 两个巨大稠密矩阵的乘法 Hadamard-乘以一个稀疏矩阵

python - Hadoop流作业失败 “Python”

node.js - 将 PCM-Streams 传输到一个函数中

cakephp - Cakephp读取音频文件

python - 将 numpy 数组发送到 Bokeh 回调以作为音频播放

python - 如何填充图像边缘内的白色背景以去除背景?