[Tutor] ossaudiodev, pygtk, and flushing buffers

Matthew White mwhite3 at ttsd.k12.or.us
Wed May 10 18:59:14 CEST 2006


Hello All,

I'm writing a little audio player that plays voicemail files.  (I realize
I'm reinventing the wheel, but it's still fun.)

The problem I'm experiencing is that I'm hearing the last fraction of
the sound clip twice, either when the clip is done playing or when the
program exits.

I've tried a few things and none of them have worked.  The bit of code
that does the playing is here:

    def play(self):
        if self.data_written < self.file_length:
            buf = self.data.read(self.buf_size)
            self.data_written += self.dsp.write(buf)
            self.percent_done = self.data_written / self.file_length

        if self.data_written == self.file_length:
            self._reopen_audio_device()

This causes the second playing of the "last little bit" when the end of
the file is reached.  When I don't include the second if statement, the
"last little bit" gets played when the program exits.

According to the documentaiton, closing the audio device will flush any
data in the sound card buffer.  I guess what I'm hearing is that buffered
clip being flushed.  I've thought about using the mixer device to put the
volume to zero, flush the buffer, then turning the volume back up again,
but that seems like a hack.

If anyone decides to use this program, you'll need to use a .wav file and
change the value of self.sample_rate in vmPlayer.py from 8000 to 44100 (or
whatever rate your file is encoded in)  (Also, I plan on auto-detecting
the sample rate in the future.  I hard coded 8000 because that's the
rate the voice mail system uses.)

See attached files for the code.

-mtw

-------------- next part --------------
A non-text attachment was scrubbed...
Name: player_py.RENAMED_BY_TTSD-0
Type: application/renamed_by_ttsd-0
Size: 1770 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20060510/62d453bd/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vmPlayer_py.RENAMED_BY_TTSD-2
Type: application/renamed_by_ttsd-2
Size: 1216 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20060510/62d453bd/attachment-0001.bin 


More information about the Tutor mailing list