In setting up my RasPi 3B as a HA Voice Assistant per Chapter 5 of Year of the Voice I followed the tutorial referenced in the documentation. It all worked as stated, and really didn’t leave me much to add.
… but I will anyway.
Note that this assumes Wyoming, openwakeword, and a Voice Assist pipeline have already been installed and setup on your HA server.
The documentation does include useful additional information; but assumes that the reader is also a developer who doesn’t need things in much detail. I strongly recommend you work through the Tutorial, then scan the documentation for the advanced options.
Installation
You should use the Install OS and Install Software sections from the tutorial. “script/setup” might be enough of a hint to a seasoned developer, but newer users need more detail.
Determine Audio Devices
Testing the audio input and output is vital; and is something new users often have trouble with.
If you have a reSpeaker 2-mic or 4-mic HAT (or a clone thereof), follow the instructions in the tutorial. Note that this uses a different installation script which may not be correct for the v6.6 kernel used by latest RasPi OS. See my post #36 below if this is a problem.
If you are using different audio devices you will have to amend the commands throughout the tutorial.
In my case I am using a USB microphone and speaker connected to the 3.5mm headphone socket – so instead of installing the reSpeaker drivers I used commands “arecord -L” and “aplay -L” to check what audio devices are detected.
pi@HA-voice-2:~ $ arecord -L
null
Discard all samples (playback) or generate zero samples (capture)
hw:CARD=ABTWPDQ0222M,DEV=0
ABTWPDQ-0222-M, USB Audio
Direct hardware device without any conversions
plughw:CARD=ABTWPDQ0222M,DEV=0
ABTWPDQ-0222-M, USB Audio
Hardware device with all software conversions
default:CARD=ABTWPDQ0222M
ABTWPDQ-0222-M, USB Audio
Default Audio Device
sysdefault:CARD=ABTWPDQ0222M
ABTWPDQ-0222-M, USB Audio
Default Audio Device
front:CARD=ABTWPDQ0222M,DEV=0
ABTWPDQ-0222-M, USB Audio
Front output / input
dsnoop:CARD=ABTWPDQ0222M,DEV=0
ABTWPDQ-0222-M, USB Audio
Direct sample snooping device
pi@HA-voice-2:~ $
The information I am looking for here is, what devices are available (here it’s only “ABTWPDQ0222M USB Audio”, but my aplay includes HDMI and the headphone socket on my microphone as well as the built-in 3.5mm socket). I want the “plughw” variation since that includes any conversions built into the driver software. So my device is “plughw:CARD=ABTWPDQ0222M,DEV=0”.
For my headphone under aplay -L is:
plughw:CARD=Headphones,DEV=0
bcm2835 Headphones, bcm2835 Headphones
Hardware device with all software conversions
To test, record a 5 second message to test.wav:
arecord -D plughw:CARD=ABTWPDQ0222M,DEV=0 -r 16000 -c 1 -f S16_LE -t wav -d 5 test.wav
to which I say some random test words. Then play it back to my headphones:
aplay -D plughw:CARD=Headphones,DEV=0 test.wav
which repeats my testing words back to me. So far, so good !
IMPORTANT: If you didn’t get to hear your test, you must get this working before continuing. If there are problems
- as a first step try a different speaker device by changing
-D <device>
- some devices (like the reSpeaker HATs) require a driver to be installed first
- If you are using Docker, you may need to allow Docker to access the audio device(s)
- getting an audio device working is pretty basic linux stuff - not a Home Assistant or Voice Assistant problem - so you are likely to get better answers if you ask for help in the support or forum for your specific device.
Running the Satellite
As in the previous section, change the device names for your microphone and speaker. It may be useful now to set the name you want this satellite to show as. In my case,
script/run --debug --name 'HA-voice-2' \ --uri 'tcp://0.0.0.0:10700' \
--mic-command 'arecord -D plughw:CARD=ABTWPDQ0222M,DEV=0 -r 16000 -c 1 -f S16_LE -t raw' \
--snd-command 'aplay -D plughw:CARD=Headphones,DEV=0 -r 22050 -c 1 -f S16_LE -t raw'
In my case I got several DEBUG: lines displayed, ending with:
DEBUG:root:Detected IP: 192.168.1.85
DEBUG:root:Zeroconf discovery enabled (name=b827ebd38289, host=None)
DEBUG:root:Connecting to mic service: ['arecord', '-D', 'plughw:CARD=ABTWPDQ0222M,DEV=0', '-r', '16000', '-c', '1', '-f', 'S16_LE', '-t', 'raw']
DEBUG:root:Connecting to snd service: ['aplay', '-D', 'plughw:CARD=Headphones,DEV=0', '-r', '22050', '-c', '1', '-f', 'S16_LE', '-t', 'raw']
INFO:root:Connected to services
Recording raw data 'stdin' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
DEBUG:root:Connected to mic service
Going to my web browser and Home Assistant page, and I see that there is already a notification, that a new device was detected … Click [Configure], select an area - and there it is in Integrations under “Wyoming Protocol”.
You should setup your Voice Assistant pipeline if you haven’t already; and Restart Home Assistant.
And as predicted, back on the RasPi satellite, the display now shows
INFO:root:Streaming audio
THAT’S IT ! READY TO TEST.
Note that this assumes Wyoming, openwakeword, and a Voice Assist pipeline have already been installed and setup on your HA server.
My test was successful, though I am used to sounds to indicate when the voice assistant has detected wakeword, and when it has completed its processing. Fortunately these are easy to add. You should remember that you proved the installation was successful by running “script/run --help” - which spewed out a lot of text. That is the help file, and includes
--awake-wav AWAKE_WAV
WAV file to play when wake word is detected
--done-wav DONE_WAV WAV file to play when voice command is done
Wyoming-satellite already includes a couple of sounds we can use, so it’s just a matter of adding the arguments to your command …
Press CTRL-C to interrupt the wyoming-satellite program currently running; press the up-arrow key to repeat the last command, add " --awake-wav sounds/awake.wav --done-wav sounds/done.wav", and press [Enter] to run the modified command.
Me: “OK Nabu”
VA: trill sound
Me: “Turn on study light”
VA: chirp
VA: “Turned on light”
In Home Assistant, on my HA-voice-2 device page under Wyoming Protocol under Integrations the “Assist in progress” indicator changed to “on” during the exchange - but of more interest, over on the satellite the console now displays:
INFO:root:Streaming audio
DEBUG:root:Wake word detected
DEBUG:root:Connected to snd service
Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
DEBUG:root:Event(type='transcript', data={'text': 'Turn on study light.'}, payload=None)
INFO:root:Streaming audio
DEBUG:root:Connected to snd service
Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
DEBUG:root:Event(type='synthesize', data={'text': 'Turned on light', 'voice': {'name': 'NatashaNeural'}}, payload=None)
DEBUG:root:Connected to snd service
Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
which shows the transcript of what it thought you said.
Create Services
Currently we will have to go back to the satellite and run the command whenever the satellite reboots - but by running it as a service in linux it can automatically start up whenever the RasPi is booted. Also, the service runs in the background, so we can use the console (or SSH session) to do other things. AND the service is automatically restarted if it crashes ! Magic !
You may need to modify the ExecStart line to match the command you were running from the console - ie with the correct devices and the awake and done sounds. Note also that since the service is started by the linux Operating System before you log on, it needs to know exactly where to find the script and files - in /home/pi/wyoming-satellite
That’s basically it ! You have a working RasPi Voice Assist satellite - GO YOU !!!