Offline Voice AI on Arduino
Did you know it’s now possible to perform high-accuracy speech recognition on a microcontroller? Advances in machine learning have brought voice capability to these extremely resource-constrained devices, via the Picovoice SDK. Arduino recently joined the list of supported devices, starting with the Arduino Nano 33 BLE Sense. We’re going to add a voice assistant loop to this board and demonstrate how you can easily customize it to make your Arduino understand naturally-spoken phrases of your own design.
The Picovoice SDK is able to infer a user’s intent from a naturally spoken utterance such as:
“Picovoice, make the blue light blink ten times quickly.”
Picovoice detects the wake word (“Picovoice”), then determines the intent from the follow-on spoken command (“make the blue lights blink ten times quickly”):
{
“intent”: “blinkLight”,
“slots”: {
“color”: “blue”
“Iteration”: “10”
“speed”: “quickly”
}
}
Let’s start with a demo project that controls the Arduino’s on-board LEDs, using voice commands.
I have shared the source code here, so you can try it yourself:
- Download the project (both
Control_LED_Picovoice.in
andparam.h
). - Open the Library Manager in the Arduino IDE, search for the
Picovoice
package, and click on the Install button. - Sign up for Picovoice Console to get your AccessKey for free. We will need an AccessKey to use the
Picovoice
package. - Open the downloaded sketch, and replace the placeholder with your AccessKey:
static const char* ACCESS_KEY = "${YOUR_ACCESSKEY}"; // AccessKey string obtained from Picovoice Console (https://picovoice.ai/console/)
- Upload it into the board.
- Open the serial monitor. You will see the grammar for the context, describing all of the follow-on voice commands it understands.
- Say, for example:
“Picovoice, make red flash”
Build your own Sketch
Create a custom context model
Go to Picovoice Console, an online tool for easily designing and training models for voice interactions that run on the Picovoice SDK. I suggest watching this video tutorial or reading this guide if you want to learn more.
Add the context model to a project
- Replace
CONTEXT_ARRAY
in theparam.h
file with the new context model by following the steps explained in the Picovoice SDK for Arduino documentation. - Update the
inference_callback
so that it takes appropriate actions (e.g., blinking a LED) once an intent is recognized.
Learn more about working with the Picovoice SDK for Arduino by visiting the documentation.