Writing a aiff audio file problem?
jym
jym at cornsoft.com
Sun May 4 10:58:42 EDT 2008
Hi all
I can not creat a usable audio file in the aiff format. The example code
below creates a wav file that I can listen to just fine. However, I just get
noise when I listen to the resulting aiff file. Is this a byte order
problem? I am using Python 2.5.2 on Windows XP. Any guidance on this issue
would be appreciated.
Thanks
jym
import pyaudio
import wave
import sys
import aifc
chunk = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 8000
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output"
p = pyaudio.PyAudio()
stream = p.open(format = FORMAT,
channels = CHANNELS,
rate = RATE,
input = True,
frames_per_buffer = chunk)
print "* recording"
all = []
for i in range(0, RATE / chunk * RECORD_SECONDS):
data = stream.read(chunk)
all.append(data)
print "* done recording"
stream.close()
p.terminate()
#write data to AIFF file
data = ''.join(all)
af = aifc.open(WAVE_OUTPUT_FILENAME + ".aiff", 'wb')
af.setnchannels(CHANNELS)
af.setsampwidth(p.get_sample_size(FORMAT))
af.setframerate(RATE)
af.writeframes(data)
af.close()
# write data to WAVE file
wf = wave.open(WAVE_OUTPUT_FILENAME + ".wav", 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(data)
wf.close()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080504/4085f3d0/attachment.html>
More information about the Python-list
mailing list