How to use Rhasspy with Windows Subsystem for Linux (WSL)

Hello there!

This is a quick tutorial to show you how to use Rhasspy in WSL.

Prerequisites

A working WSL environment is required. This guide won’t cover how to install WSL or Rhasspy. I’m assuming that you got that set up already. I’m using Ubuntu 20.04 running in WSL 2.

Pulseaudio

As far as I know there is no way to use your sound devices directly in the WSL environment. That’s why we will be using a Pulseaudio server that is running on the Windows host which communicates via TCP with the Pulseaudio client in WSL.

Installation on Windows

You can find pre-build binaries for Windows on this website. After downloading the zip file extract it and make the following config changes:

etc/pulse/default.pa:

From: #load-module module-native-protocol-tcp
To: load-module module-native-protocol-tcp auth-anonymous=1

Some guides use the option auth-ip-acl here which is not required when you use auth-anonymous=1 (this tells Pulseaudio to accept every connection).

etc/pulse/daemon.pa:

From: ; exit-idle-time = 20
To: exit-idle-time = -1

After that you need to add an exception for “pulseaudio.exe” to your Firewall (at least this was required for the Windows Firewall). I added a rule that allows TCP traffic for private and public networks (I read that WSL uses a public network, though I did not check that).

That’s it for the Windows side! You can launch “pulseaudio.exe” now.

Installation on Linux

Install the Pulseaudio command line tools:

sudo apt install pulseaudio-utils

Now you need to tell Pulseaudio to use the remote server which is running on your Windows host. You can do that by defining an environment variable (you may want to add that line to your “.bashrc” file):

export PULSE_SERVER=tcp:$(grep nameserver /etc/resolv.conf | awk '{print $2}');

You can use nc to see if you can establish a connection to the Pulseaudio server:

nc -vz $(grep nameserver /etc/resolv.conf | awk '{print $2}') 4713

nc should immediately return “Connection to 4713 port [tcp/*] succeeded!”.

parecord and paplay should also work now.

ALSA

Rhasspy uses ALSA to play audio. That’s why we need to tell ALSA to use Pulseaudio. This is quite easy.

Open “/etc/asound.conf” and insert the following content:

pcm.!default {
    type pulse
    # If defaults.namehint.showall is set to off in alsa.conf, then this is
    # necessary to make this pcm show up in the list returned by
    # snd_device_name_hint or aplay -L
    hint.description "Default Audio Device"
}
ctl.!default {
    type pulse
}

“type pulse” requires some extra binaries that can be installed with the following command:

sudo apt install libasound2-plugins

After that arecord and aplay should work just like their Pulseaudio counterparts.

And that’s it

You can start Rhasspy in your WSL environment now and should be able to record and play audio.

(I’m sorry if there some parts of this guide are poorly written. I’m in a rush at the moment.)

6 Likes

Very cool! Do you think this is interesting enough to add to the installation section of the documentation?

I think this would be a great way to get more developers on board. Do you want me to create a pull request?

1 Like

Sure, go ahead! It would be interesting indeed to attract more Windows users.

1 Like

This is excellent, thank you @NullEntity!

As @koan said, I’d like to get this into the documentation. How is the performance on Windows?

I am definitely going to look into this.

Any idea if after you get the pulseaudio and stuff working, if you could get the dockers to run as well?

How is the performance on Windows?

Feels as snappy as on a native Linux system. WSL 2 runs the Linux kernel in a lightweight Hyper-V VM.

1 Like

Docker should be possible too if you run the container on the host network.

1 Like

@koan @synesthesiam Pull request is open: https://github.com/rhasspy/rhasspy-voltron/pull/41

1 Like

That is really great… I managed to make it work with wsl (not wsl2, since it seems only for Windows Insider) with few extra steps (like install gnupg2, git, curl, netcat, alsa-utils…) and setting the PULSE_SERVER variable manually to the ip of the windows machine (ssl sometimes put three lines for me in /etc/resolv.conf).
Thanks for the great contribution.