I have been given a large WAV-file of continuous underwater recording which I would like to convert to a numpy array for analysis. I am struggling to do this.
So far I have:
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)
The first frame looks like this: '\xcd\xbc\xff@\x01\x00'. I have tried to unpack it using struct but unpack whatever I do I get the following error: "str size does not match format". I guess this is related to the fact that Python struct cannot handle 24-bit data.
The parameter of the wave-file looks as following:
- nchannels=2
- sampwidth=3
- framerate=48000
- nframes=283516532L
- comptype='NONE'
- compname='not compressed'
Someone know hows to read a 24-bit stereo WAV-file into a numpy array?
scipy
reads 24bit wav files into an array of 32 bit integers, but it doesn't write 24 bit wavs. You can always read the bytes one at a time, and them convert them into 24 bit values doing something likew24 = (w8_3 << 16) | (w8_2 << 8) | w8_1
– Payment