[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Problem copying then playing a wav file



I'm using the pyaudio example to save a wave file called "temp.wav"
http://people.csail.mit.edu/hubert/pyaudio/#docs

The following code correctly plays it:

    def Play(self):
        if not pygame.mixer.get_init():
            pygame.mixer.init()
        if os.path.exists("temp.wav"):
            self.snd = pygame.mixer.Sound("temp.wav")
            self.snd.play()

However when I copy "temp.wav" to a new filename like so:

        fd, filename = tempfile.mkstemp(".wav", "myaudio_", dirname)
        shutil.copy("temp.wav",filename)

The following code fails to play any wave files I create, I just get a
*pock* then nothing.

        self.snd = pygame.mixer.Sound(dirname+filename)
        self.channel = self.snd.play()

This is from a wxPython app. If I close the app and reopen it (I save
the list of recorded sound filenames), then the sound file plays
correctly. The sound file exists after the shutil copy is called, and
I can play the file in an external player. Anyone have any ideas why
this would happen?