problems to write a wav file

Gautier Krings gautier.krings at gmail.com
Thu May 24 09:55:42 EDT 2007


Hello,

I have a small problem for writing a .wav file. I can't find in which format
I have to pass my data in the writeframes function of the wave module.

here's my code, I am just trying to open a wav file, extracting the data
from it, and writing it in another wav file.
The problem is that the sound I get in the second wav file isn't the same as
from the firs file (in fact it is horrible).

import wave, audioop, numpy
from numpy.fft import *
from math import *

signal = wave.open('C:\demo.wav', 'rb' )
Nframes = float(signal.getnframes())
width = signal.getsampwidth()
frameRate = signal.getframerate()

frame = signal.readframes(1)
power =[]
while len(frame):
    power.append(audioop.rms( frame, width ))
    frame = signal.readframes(1)

new_signal = wave.open('C:\demo2.wav', 'wb')
new_signal.setsampwidth(width)
new_signal.setframerate(frameRate)
new_signal.setnchannels(signal.getnchannels())

for j in range(len(power)):
     data = hex(power[j])    ---> I guess that my problem is located at this
line
     new_signal.writeframes(data)
new_signal.close()


thanks a lot,
-- 
Gautier Krings
gautier.krings at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070524/e8a0da81/attachment.html>


More information about the Python-list mailing list