wave.readframes() (or conversion?)

Tim Roberts timr at probo.com
Sun Sep 26 02:31:10 EDT 2004


andrea valle <andrea.valle at unito.it> wrote:
>
>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.
>
> >>> a = wave.open("/test.wav", "r")
> >>> a.readframes(1)
>'\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.
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list