wslg icon indicating copy to clipboard operation
wslg copied to clipboard

Support programs that output audio to ALSA

Open TonalidadeHidrica opened this issue 3 years ago • 5 comments

Is your feature request related to a problem:

Some programs that make sound talk directly to ALSA instead of PulseAudio. WSLg supports PulseAudio but not ALSA. As a result, we cannot hear audio from such an application.

Describe the solution you'd like:

There is a plugin of libasound2 (ALSA library) that transfers a connection to ALSA onto PulseAudio. The plugin is called pulse. So what we need is to install the plugin by running

$ apt install libasound2-plugins

and enable it manually by editing ~/.asoundrc

pcm.default pulse
ctl.default pulse

Finally, restart the WSL system.

I think this should be the default configuration so that you can use such ill-behaved programs out-of-box.

Describe alternatives you've considered:

Alternatively, we can let users perform those steps manually, at least now that we do have a description here...

Additional context:

No response

TonalidadeHidrica avatar Oct 16 '22 06:10 TonalidadeHidrica

I would not classify these programs as ill-behaved. For example Chromium always using ALSA. You are only getting sound with Chromium via above described method. In conclusion, I do support your idea.

Gerdya avatar Nov 03 '22 09:11 Gerdya

Can it be extended to solve the problem due to the missing of /dev/snd/seq?

I saw similar error in random programs e.g. mame or aconnect -o

ALSA lib seq_hw.c:466:(snd_seq_hw_open) open /dev/snd/seq failed: No such file or directory
can't open sequencer

arbipher avatar Jan 04 '23 05:01 arbipher

Can confirm this fixed my audio issue in google-chrome.

DKingAlpha avatar Apr 04 '23 21:04 DKingAlpha

Is your feature request related to a problem:

Some programs that make sound talk directly to ALSA instead of PulseAudio. WSLg supports PulseAudio but not ALSA. As a result, we cannot hear audio from such an application.

Describe the solution you'd like:

There is a plugin of libasound2 (ALSA library) that transfers a connection to ALSA onto PulseAudio. The plugin is called pulse. So what we need is to install the plugin by running

$ apt install libasound2-plugins

and enable it manually by editing ~/.asoundrc

pcm.default pulse
ctl.default pulse

Finally, restart the WSL system.

I think this should be the default configuration so that you can use such ill-behaved programs out-of-box.

Describe alternatives you've considered:

Alternatively, we can let users perform those steps manually, at least now that we do have a description here...

Additional context:

No response

This exactly solved my problem with getting Alsa sound working in a Docker image on WSL2. Thank you!

selrahc13 avatar Jul 31 '23 00:07 selrahc13

The suggested solution does not work correctly with the latest version of the various softwares / libs / etc.

➜  aplay 8_Channel_ID.wav
ALSA lib conf.c:1245:(parse_value) default is not a string
ALSA lib conf.c:2012:(_snd_config_load_with_include) _toplevel_:2:0:Invalid argument
ALSA lib conf.c:4120:(config_file_open) /home/user/.asoundrc may be old or corrupted: consider to remove or fix it
ALSA lib conf.c:4042:(snd_config_hooks_call) function snd_config_hook_load returned error: Invalid argument
ALSA lib conf.c:4649:(snd_config_update_r) hooks failed, removing configuration
aplay: main:834: audio open error: Invalid argument

Corrected syntax for the .asoundrc is as follows (Source: Asoundrc Docs):

pcm.!default
{
    type pulse
}
ctl.!default
{
    type pulse
}

The above change gets sound routing properly from alsa to pulse for wslg, however - it appears best I can tell that various applications remain broken. For instance, chromium and firefox both still do not direct sound properly after this change.

dreamwraith avatar Jul 11 '25 16:07 dreamwraith