Simple Python struct issue
Carlo DiCelico
carlo.dicelico at gmail.com
Fri Oct 2 17:01:15 EDT 2009
On Oct 2, 12:49 pm, MRAB <pyt... at mrabarnett.plus.com> wrote:
> Carlo DiCelico wrote:
> > I saw an article on O'Reilly about using NumPy and Dislin to analyze
> > and visualize WAV files. It's a really fantastic article but was a
> > little out of date. I updated the script to work with the newer
> > modules &etc but am still having trouble getting it working.
>
> > The line
>
> > temp[i,:] = array(struct.unpack("%dB"%(fft_length), tempb),Float) -
> > 128.0
>
> > always returns the same error: "Traceback (most recent call last):
> > File "pysono.py", line 31, in <module>
> > temp[i,:] = array(struct.unpack("%dB"%(fft_length),tempb),float) -
> > 128.0
> > struct.error: unpack requires a string argument of length 256" when I
> > do python pysono.py test.wav 256
>
> > I'm sure it's probably something simple but I just can't see what it
> > is!
>
> > Here's the original code:http://onlamp.com/python/2001/01/31/graphics/pysono.py
>
> .readframes(n) returns (at most) n _frames_ as a bytestring (str), not n
> bytes. I tried reading 256 frames from a .wav file containing stereo at
> 16 bits per channel and got 1024 bytes (4 bytes per frame, not
> surprisingly!).
Yes! Thank you very much for pointing this out, don't know how I
missed it!
More information about the Python-list
mailing list