[Tutor] wave.readframes() (or conversion?)

Kent Johnson kent_johnson at skillsoft.com
Sat Sep 25 03:26:42 CEST 2004


You can use the struct module to do this. You will have to find out whether 
the wave data is stored in big-endian or little-endian format.

 >>> import struct
 >>> hex(32000)
'0x7d00'
 >>> d='\x7d\x00\x00\x00'
 >>> struct.unpack('<hh', d)
(125, 0)
 >>> struct.unpack('>hh', d)
(32000, 0)

Kent

At 12:42 PM 9/23/2004 +0200, andrea valle wrote:
>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.
>
> >>> a = wave.open("/test.wav", "r")
> >>> a.readframes(1)
>'\x00\x00'
>
>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
>andrea.valle at unito.it
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list