Sound Options through RP4

March 4, 2023, 17:21

sherpapsu

Working on a hockey siren project that activates a rotating beacon if a selected hockey team scores. Curious of the best option to play custom audio (e.g. horn sounds, goal music, etc.) through a RP4. I have an 8ohm speaker & LM386 chip, but now I'm thinking that can only be used to process the most basic of sounds through PWM (am I wrong?). Trying to not send the audio over bluetooth to a speaker to avoid having an additional peripheral (which decreases portability of the device). Any other options y'all can think of?

andy_s

Pi4 has full blown soundcard that can easily play music.

andy_s

Works as any other computer soundcard <@267468714486530058>

andy_s

You can use hdmi out for digital audio output as well.

andy_s

Pi4 is often used as mediaplayer for movies 🙂

.mrlunk

I founf the easy way to play a .wav soundfile is to use Pygame: import pygame # initialize pygame mixer pygame.mixer.init() # load sound file sound = pygame.mixer.Sound("/path/to/soundfile.wav") # play sound file sound.play() # wait for sound to finish playing while pygame.mixer.get_busy(): pass # cleanup pygame mixer pygame.mixer.quit()

andy_s

see

.mrlunk

pip install pygame 😉

andy_s

yep

sherpapsu

This is helpful..thank you! I've played around with pygame a bit so am comfortable there. Any recos on the hardware device to play audio? Could I play it through the PWM ping to one of those small 8ohm speakers? Any small devices that could mount inside a small housing with the rotating beacon that I could use the hdmi audio out with?

andy_s

<@267468714486530058> why dont you just use that 3.5mm jack on your pi for audio out?