Speech Recognition with BitVoicer, Arduino and a Microphone

In this project I use BitVoicer’s speech recognition features (http://www.bitsophia.com/BitVoicer.aspx), one Arduino board and one electret microphone (SparkFun Electret Microphone Breakout - BOB-12758 - SparkFun Electronics) to control a few LEDs.

This project is similar to the one in my first post (http://arduino.cc/forum/index.php/topic,133051.0.html), but now I use audio streaming to send audio to BitVoicer.

The following fritzing schematic shows how I wired my Arduino board:

I’m also adding a few pictures and a YouTube video of the project running.

Unfortunately, the sketch I wrote for my first post is no longer supported by the new version of BitVoicer. Here is the new sketch:

#include <BitVoicer11.h>

//Instantiates the BitVoicerSerial class
BitVoicerSerial bvSerial = BitVoicerSerial();

//Stores true if the Audio Streaming Calibration tool
//is running
boolean sampleTest = false;
//Stores the data type retrieved by getData()
byte dataType = 0;
//Sets up the pins and default variables
int pinR = 3;
int pinY = 5;
int pinG = 6;
int lightLevel = 0;

void setup()
{
  //Sets the analog reference to external (AREF pin)
  //WARNING!!! If anything is conected to the AREF pin,
  //this function MUST be called first. Otherwise, it will
  //damage the board.
  bvSerial.setAnalogReference(BV_EXTERNAL);
  //Sets up the microcontroller to perform faster analog reads
  //on the specified pin
  bvSerial.setAudioInput(0);
  //Starts serial communication at 115200 bps
  Serial.begin(115200);
  //Sets up the pinModes
  pinMode(pinR, OUTPUT);
  pinMode(pinY, OUTPUT);
  pinMode(pinG, OUTPUT);
}

void loop()
{
  //Captures audio and sends it to BitVoicer if the Audio
  //Streaming Calibration Tool is running
  if (sampleTest == true)
  {
    //The value passed to the function is the time
    //(in microseconds) that the function has to wait before
    //performing the reading. It is used to achieve about
    //8000 readings per second.
    bvSerial.processAudio(46);
  }
  
  //Captures audio and sends it to BitVoicer if the Speech
  //Recognition Engine is running
  if (bvSerial.engineRunning)
  {
    //The value passed to the function is the time
    //(in microseconds) that the function has to wait before
    //performing the reading. It is used to achieve about
    //8000 readings per second.
    bvSerial.processAudio(46);
  }
}

//This function runs every time serial data is available
//in the serial buffer after a loop
void serialEvent()
{
  //Reads the serial buffer and stores the received data type
  dataType = bvSerial.getData();
  
  //Changes the value of sampleTest if the received data was
  //the start/stop sampling command
  if (dataType == BV_COMMAND)
      sampleTest = bvSerial.cmdData;
  
  //Signals BitVoicer's Speech Recognition Engine to start
  //listening to audio streams after the engineRunning status
  //was received
  if (dataType == BV_STATUS && bvSerial.engineRunning == true)
    bvSerial.startStopListening();
  
  //Checks if the data type is the same as the one in the
  //Voice Schema
  if (dataType == BV_STR)
    setLEDs();
}

//Performs the LED changes according to the value in
//bvSerial.strData
void setLEDs()
{
  if (bvSerial.strData == "wake")
  {
    digitalWrite(pinR, LOW);
    digitalWrite(pinY, LOW);
    digitalWrite(pinG, LOW);
    digitalWrite(pinR, HIGH);
    digitalWrite(pinY, HIGH);
    digitalWrite(pinG, HIGH);
    delay(200);
    digitalWrite(pinR, LOW);
    digitalWrite(pinY, LOW);
    digitalWrite(pinG, LOW);
    delay(200);
    digitalWrite(pinR, HIGH);
    digitalWrite(pinY, HIGH);
    digitalWrite(pinG, HIGH);
    delay(200);
    digitalWrite(pinR, LOW);
    digitalWrite(pinY, LOW);
    digitalWrite(pinG, LOW);
    delay(200);
    digitalWrite(pinR, HIGH);
    digitalWrite(pinY, HIGH);
    digitalWrite(pinG, HIGH);
    delay(200);
    digitalWrite(pinR, LOW);
    digitalWrite(pinY, LOW);
    digitalWrite(pinG, LOW);
    lightLevel = 0;
  }
  else if (bvSerial.strData == "sleep")
  {
    digitalWrite(pinR, LOW);
    digitalWrite(pinY, LOW);
    digitalWrite(pinG, LOW);
    digitalWrite(pinR, HIGH);
    digitalWrite(pinY, HIGH);
    digitalWrite(pinG, HIGH);
    delay(200);
    digitalWrite(pinR, LOW);
    digitalWrite(pinY, LOW);
    digitalWrite(pinG, LOW);
    delay(200);
    digitalWrite(pinR, HIGH);
    digitalWrite(pinY, HIGH);
    digitalWrite(pinG, HIGH);
    delay(200);
    digitalWrite(pinR, LOW);
    digitalWrite(pinY, LOW);
    digitalWrite(pinG, LOW);
    lightLevel = 0;
  }
  else if (bvSerial.strData == "RH")
  {
    digitalWrite(pinR, HIGH);
    lightLevel = 255;
  }
  else if (bvSerial.strData == "RL")
  {
    digitalWrite(pinR, LOW);
    lightLevel = 0;
  }
  else if (bvSerial.strData == "YH")
  {
    digitalWrite(pinY, HIGH);
    lightLevel = 255;
  }
  else if (bvSerial.strData == "YL")
  {
    digitalWrite(pinY, LOW);
    lightLevel = 0;
  }
  else if (bvSerial.strData == "GH")
  {
    digitalWrite(pinG, HIGH);
    lightLevel = 255;
  }
  else if (bvSerial.strData == "GL")
  {
    digitalWrite(pinG, LOW);
    lightLevel = 0;
  }
  else if (bvSerial.strData == "ALLON")
  {
    digitalWrite(pinR, HIGH);
    digitalWrite(pinY, HIGH);
    digitalWrite(pinG, HIGH);
    lightLevel = 255;
  }
  else if (bvSerial.strData == "ALLOFF")
  {
    digitalWrite(pinR, LOW);
    digitalWrite(pinY, LOW);
    digitalWrite(pinG, LOW);
    lightLevel = 0;
  }
  else if (bvSerial.strData == "brighter")
  {
    if (lightLevel < 255)
    {
      lightLevel += 85;
      analogWrite(pinR, lightLevel);
      analogWrite(pinY, lightLevel);
      analogWrite(pinG, lightLevel);
    }
  }
  else if (bvSerial.strData == "darker")
  {
    if (lightLevel > 0)
    {
      lightLevel -= 85;
      analogWrite(pinR, lightLevel);
      analogWrite(pinY, lightLevel);
      analogWrite(pinG, lightLevel);
    }
  }
  else
  {
    bvSerial.startStopListening();
    bvSerial.sendToBV("ERROR:" + bvSerial.strData);
    bvSerial.startStopListening();
  }
}

The BitVoicer Voice Schema I used can be downloaded from: http://www.justbuss.xpg.com.br/BitVoicerTest2.zip (you need to have BitVoicer installed to be able open it).

Now I want to control a few things (lights and ceiling fan) at home. Suggestions on how to connect them to the Arduino are very welcome.

I added wireless communication to this project so that the Arduino does not have to be physically connected to the computer. Here is the link to the new project: http://arduino.cc/forum/index.php/topic,140765.0.html

what if i didnt want to use an electret microphone. Would this code work with my computers built in microphone?

brainaly, most of the code will work. You just have to disable some parts of the loop() structure.

What exactly would i have to do, please help :slight_smile:

Great job
I'm looking something like this to control cervos, but I need to do it without a computer, there's possible to control them with a code into arduino? or maybe with a phone?
Any ideas are welcome!
Thanks! :slight_smile:

Can i do the same with Arduino Duemilanove? i mean there is a difference in baud rate you used here.
Will that be okay if i use 9600 as baud rate?

ajayo2, BitVoicer requires at least 8000 samples per second to work properly. Considering each sample as an 8-bit sample, you need to stream 64000 bits/sec to BitVoicer. This will require a baud rate greater than 9600 bps.

I think the duemilanove board is able to achieve the baud rate I used.

Hello,
My name Hasci are new in the Forum so it's my first question that place. I apologize in advance if there are any mistakes in grammar because I use Google translator.
I use the program you mentioned Bitvoicer I really like, I did a project with Arduino interface to control the lights and the TV at home and everything I function very well ..... until it starts to be a bit of mess that as long as you turn the volume all but just the TV or my children converse with each other, me by false positives.
I increased the level of confidence to 86% and here I noticed a significant improvement, but on a bad note that when I give a voice command preset the bitvoicer rejects the command because it unites me
the command with the Sermon on the TV or the children.
In conclusion the help I ask is: if you have advice on how best to approach or another on the preferences page.
Where we are setting confidence - latency - minimum audio level and ....
Having a very lively and noisy you could not set the bitvoicer that, listening to a speech from the TV - from the boys - and to me with my command, accept my command only as good speech?
Thanks accept any your advice hello