Arduino: Speech control with the EasyVR Shield
Introduction
Recently I’ve found an quite interesting Arduino shield on: https://www.fortebit.tech/speech-recognition/. Using this shield you can control your Arduino using speech commands.
The shield consists of these components: - EasyVR Arduino Shield (includes EasyVR module) - Microphone
On the website you can also find following free software downloads (see link above): - User manual - EasyVR Commander - Arduino Libraries
Following shops sell the EasyVR shield: https://www.fortebit.tech/speech-recognition/ It costs around 40€ or 50$.
Demo
In this demo I control a LED with my voice and the EasyVR shield.
For this demo I also use an Arduino, that has been kindly provided by Farnell.com.
Overview Arduino: https://web.archive.org/web/20260125063429/https://de.farnell.com/arduino Arduino schematic: https://www.arduino.cc/en/uploads/Main/arduino-uno-schematic.pdf Link to product page: https://web.archive.org/web/20260125063429/https://de.farnell.com/arduino/a000046/board-arduino-uno/dp/1848687?ICID=i-9ec8-00001000
Step 1: Software Installation
Install the „EasyVR Commander“ software [Link]. Before you run the software, make sure you run the program with administrator privileges. But don’t start the software at the moment.
Step 2: Prepare hardware
Put the shield and the Arduino together and connect the mic to the shield (J11). Put Jumper J12 at position „PC“. Connect the Arduino to the PC via USB.
Step 3: Train the EasyVR Shield
Now run „EasyVR Commander“ and connect to the serial port of the Arduino USB connection. Click in the group list on Index 0 - Trigger. Add a new command, name it e.g. „ARDUINO“. Then click on „Train Command“. And speak the word „Arduino“ in the mic. And a second time, when the software tells you so.
Click in the group list on Index 1 - Group. Add a new command, name it e.g. „LED_ON“. Then click on „Train Command“. And speak the words „LED on“ in the mic. And a second time, when the software tells you so. And add a second command „LED_OFF“ and train this command as well.
Note: LED_AN is LED_ON and LED_AUS is LED_OFF.
Now your EasyVR is configured. We finally generate some code for the microcontroller inside of the Arduino. In EasyVR Commander click on File->Generate code.
Disconnect your Arduino from USB and change jumper J12 to SW.
Step 4: Some Arduino code
Install the EasyVR Arduino libraries (see first link) to the Arduino IDE library folder.
I slightly altered the previously generated code to control a LED. The LED is connected to pin 11:
#if defined(ARDUINO) && ARDUINO>= 100
#include "Arduino.h"
#include "SoftwareSerial.h"
SoftwareSerial port(12,13);
#else // Arduino 0022 - use modified NewSoftSerial
#include "WProgram.h"
#include "NewSoftSerial.h"
NewSoftSerial port(12,13);#include "EasyVR.h" EasyVR easyvr(port);
//Groups and Commands enum Groups { GROUP_0 = 0, GROUP_1 = 1, };
enum Group0 { G0_ARDUINO = 0, };
enum Group1 { G1_LED_AN = 0, G1_LED_AUS = 1, };
EasyVRBridge bridge;
int8_t group, idx;
void setup() { // bridge mode? if (bridge.check()) { cli(); bridge.loop(0, 1, 12, 13); } // run normally Serial.begin(9600); port.begin(9600);
if (!easyvr.detect()) { Serial.println("EasyVR not detected!"); for (;;); }
easyvr.setPinOutput(EasyVR::IO1, LOW); Serial.println("EasyVR detected!"); easyvr.setTimeout(5); easyvr.setLanguage(3);
group = EasyVR::TRIGGER; //<- start group (customize)
pinMode(11, OUTPUT); digitalWrite(11, LOW); // set the LED off
}
void action();
void loop() { easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)
Serial.print("Say a command in Group "); Serial.println(group); easyvr.recognizeCommand(group);
do { // can do some processing while waiting for a spoken command } while (!easyvr.hasFinished());
easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off
idx = easyvr.getWord(); if (idx>= 0) { // built-in trigger (ROBOT) // group = GROUP_X; = 0) { // print debug message uint8_t train = 0; char name[32]; Serial.print("Command: "); Serial.print(idx); if (easyvr.dumpCommand(group, idx, name, train)) { Serial.print(" = "); Serial.println(name); } else Serial.println(); easyvr.playSound(0, EasyVR::VOL_FULL); // perform some action action(); } else // errors or timeout { if (easyvr.isTimeout()) Serial.println("Timed out, try again..."); int16_t err = easyvr.getError(); if (err>= 0) { Serial.print("Error "); Serial.println(err, HEX); }
group = GROUP_0; } }
void action() { switch (group) { case GROUP_0: switch (idx) { case G0_ARDUINO: // write your action code here group = GROUP_1; //<- or jump to another group X for composite commands break; } break; case GROUP_1: switch (idx) { case G1_LED_AN: // write your action code here group = GROUP_0; //<- or jump to another group X for composite commands
digitalWrite(11, HIGH); // set the LED on
break; case G1_LED_AUS: // write your action code here group = GROUP_0; //<- or jump to another group X for composite commands digitalWrite(11, LOW); // set the LED off
break; } break; } }
Compile and upload this code. Your Arduino should now do something like this: