Skip to content

Voice controlled LED

Arjo Chakravarty edited this page Dec 27, 2013 · 7 revisions

Introduction

In this tutorial we are going to build a simple voice controlled energy that turns on and off when you say "on" and "off". The tutorial assumes you know the arduino language.

The hardware

This tutorial was done on an arduino UNO. Stick an LED into pin 13 and ground the negative lead. Any microphone with pre-amp plugged in should work just fine.

The software

The code can be found in the examples folder. A full listing is given here.



#include <uspeech.h>
#define led 13
signal voice(A0);
char prev;
boolean newline=false;
int sum = 0;
void setup(){
  voice.f_enabled = true;
  //Calibrate these values.
  voice.minVolume = 1500;
  voice.fconstant = 400;
  voice.econstant = 1;
  voice.aconstant = 2;
  voice.vconstant = 3;
  voice.shconstant = 4;
  voice.calibrate();
  Serial.begin(9600);
  pinMode(led, OUTPUT); 
}
void loop(){
    char p = voice.getPhoneme();
    if(p!=' '){
      if(p=='f'){
          newline = true;
      }
      else{
          newline = false;
      }
    }
    else{
      if(newline){
        digitalWrite(led, LOW);
      }
      else{
        digitalWrite(led, HIGH);
      }
    }
}

#Line by line explanation

#include <uspeech.h>

This line imports the µSpeech library into your arduino sketch.

signal voice(A0);

This line creates a new µspeech signal object. The signal object is where all of µspeech's logic resides.

voice.calibrate();

This line calibrates the voice object so as to remove noise and interference from the system.

char p = voice.getPhoneme();

This returns the closest phoneme guess to the real phoneme, if it is too quiet the system will return ' ' and 'm' if there was an error. The rest of the code goes on to tell if there was the "sh" sound in the word, if there was its time to turn off the LED, if there wasn't it means the person said "on".