Hello !
I'm making a project with the Raspberry Pi Zero and the Pimoroni Speaker pHat. I added a push button and i want the speaker to play a sound randomly in a folder when the button is pressed. I'm doing the logic in python and everything works but I have a weird bug when playing the audio.
In the command-line
aplay ./redfr/Bonjour.wav works perfectly fine.
But in python if I do
os.system("aplay ./redfr/Bonjour.wav &") it displays
Using device: speaker-phat and freeze for many seconds before playing the sound, and it freezes again for few seconds. (I tried without the & and same).
So I tried using
playsound('./redfr/Bonjour.wav') but it gives me an error i donĀ“t understand (I'll post it after because it's big)
I tried using pygame:
pygame.init()
soundfile = pygame.mixer.Sound('./redfr/Bonjour.wav')
soundfile.play()
This way it takes a very long time for the script to start and then I get this
pygame 2.5.2 (SDL 2.0.14, Python 3.9.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
Using device: speaker-phat
and it plays the sound, and if I press the button it plays the sound instantly. great right ? well not really because right after the sound played the program crashed saying
Segmentation fault :/
Does anyone has an idea of what's wrong here ?