wave.readframes() (or conversion?)

A

andrea valle

Hi to all,
I'm using wave module with success. I'm writing data to wave file.
Typically I create a list of values (data) and pass it to
..writeframes(data) methods.

a = wave.open("/test.wav", "w")
a.writeframes([32000, 0])

This sets the first sample to 32000 and the 2nd to 0

But when I use the .readframes() method I don't know exactly what
values I extract from the open wave.
'\x00\x00'
What does it mean? (hexa?)
How do I convert it to an integer? I'd like to have it like 32000 or 0,
so to make some maths on it.

Thanks a lot

-a-

Andrea Valle
Laboratorio multimediale "G. Quazza"
Facoltà di Scienze della Formazione
Università degli Studi di Torino
(e-mail address removed)
 
T

Tim Roberts

andrea valle said:
I'm using wave module with success. I'm writing data to wave file.
Typically I create a list of values (data) and pass it to
.writeframes(data) methods.

a = wave.open("/test.wav", "w")
a.writeframes([32000, 0])

What version of Python are you using?? On my Win32 Python 2.3, writeframes
accepts only strings, and only after you have set the frame rate, sample
size, and number of channels.
But when I use the .readframes() method I don't know exactly what
values I extract from the open wave.

'\x00\x00'
What does it mean? (hexa?)
How do I convert it to an integer? I'd like to have it like 32000 or 0,
so to make some maths on it.

You get back a buffer of bytes. You can use the array() module to convert
it to a list of integers.
 
T

Tim Roberts

Tim Roberts said:
andrea valle said:
I'm using wave module with success. I'm writing data to wave file.
Typically I create a list of values (data) and pass it to
.writeframes(data) methods.

a = wave.open("/test.wav", "w")
a.writeframes([32000, 0])

What version of Python are you using?? On my Win32 Python 2.3, writeframes
accepts only strings, and only after you have set the frame rate, sample
size, and number of channels.

For those who may be following this at home, Andrea and I had a private
e-mail exchange during which we discovered why HE was able to pass a list
of integers to wave.writeframes, while I got an error saying that it had to
be a string.

Turns out he's using a Mac, which is big-endian. On big-endian systems,
wave.writeframes passes its first parameter to array.array, calls byteswap,
and uses array.tofile to write it out. array.array accepts a list.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top