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

Re: [pygame] Re: Re: playing sound on Windows



Hi Sarah,

There are two audio drivers pygame.mixer can use on Windows. I believe the default is "waveout". Try setting the SDL_AUDIOMIXER environment variable to "dsound" to use the directX. This can be done within Python by adding these two lines to the top of the file:

import os
os.environ['SDL_AUDIODRIVER'] = "dsound"


This will work for Windows, but not Linux. So add add some conditional code to only set SDL_AUDIODRIVER when the program is running on Windows.

Hope this helps,

Lenard Lindstrom

On 13-06-29 07:34 PM, sarah wrote:
Hi, reallyvery strange. I did these tests (actually I had already done
them, when I was programming it to work on Linux, but unfortunately the
final user of the program this script is part needs it to work on
windows). I also tested what Christoph suggested, but the result is the
same. My wav files still play in windows players. the print of
get_init() showed the same result you've got. So I'm keeping trying
comand combinations unsuccessfully, for what I still need you guys'
help.

Sarah

-----Mensagem original-----
De: James Paige <Bob@xxxxxxxxxxxxxxxxxxx>
Para: pygame-users@xxxxxxxx
Data: Quinta, 27 de Junho de 2013 10:48
Assunto: Re: [pygame] playing sound on Windows

I don't know why this problem is happening, but I can reproduce it.

I tested your script (with my own 0.wav file) and it worked fine on
Linux, but on Windows 7 (64 bit) with both python 2.6 + pygame 1.9.1 and
python 2.7 and pygame 1.9.2 there is no sound.

Although this does not solve your problem, I think you should remove the
pygame.mixer.pre_init() because inside the class but not inside a
function is definitely the wrong place for it, and even if you move it,
all it does is change the defaults for pygame.mixer.init() to the same
values those defaults have already.

You can also add

    print pygame.mixer.get_init()

and it will display the settings with which the mixer was initialized,
or if mixer init failed entirely it will return None.

When I tested, .get_init() returned (22050, -16, 2) indicating that the
init succeeded with the default settings.

Before I tested your script on my windows box, I tested my 0.wav file in
audacity and it sounded fine.

After I tested your script, and the sound failed to play, I tried it
again in audacity, and then it would not play.

Even though I could not get the .wav file to play anymore either in
python or in audacity, the windows volume mixer test sound still worked
find.

Very strange.

On Thu, Jun 27, 2013 at 01:04:12PM -0300, sarah marques wrote:
Yes, I meant that. Sorry, I translated my code from Portuguese to send
it to the list, and this word 'som' slipped.

Sarah Barreto Marques

2013/6/27, James Paige <Bob@xxxxxxxxxxxxxxxxxxx>:
On Thu, Jun 27, 2013 at 08:11:39AM -0700, sarah wrote:
Hi all,
I've just subscribed to this list hoping someone can hplease elp me with
the
following problem: I wrote the class bellow (I also attached it) that
simply plays a sound
file when its method play_file() is called. It works on Linux perfectly,
but
on Windows, no sound is played and I do need to find the reason of it.
Configurations are:
Windows 7 (32 bits), Python 2.6 and Pygame 1.9.1 (win32). Thank very
much for any help!
Sarah Barreto Marques

www.audiogames.com.br
@sarahbmarques




import sys, pygame
import time

class Sound:
     pygame.mixer.pre_init(frequency=22050, size=-16, channels=2,
buffer=1024)

     def play_file(self, name):
#        pygame.mixer.pre_init(frequency=44100, size=-16, channels=2,
buffer=1024)
#        pygame.mixer.get_init()
         sound=pygame.mixer.Sound(name)

         print 'playing'
         sound.play()

         print 'done'
         time.sleep(2)
         return sound

if __name__=='__main__':
     pygame.init()
     sound=Sound()
     som.play_file('0.wav')

did you mean:

   sound.play_file('0.wav')

in the last line? som does not seem to be defined anywhere.

---
James Paige