Speech Recognition with Arduino and BitVoicer Server

In this Instructable I am going to show how to use an Arduino board and BitVoicer Server to control a few LEDs with voice commands. I will be using the Arduino Micro in this Instructable, but you can use any Arduino board you have at hand.

Speech Recognition with Arduino and BitVoicer Server

The following procedures will be executed to transform voice commands into LED activity:

  1. Audio waves will be captured and amplified by the Sparkfun Electret Breakout board;
  2. The amplified signal will be digitalized and buffered in the Arduino using its analog-to-digital converter (ADC);
  3. The audio samples will be streamed to BitVoicer Server using the Arduino serial port;
  4. BitVoicer Server will process the audio stream and recognize the speech it contains;
  5. The recognized speech will be mapped to predefined commands that will be sent back to the Arduino;
  6. The Arduino will identify the commands and perform the appropriate action.

The video above shows the final result of this Instructable. Note in the video that BitVoicer Server also provides synthesized speech feedback. This speech feedback is defined in the server and reproduced by the server audio adapter, but the synthesized audio could also be sent to the Arduino and reproduced using a digital-to-analog converter (DAC). In my next post, I am going to show how to use the Arduino DUE, one amplifier and one speaker to reproduce the synthesized speech using the Arduino itself.

List of Materials:

Step 1: Wiring

The first step is to wire the Arduino and the breadboard with the components as shown in the pictures above.

The most important detail here refers to the analog reference provided to the Arduino ADC. In my tests, I got better results using 3.3V with the Sparkfun Electrect Breakout. That is why I added a jumper between the 3.3V pin and the AREF pin. If you decide to use the analogRead funcion (for any reason) while 3.3V is being applied to the AREF pin, you MUST call analogReference(EXTERNAL) before you use the analogRead function. Otherwise, you will short together the active reference voltage (internally generated) and the AREF pin, possibly damaging the microcontroller on your Arduino board.

Step 2: Uploading the Code to the Arduino

Now you have to upload the code below to your Arduino. You can also download the Arduino sketch from the link at the bottom of the page. Before you upload the code, you must properly install the BitVoicer Server libraries into the Arduino IDE (Importing a .zip Library).

#include <BVSP.h>
#include <BVSMic.h>

// Defines the Arduino pin that will be used to capture audio 

// Defines the LED pins
#define RED_LED_PIN 6
#define YELLOW_LED_PIN 9
#define GREEN_LED_PIN 10

// Defines the constants that will be passed as parameters to 
// the BVSP.begin function
const unsigned long STATUS_REQUEST_TIMEOUT = 1000;
const unsigned long STATUS_REQUEST_INTERVAL = 2000;

// Defines the size of the audio buffer 
const int AUDIO_BUFFER_SIZE = 64;

// Defines the size of the receive buffer
const int RECEIVE_BUFFER_SIZE = 2;

// Initializes a new global instance of the BVSP class 
BVSP bvsp = BVSP();

// Initializes a new global instance of the BVSMic class 
BVSMic bvsm = BVSMic();

// Creates a buffer that will be used to read recorded samples 
// from the BVSMic class 
byte audioBuffer[AUDIO_BUFFER_SIZE];

// Creates a buffer that will be used to read the commands sent
// from BitVoicer Server.
// Byte 0 = pin number
// Byte 1 = pin value
byte receiveBuffer[RECEIVE_BUFFER_SIZE];

void setup() 
  // Sets up the pin modes
  // Starts serial communication at 115200 bps 
  // Sets the Arduino serial port that will be used for 
  // communication, how long it will take before a status request 
  // times out and how often status requests should be sent to 
  // BitVoicer Server. 
  // Defines the function that will handle the frameReceived 
  // event 
  bvsp.frameReceived = BVSP_frameReceived; 
  // Prepares the BVSMic class timer 

void loop() 
  // Checks if the status request interval has elapsed and if it 
  // has, sends a status request to BitVoicer Server 
  // Checks if there is data available at the serial port buffer 
  // and processes its content according to the specifications 
  // of the BitVoicer Server Protocol 

  // Checks if there is one SRE available. If there is one, 
  // starts recording.
  if (bvsp.isSREAvailable()) 
    // If the BVSMic class is not recording, sets up the audio 
    // input and starts recording 
    if (!bvsm.isRecording)
      bvsm.setAudioInput(BVSM_AUDIO_INPUT, EXTERNAL); 

    // Checks if the BVSMic class has available samples 
    if (bvsm.available)
      // Makes sure the inbound mode is STREAM_MODE before 
      // transmitting the stream
      if (bvsp.inboundMode == FRAMED_MODE)
      // Reads the audio samples from the BVSMic class
      int bytesRead = bvsm.read(audioBuffer, AUDIO_BUFFER_SIZE);
      // Sends the audio stream to BitVoicer Server
      bvsp.sendStream(audioBuffer, bytesRead);
    // No SRE is available. If the BVSMic class is recording, 
    // stops it.
    if (bvsm.isRecording)

// Handles the frameReceived event 
void BVSP_frameReceived(byte dataType, int payloadSize) 
  // Checks if the received frame contains binary data
  // 0x07 = Binary data (byte array)
  if (dataType == DATA_TYPE_BINARY)
    // If 2 bytes were received, process the command
    if (bvsp.getReceivedBytes(receiveBuffer, RECEIVE_BUFFER_SIZE) == 
      analogWrite(receiveBuffer[0], receiveBuffer[1]);

This sketch has four major parts:

  • Library references and variable declaration: The first two lines include references to the BVSP and BVSMic libraries. These libraries are provided by BitSophia and can be found in the BitVoicer Server installation folder. The other lines declare constants and variables used throughout the sketch. The BVSP class is used to communicate with BitVoicer Server and the BVSMic class is used to capture and store audio samples.

Read more: Speech Recognition with Arduino and BitVoicer Server

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top