Using Mixer in Pygame

I’m trying to use the pygame.mixer module for sound, as I’ll eventually switch my project over to an IDE, but it can’t init() a audio dsp device. I’ve seen multiple projects posted that successfully run pygame.mixer.init(), but I can’t figure out why those projects don’t have any dsp errors.

Example Replit:
Tetris - Replit

Open the below topic and follow both steps posted.

Audio in replit may be unreliable, some devices and browsers may work poorly or not at all, there might be a lot of latency.

1 Like

That’s not the issue though. When I try to do pygame.mixer.init(), it says there’s no dsp audio device.

Have you looked at the bottom post?

Open the hidden file .replit and insert:

audio = true

near the top.

For starters, audio is automatically enabled with pygame. I can play audio fine using a separate module. I specifically want to use pygame for audio, and I’m getting a run error trying to do pygame.mixer.init()

Am I missing something that pygame.mixer requires?

Error Code:

pygame 2.5.0 (SDL 2.28.0, Python 3.10.11)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "/home/runner/Storyshift/Storyshift/main.py", line 7, in <module>
    pygame.mixer.init()
pygame.error: dsp: No such audio device

This doesn’t seem 100% correct, but is about the same issue:

So, I’m assuming you’ve refreshed the tab.
There should then be a little headphones icon checkbox near the output which has to be checked first before running the repl.
If it still doesn’t work, maybe it’s a problem with the browser or device, so then provide a minimum repl to have other people test if the audio works.

I tried out pygame audio and it looks like it doesn’t work anymore. It used to work on the newer templates, but now it doesn’t, so it only works on repls with older configuration (prybar and venv).
I wouldn’t recommend using old configuration to have pygame audio. I have not tested the replit package audio, you could use that. Many pygame repls use replit audio instead of pygame audio.
(If replit audio also does not work, then it’s probably good to make a bug report.)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.