I’ve tried to play a .wav in a Python script on a Grove Pi. I’ve set the correct amixer settings: amixer cset numid=3 1. When I start my script, nothing happens. No errors, but also no sound.
My script looks like this:
Is this the complete code that you posted here?
If so, then the sound doesn’t play simply because the program has ended, and pygame is just like that. Program ends, therefore kill every thing.
Add at the top import time
Then the last line would be: time.sleep(60)
That gives your audio 60 seconds to play before getting killed
No, omxplayer is not working either. What works is: aplay crazy.wav. I first have to set the output: amixer cset numid=3 1. That sets the sound output to the jack (phones or speakers). Then my sound is playing as it should do. The crazy thing is, when I play a Python game (also installed on my Jessie Pi image), sound is working fine. I ran trough the Pi games code, but didn’t discover anything special.
Another question, just to be sure.
Are you starting the python program from the same directory as the one that contains crazy.wav?
I just tried my little program, and if the file is not found, I simply get 60 seconds of noise, no error message. Pygame doesn’t seem to think it needs to give out a warning…
Yes, it\s in the same directory. I’ve placed my little program and the sound (.wav) in the /home/pi/Downloads dir. With and without the full path gives the same no-sound-but-noise issue. It’s really very strange, since the python games in my Jessie Dexter distribution of Raspbian are playing sounds. I tried to set the initial sound on my Pi to jack trough sudo raspi-config. No effect.
At this poing I’m out of idea. This is a pygame puzzle, and I’m not that familiar with pygame.
Are you running Raspbian for Robots or straight Jessie from the Foundation?