Before getting started, let's review what you'll need.
- Raspberry Pi 3 or 4.
- MATRIX Voice or MATRIXCreator - Raspberry Pi does not have a built-in microphone, the MATRIX Voice&MATRIXCreator each have an 8 mic array - Buy MATRIX Voice or Buy MATRIX Creator.
- Micro-USB power adapter for Raspberry Pi.
- Micro SD Card (Minimum 8 GB) - An operating system is required to get started. You can download Raspbian and use the guides for Mac OS, Linux. and Windows on the Raspberry Pi website.
- A USB Keyboard & Mouse, and an external HDMI Monitor - we also recommend having a USB keyboard and mouse as well as an HDMI monitor handy. You can also use the Raspberry Pi remotely, see this guide from Google.
- Internet connection (Ethernet or WiFi)
This guide assumes that you've read & followed our previous guide: Rhasspy Voice Assistant on MATRIX Voice and MATRIX Creator. Aside from MATRIX specific steps, anyone can still follow along to get a better understanding of handling custom intents for Rhasspy.
Let's Get StartedThe scope of this guide will cover how to create and listen to custom intents for the Rhasspy voice assistant. Most of the information covered here can be found on the official documentation for Rhasspy.
Installing MATRIX Lite JSTo program your MATRIX device, you'll need to install MATRIX Lite. We'll be using the JavaScript version for this guide.
SSH into your Raspberry Pi and install the following:
Understanding Sentences (Intents)Open your Rhasspy's web interface by opening your browser to http://YOUR_PI_IP_HERE:12101 and then click on the Sentences tab. Here is where all Intents and sentences are defined.
By default, there are a few example sentences ready for use. The bottom of the page explains the rules on how they're created.
Sentences shouldn't contain non-words characters like commas and periods. Optional words are [bracketed]. Alternatives are (separated | by | pipes). Rules have an = after their name, optionally contain {tags}, and are referenced <by_name>.
Each intent holds a number of sentences and rules that allow for multiple ways of invoking it. Below are a few examples of how this works.
- Training Documentation (more in-depth explanation)
## General Sentence Examples. Only meant to highlight different features.
## Refer to the official documentation for a list of all sentence features.
[SimpleIntent] # intent name
# 3 simple sentences
set the device to red
set the device blue
set the device green
[AlternativeWords]
# helps avoid writing a sentence to match each possible option
set the device to (red | green | blue)
[OptionalWords]
# allows for diverse phrasing
# "the" and "to" are now optional to say
set [the] device [to] (red | green | blue)
[Rules]
# reusable parts for this/all intents
color = (red | blue | green) # a simple rule
set [the] device [to] <color> # same as the previous sentence in OptionalWords
[NumberRanges]
set [the] device [to] <Rules.color> in (1..10) minutes
[Tags]
# tagged entities will show up in more visibly for JSON events
set [the] device to <Rules.state>{color} in (1..10){mins} minutes
Understanding SlotsAs you may have noticed, storing every possible color with all your sentences can make this interface cluttered and hard to read. This is where the slots come in.
From the web interface, go into the Slots tab.
For any large or generic lists, the slot page allows you to easily include them inside a sentence.
Pretending you've created a slot named color, here's how it can be used in a sentence.
# Example usage of a slot
[SetColor]
set the light to ($color)
The Slots Lists documentation covers this, as well as how to use place individual lists in separate files.
Creating an IntentBefore learning how to listen to intents, we'll need to make one. Go to the sentences page, remove the default intents, and add the following:
[Led]
set [the] device [to] (red | green | blue | purple){color}
Once created, click on SaveSentences and wait for Rhasspy to finish training.
For intent catching, we'll be using Rhasppy's Web Socket API. There are also options to interface with Node-Red and Home Assistant.
To keep things simple, the program to listen for Intents will be on the same Pi with the Rhasspy assistant. We've prepared an easy to follow Node.js template to quickly set this up.
SSH into your Pi and run the following commands:
Install git.
sudo apt-get install git
Download our example repository.
git clone https://github.com/matrix-io/rhasspy-examples
Move into web socket example and install the project dependencies.
cd rhasspy-examples/websocket/matrix_example/node
npm install
Run the program.
node index.js
Testing The IntentYou can now say "Hey Porcupine, set the device to red"!
Once heard, you should receive an output similar to the image below.
You're all set now to start adding skills to your Rhasspy assistant. If you have any questions for us, feel free to us know by leaving a comment on this guide or our community website!
Reacting to a Wake WordThere's currently no WebSocket implementation to listen for wake word events. You can track this feature, along with a few workarounds, in this GitHub issue.
Comments
Please log in or sign up to comment.