[issue5202] wave.py cannot write wave files into a shell pipeline

David Jones report at bugs.python.org
Thu Feb 12 10:00:11 CET 2009


David Jones <drj at pobox.com> added the comment:

The following program does a very basic do-i-get-back-what-i-wrote test.  
sunau can't cope; I am investigating.

#!/usr/bin/env python
# $Id$
# Audio File Tests

import aifc
import sunau
import wave

import struct
import sys
from StringIO import StringIO

frames = struct.pack('256B', *range(256))
log = sys.stderr

# Basic test of reproducability.
# We test that a set of frames (an entirely artifical set, see `frames`, 
# above) can be written to an audio file and read back again to get the 
# same set of frames.
# We test mono/stereo, 8-bit/16-bit, and a few framerates.    
# As of 2009-02-12 sunau does not pass these tests, so I recommend that 
# you remove it.
for af in (aifc, sunau, wave):
  for nchannels in (1, 2):
    for sampwidth in (1, 2):
      for framerate in (11000, 44100, 96000):
        print >> log, "%s %d/%d/%d" % (af.__name__,
          nchannels, sampwidth, framerate)
        f = StringIO()
        w = af.open(f, 'w')
        w.setnchannels(nchannels)
        w.setsampwidth(sampwidth)
        w.setframerate(framerate)
        w.writeframesraw(frames)
        w.close()
        s = f.getvalue()
        f = StringIO(s)
        w = af.open(f)
        assert w.getnchannels() == nchannels
        assert w.getsampwidth() == sampwidth
        assert w.getframerate() == framerate
        assert w.readframes(len(frames)//nchannels//sampwidth) == frames
        assert w.readframes(1) == ''

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5202>
_______________________________________


More information about the Python-bugs-list mailing list