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.)