In this blog post I will show you how to control some Neopixels using your voice, using one Flip & click, one 4×4 RGB click board and the Speakup click from MikroElektronika.
In my previous story I wrote a bit about using the SpeakUp click in an Arduino environment, focusing on potential problems related to logic levels. Shortly, the SpeakUp click has three pins that are 3.3V only, thus its use with Arduino Uno boards is quite difficult, and you can easily damage your SpeakUp click board.
Initially, I wanted to use a 3.3V Arduino Pro, but that board is 3.3V only, The SpeakUp click will work fine with the Arduino Pro. On the other hand, the 4×4 RGB click needs both 5V (for LED power supply) and 3.3V (for control logic). So, the Arduino Pro won’t work in this project.
I’m left with two possible choices: Arduino Due plus Arduino Mega Click Shield, or the Flip & Click. I close the latter, as it’s a cheaper option.
As usual, it’s just like playing with Lego: 4×4 RGB LED click goes into mikroBUS socket #1, while the SpeakUp click goes into mikroBus socket #2. Simple as this.
But what about software? Well, there are two issues to solve: programming the SpeakUpo click and writing the Arduino code.
Programming the SpeakUp click
The SpeakUp click is programmed using the PC software provided by MikroElektronika. So, download and install the software.
The SpeakUp Firmware uses Dynamic Time Warping (DTW) algorithm — word-based, isolated word, speaker dependent and template matching algorithm:
- in the word based speech recognition the smallest recognition unit is a word;
- in the isolated word recognition, words that are uttered with short pauses are recognized;
- speaker dependent reference patterns are constructed for a single speaker;
- template matching algorithm is a form of pattern recognition. It represents speech data as sets of feature/parameter vectors called templates. Each word or phrase in an application is stored as a separate template. The input speech is then compared with stored templates and the stored template most closely matching the incoming speech pattern is identified as the input word or phrase.
Before going into programming, one must choose the command words. Try to choose words that are as dissimilar to each other as possible, thus increasing the chance of a good recognition. My commands are “white”, “red”, “green”, “blue”, “brighter”, “dimmer”, and “turn off”. Note that I don’t use bright as it’s just too similar with white.
Once you connect the SpeakUp click it will perform ambient noise detection. This takes about 20 seconds, during which the SpeakUp click will appear unresponsive. Just give it enough time and it will start.
Next, we create a new project and we go to Settings. My settings are: Acceptance threshold = 50; Recording timeout = 5s; Word length = 1.5; Noise Level = Auto; Notify mater = UART; Data rate = 9600 baud.
The next step is to record the commands. Keep the SpeakUp click close to your mouth (5–6 cm works fine) and speak loudly and clear. Listen to the recorded voice and record it again if the level is too low of it’s not clear.
Note that the DTW algorithm used by the SpeakUp click is speaker-specific. If you have multiple users, you have to record the same command for each speaker. Thus, a command can have multiple numeric indices. This can be later solved in the Arduino code.
Once everything is fine, save your project, upload the code to the SpeakUp click and export the constants. This latter step creates a .c file with the numeric correspondence of each command.
This file is generated by SpeakUp Software. It containts voice commands constants.
Creation date: 5/30/2017
Creation time: 10:08:22 AM
Length: 1.5 s
const VCMD_WHITE = 0;
Length: 1.5 s
const VCMD_RED = 1;
SpeakUp Arduino code
Now that we have programmed our SpeakUp click we can go to the Arduino code. I used Arduino IDE v.1.8.1, with the latest version of Adafruit Neopixel library (1.1.1) — this is important, older versions of the Neopixel library don’t work with the Due.
The code uses Serial2 for the SpeakUp click and Serial for debugging. For unknown reasons I wasn’t able to make it work with Serial1. I assume there’s a cold joint somewhere or something…
The code pulls the RST pin of the SpeakUp click low for just one millisecond. Then it waits for the SpeakUp click to come online. When the SpeakUp click comes online it sends the string “READY” over the UART. No termination, just the READY string. So, I wait for five characters to gather in the serial buffer, then I read those and compared against the expected string.
Then we go into normal mode. Although the SpeakUp can recognize some 200 commands, the index sent over the UART is two bytes. This complicates things a little bit, as I have to wait for two bites to gather in the serial buffer, then read them and parse them into commands.
That’s all! Of course, if you have any questions there’s always the comment form below 🙂
Originally published at https://electronza.com on May 30, 2017. Moved to Medium on May 6, 2020.