I’m wanting to make a standalone device that plays a .wav file when a button is pressed, using a pHATBEAT and a Pi Zero W. The simple Python 3 script I’ve written so far works fine when executed in IDLE, but if I try to run it from the command line I get silence, and a couple of random LEDs light on the pHAT. If I remove the button handlers and just run the bit that plays the sound file, it’s fine. I’m new to all this so it’s hopefully something simple!
I run it using python whistle.py
from the directory containing the script; pwd returns /home/pi/GPIOMB
and ls returns sounds whistle.py
sounds is the directory containing the .wav file(s).
Is the “sounds/whistle.wav” directory in your current working directory?
“MemoryError” seems like it might be a red herring- I can’t see a 1.0MB wav file being an issue, unless it’s accidentally loaded hundreds of times or some other weirdness.
Thanks both. I’ve tried mov the .wav file to the same directory as the .py file and also specifying the full path name. Both result in silence and a return to the command prompt when run from the command line, and the same MemoryError if I type the commands in separately. I’m assuming the pygame library is well proven and unlikely to be the issue, is that reasonable? Is there a log file somewhere that might offer a clue? I’ve a couple of RPi books on order which I’m hoping will help clarify how the Pi works.
I’m more used to programming microcontrollers in assembly language when it’s much easier to see exactly what’s going on, and it’s 30 years or more since I used Unix!