pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
849 stars 140 forks source link

Working with audio generates error (WSL2 - Windows11) #2857

Closed toxfu closed 4 months ago

toxfu commented 4 months ago

only pygame-ce enviroment on WSL (Windows 11)

when I want to work with audio, regardless of the code, it always generates the following error:

ALSA lib confmisc.c:855:(parse_card) cannot find card '0'
ALSA lib conf.c:5204:(_snd_config_evaluate) function snd_func_card_inum returned error: No such file or directory
ALSA lib confmisc.c:422:(snd_func_concat) error evaluating strings
ALSA lib conf.c:5204:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1342:(snd_func_refer) error evaluating nam
...
ALSA lib conf.c:5204:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5727:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM default
Traceback (most recent call last):
...
pygame.error: ALSA: Couldn't open audio device: No such file or directory

I have already tried the solution with PulseAudio, it works well with applications. But I can't get it to work with pygame.

postscript: I have used this tutorial https://www.linuxuprising.com/2021/03/how-to-get-sound-pulseaudio-to-work-on.html

ankith26 commented 4 months ago

It seems like pygame-ce is trying to find PulseAudio and failing, then falling back to using ALSA.

Could you try updating to pygame-ce 2.5.0.dev2 and using the PipeWire driver? To use the pipewire driver just do something like SDL_AUDIODRIVER=pipewire python3 your_app.py

toxfu commented 4 months ago

As I had been working with my WSL environment for years, at the time the audio was a problem, so I did the pulseaudio tutorial.

Searching I found that WSL now comes with WSLg (which has audio control included). Installed a new WSL environment and everything works great with audio (includes pygame-ce=2.4.1).

Thanks for your time.