Rhasspy Voice Assistant with Node-Red
December 21, 2020
I decided that I wanted a voice assistant, but didn’t want to go with a product like Amazon Echo or Google Home. I don’t like the idea of having a device listening in on my conversations that is not entirely in my control. This is where Rhasspy comes in. Rhasspy is an open source, fully offline set of voice assistant services that can run on a Raspberry Pi. While there is quite a bit more involved in setting everything up compared to a commercial voice assistant, everything is much more customizable and your data is in your control.
I started out running Rhasspy on a Raspberry Pi 4 with 2 GB of ram and a ReSpeaker 6-Mic Circular Array hat. While I was pleased with the performance, I decided to leverage my NUC as a base station. The NUC takes care of speech to text, intent recognition, text to speech, and intent handling. I have a Raspberry Pi serving as a satellite, taking care of care of wake word detection, audio recording, and audio playback.
I am also running Node-Red on the NUC, which is what handles the skills for Rhasspy. Voice commands are handled by Rhasspy as a simple ini file. Below is a simple intent called GetTime. Words in brackets are optional. Words in parenthesis are alternatives, where one is selected at a time. The intent GetTime would thus be recognized with “what is the time” or “what’s the time.” Node-Red processes the intent, gets the current time using JavaScript, and returns it aloud using text to speech.
[GetTime]
(what | what's) [is] the time
Tags are used as variables and are denoted with curly braces. The example below shows the intent for my HUE lights. The tag {brightness_action} can be set to 'turn,' 'dim,' or 'brighten.' The tag {brightness_level} can be set to an integer from 0 to 100. An example phrase that would be recognized for this intent would be, "dim all the lights to 50 percent."
[ChangeLightBrightness]
(turn | dim | brighten){brightness_action} [all] [the] lights [on] [to] (0..100){brightness_level} [percent]
I am able to interact with my HUE lights using the HueMagic node. I was very happy to see this node work considering that I’ve already bought into the HUE ecosystem. My flow can be imported and used as an example using the json here. Just make sure that you have all of the nodes installed that are named in the README file of my Home Assistant Config repository. The repository also has the voice commands that I use saved as “sentences.ini.”
~ JHE