How to get the sound (PulseAudio) to work on WSL2

This article describes how to get the sound (PulseAudio) for processing WSL2 Under Microsoft Windows.

Follow these instructions and you will be able to use Pulse audio Used for both console and GUI applications on Windows/WSL2 (although this article does not involve running graphical applications on WSL2). With this feature, the microphone will not work, or at least it will not work for me (and I, one of them does not need it).

Microsoft plan Add built-in support for running graphics applications and sounds to WSL2. But until then, you can use these instructions to make the sound work on WSL2.

If you are still using WSL1, please see how to upgrade to WSL2 Here. You can check if you are already using WSL2 by running the following command wsl -l -v In Windows PowerShell.Every machine using WSL2 should be listed here, 2 of which are theirs VERSION; If you don’t see the version number, or if you see an error message, you have WSL1.

The following is a screenshot showing that I am using the Windows Terminal of Ubuntu/WSL2 Combs The console music player plays music. You cannot hear the music to check if the music is actually working, so this screenshot is almost useless, but I need to use the screenshot as an article thumbnail ?️.

As a completely irrelevant note, if you want to use cmus on WSL2, please edit it ~/.config/cmus/rc File (create if it doesn’t exist) and add set output_plugin=pulse Make its sound output work normally on the Windows desktop.

1. Download PulseAudio for Windows.

On Windows:

The latest version of PulseAudio for Windows 10 that I can find is version 7 Here, Is built for X2Go. You can visit the link and click “Snapshot” to download PulseAudio for Windows, Or click here to download.

This downloaded a .tar.gz file.Unzip this archive file and rename the folder containing the following pulseaudio.exe, And other PulseAudio executable files and files to pulseAnd then copy this new pulse Folder to C: (So ​​you should have e.g. C:pulsepulseaudio.exe).

2. Configure PulseAudio for Windows.

On Windows:

Create a file named config.pa in C:pulse. In order to be able to rename file extensions on Windows, you need to enable the display of file extensions from File Explorer.

at this C:pulseconfig.pa File, add the following content and save the file when finished:

load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;172.16.0.0/12load-module module-esound-protocol-tcp auth-ip-acl=127.0.0.1;172.16.0.0/12load-module module-waveout sink_name=output source_name=input record=0

Here we allow from 127.0.0.1 This is the local IP address, and 172.16.0.0/12 This is the default space of WSL2 (172.16.0.0-172.31.255.255).

3. Configure PulseAudio in WSL2.

On WSL2 (Ubuntu/any device you use):

Let us make sure you have libpulse0 Has been installed, otherwise it will not work properly. Its name and installation command depend on the Linux distribution you are using, so you need to search for and install it. On Ubuntu/Debian, you can use the following command to install:

sudo apt install libpulse0

Still on WSL2, you still need to edit ~/.bashrc Edit the file with a text editor-using the following command, we will edit it with the Nano console editor:

nano ~/.bashrc

Scroll down to the end of this file and paste the following:

export HOST_IP="$(ip route |awk '/^default/{print $3}')"export PULSE_SERVER="tcp:$HOST_IP"#export DISPLAY="$HOST_IP:0.0"

Here you can uncomment export DISPLAY Also export DISPLAY Environment variable (I have commented it out by default because not everyone needs it). If you want to use something like VcxSrv to launch graphics applications from WSL2, you need to do so (using the configuration in this article, graphics applications running in WSL2 will have good support).

When finished, save the file and exit Nano (Ctrl + o, Enter then x Save the file and save it in Nano).Next, change ~/.bashrc File to use the new environment variables:

source ~/.bashrc

4. Install PulseAudio as a Windows service.

On Windows:

To start PulseAudio as a Windows service, we will use NSSM. Download NSSM from here, Unzip the downloaded archive and copy win64 nssm.exe Executable to C:pulse.You can win64 The folder in the downloaded NSSM zip archive.

Next, search for PowerShell in the Windows Start menu, right-click the PowerShell entry, and select Run as Administrator.

In PowerShell, type or paste:

C:pulsenssm.exe install PulseAudio

After running this command, the NSSM GUI will be displayed.In its Application Label, use:

NSSM application tab

  • Application path: C:pulsepulseaudio.exe
  • Startup directory: C:pulse
  • parameter: -F C:pulseconfig.pa --exit-idle-time=-1
  • Service name (should be filled in automatically when the NSSM dialog box is opened): PulseAudio

In the “Parameters” field, we are using -F, It tells PulseAudio to run the specified script at startup, and --exit-idle-time=-1 Disable the option to terminate the daemon after a few seconds of inactivity.

in Details Label, enter PulseAudio inside Display name site:

NSSM details tab

After completing all of these operations, click Install service Button.

If you need to delete this Windows service in the future, please run PowerShell again as an administrator, and then run the following command to delete the service:

C:pulsenssm.exe remove PulseAudio

5. Start the PulseAudio Windows service.

Start the Windows Task Manager and click Services Tab and scroll to PulseAudio.When you find the PulseAudio service, right-click on it and select Start it:

Windows Task Manager Service PulseAudio

We are done. PulseAudio is now working. You should be able to use audio-enabled applications in WSL2 and hear its audio output on the Windows 10 desktop.

Since we have installed PulseAudio as a service on Windows 10, once it is started, it will start automatically when you log in to the Windows desktop, so there is no need to start it manually again.

reference: Ubuntu discourse, This one, This one with X2Go Wiki.

Source

Related Posts