Offline Voice AI on Arduino

Mohammadreza Rostam
Picovoice
Published in
3 min readJun 14, 2021

--

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”
}
}
Arduino Nano 33 BLE Sense

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:

  1. Download the project (both Control_LED_Picovoice.in and param.h).
  2. Open the Library Manager in the Arduino IDE, search for the Picovoice package, and click on the Install button.
  3. Sign up for Picovoice Console to get your AccessKey for free. We will need an AccessKey to use the Picovoice package.
  4. 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/)
  1. Upload it into the board.
  2. Open the serial monitor. You will see the grammar for the context, describing all of the follow-on voice commands it understands.
  3. Say, for example:

“Picovoice, make red flash”

The demo with multiple speakers

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.

Context Editor

Add the context model to a project

  1. Replace CONTEXT_ARRAY in the param.h file with the new context model by following the steps explained in the Picovoice SDK for Arduino documentation.
  2. Update the inference_callback so that it takes appropriate actions (e.g., blinking a LED) once an intent is recognized.
The logic inside the inference_callback function to address several intents with different slots.

Learn more about working with the Picovoice SDK for Arduino by visiting the documentation.

--

--