我被赋予了一个大的连续水下录音的WAV文件,我想将其转换为numpy数组进行分析。但我无法做到这一点。
到目前为止,我已经:
第一帧如下:'\xcd\xbc\xff@\x01\x00'。我试着使用 struct 解包,但无论我做什么都会出现以下错误:"str size does not match format"。我猜这与 Python 的 struct 无法处理 24 位数据有关。
波形文件的参数如下:
nchannels=2 sampwidth=3 framerate=48000 nframes=283516532L comptype='NONE' compname='not compressed'
有人知道如何将 24 位立体声 WAV 文件读入 numpy 数组吗?
到目前为止,我已经:
import numpy as np
import scipy as sp
import wave as wv
import struct
wavefile = wv.open(filename,'r')
(nchannels,sampwidth,framerate,nframes,comptype,compname) = wavefile.getparams()
// read a sample as example
wavedata =wavefile.readframes(1)
第一帧如下:'\xcd\xbc\xff@\x01\x00'。我试着使用 struct 解包,但无论我做什么都会出现以下错误:"str size does not match format"。我猜这与 Python 的 struct 无法处理 24 位数据有关。
波形文件的参数如下:
nchannels=2 sampwidth=3 framerate=48000 nframes=283516532L comptype='NONE' compname='not compressed'
有人知道如何将 24 位立体声 WAV 文件读入 numpy 数组吗?
scipy
将24位wav文件读入一个32位整数数组中,但它不会写入24位的wav文件。你可以一次读取字节,并将它们转换为24位的值,类似于w24 = (w8_3 << 16) | (w8_2 << 8) | w8_1
这样的操作。 - Jaime