Getting speaker Phat to work from python


#1

So I’ve got as far as being able to play a .wav file from the command line, but I need to be able to play from within a Python program and so far have been unsuccessful.
I tried to find out if the alsa module was loaded with Help (“modules”) and got back a message that said
Automation Phat detected
and nothing else.
In the meantime I noticed that the speaker was very hot. I note that this has already been raised as a problem, but is there a solution?
So, how do I find out if alsa is loaded and if so, why doesn’t it work?


#2

The issue with help("modules") is something I’ve been carefully rolling out fixes for. The fix for Automation HAT should be available within a few days via apt update && apt upgrade

You will probably have more luck using something like PyGame to play sound files: https://www.pygame.org/docs/ref/mixer.html

Here’s an example of PyGame being used to create a drum pad and trigger: https://github.com/pimoroni/drum-hat/blob/master/examples/drums.py


#3

Thanks, I’ll look out for the update.

I’ve worked out that using alsa from within python won’t work for me, so I tried pygame.
Works a treat.