OiO.lk Blog python Problems with Pygame mixer and ALSA
python

Problems with Pygame mixer and ALSA


I’m trying to get pygame to run in a bigger script to play multipule overlapping audios based of key presses, basically to simulate a piano. However, I keep getting the error "pygame.error: ALSA: Couldn’t open audio device: Unknown error 524" whenever I call the pygame.mixer.init() function. I seperated a sample test code to see if it was a problem with the large script but I recieve the same error on the same line. I’ll post the smaller code snippet below. I’m running this on a Raspi 3b+ with Bookworm installed. I’m using the latest version of pygame. As far as audio devices connected, I’m using the 3.5 mm audio jack connected to a fossi audio which runs to a speaker with speaker wire. I’ve tried troubleshooting this to no avail by setting amixer cset numid=3 1 and restarting the ALSA daemon. Any help would be appreciated.

Here is the code snippet that is still produing the Unknown error, it produces the error on line 2, the init function:

import pygame
pygame.mixer.init()
sound = pygame.mixer.Sound('audio_1.wav')
sound.play()

while pygame.mixer.get_busy():
    pygame.time.delay(100)

It’s probably relevant to say that I’ve tested random audi files with the aplay command and everything plays perfectly fine through the speaker setup. I’ve also tested with random WAV files that I’ve grabbed from online to make sure that it is not my audio files that are corrupted. I’m pretty inexperienced with Audio settings and configs so if it’s something very simple or something with the setup I apologize in advance but I’ve used this setup with omxplayer in the past and had success so I’m struggling to see what I’m doing wrong here.

Thanks in Advance



You need to sign in to view this answers

Exit mobile version