wave.readframes() (or conversion?)
andrea valle
andrea.valle at unito.it
Sun Sep 26 04:06:37 EDT 2004
On 26 Sep 2004, at 08:31, Tim Roberts wrote:
> You get back a buffer of bytes. You can use the array() module to
> convert
> it to a list of integers.
Thanks a lot, I'll try.
> 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.
I'm using MacPython hardwired (damn') with Numerical package (Numeric
22.0) in MacOSX 10.3.5. It's Python2.3.
I surely have to set wave params, but then I pass .writeframes an array
converted to list (array.tolist()). Works for me (luckily).
Here a minimum example:
from Numeric import *
from RandomArray import *
class SoundFile:
def __init__(self, signal):
self.file = wave.open('/test.wav', 'w')
self.signal = signal
self.sr = 44100
def write(self):
print "\nwriting to wavefile"
self.file.setparams((1, 2, self.sr, 6, 'NONE', 'noncompressed'))
self.file.writeframes(self.signal.tolist())
print "done\n"
signal = uniform(-1, 1, 44100)
f = SoundFile(signal)
f.write()
Best
-a-
Andrea Valle
Laboratorio multimediale "G. Quazza"
Facoltà di Scienze della Formazione
Università degli Studi di Torino
andrea.valle at unito.it
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 1568 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20040926/0729aefb/attachment.bin>
More information about the Python-list
mailing list