speech recognition over LAN network

Hey Guys!

I'm a bit new to the arduino, and this forum (this is my first post). I have to say I've been absulutly loving it! I have hit
a bump however in one of my projects and was wondering if you guys could help. For my current project, I copied some of the code from the bitvoicer and LEDs project and slightly modified it to work for a few things around my house such as a light I soldered, my server/pc, and my 3d printer. That was great but now I have this usb cord plugged into my computer all the time, so after doing a bit of research I discovered I could send bitvoicer serial over my LAN network. This is where I'm stuck. I purchased the Ethernet shield today at my Radio Shack but can't figure out how to write the code to run communication to my laptop over my LAN network. Here's my current code:

#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 pc = 12;
int light = 11;
int lightBrightness = 250;
int lightFade = 50;
int printer = 9;
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(pc, OUTPUT);
  pinMode(light, OUTPUT);
  pinMode(printer, 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()
{
  // turns pc on (press power button)
  if (bvSerial.strData == "pcHIGH")
  { 
    digitalWrite(pc, HIGH);
    delay(200);
    digitalWrite(pc, LOW);
    delay(200);
    digitalWrite(pc, HIGH);
  }
  //turns pc off (hold power button)
  else if (bvSerial.strData == "pcKILL")
  {
    digitalWrite(pc, LOW);
  }
  //turn pc off(press button)
  else if (bvSerial.strData == "pcLOW")
  {
    digitalWrite(pc, LOW);
    delay(500);
    digitalWrite(pc, HIGH);
  }
  //turns light on
  else if (bvSerial.strData == "lightHIGH")
  {
    digitalWrite(light, HIGH);
    lightBrightness = 250;
  }
  //turns light off
  else if (bvSerial.strData == "lightLOW")
  {
    digitalWrite(light, LOW);
  }
  //dims light
  else if (bvSerial.strData == "lightD")
  {
    lightBrightness = lightBrightness - lightFade;
    analogWrite(light, lightBrightness);
  }
  //brightens light
  else if (bvSerial.strData == "lightB")
  {
    lightBrightness = lightBrightness + lightFade;
    analogWrite(light, lightBrightness);
  }
  //turns printer relay on
  else if (bvSerial.strData == "printerHIGH")
  {
    digitalWrite(printer, HIGH);
  }
  //turns printer relay off
  else if (bvSerial.strData == "printerLOW")
  {
    digitalWrite(printer, LOW);
  }

}

Thanks guys! Happy Programing!

What is going to be running on the PC at the far end of the LAN, and receiving this 'bitvoicer serial' stream? That will determine the protocol used and what you need to do to implement the Arduino part of that protocol.

The program currently runs like this, the bitvoicer software on my computer recognizes my speech, then sends a serial code over the usb to the arduino, then the arduino executes the command to that code. What I want to do is to run this through my wifi router so I don't have to have the usb plugged into my laptop, as long as I'm connected to my wifi router. The plan is to use the Ethernet shield to plug my arduino into my router.

Thanks for the help!

  • calm8809

I understand that your 'bitvoicer' PC application sends data to the Arduino via a serial connection and you want it to be sent over a network connection instead. In principle that's possible. I'm not familiar with bitvoicer. Is it an application supplied by somebody else? Does it have the capability to send it's "serial code" over a network connection? If so, what network protocol does it use for that?

If this has to be done without any support from bitvoicer and without changing anything there then it may be possible to set up a loopback connection between a virtual serial port and a network socket using something like PuTTY, but that would be a last resort rather than a first choice.

bitvoicer is a third party program that can be used with arduino and gives me the option of using TCP or IP communication.

Sounds promising. How does the TCP support work? (Does Bitvoicer initiate the connect or expect an incoming connection? Is the network protocol just a text stream over a raw TCP socket connection, or is there more to it?)

I believe bitvoicer initiates contact, because after startup it says "ERROR: unable to establish ip connection". All I have to do in the preferences for this setting is enter the ip address (I entered the ip my router gave "192.168..") and the port (I put 80). The way I have it set up is when bitvoicer recognizes a sentence or word, it will send a specified string code, which the arduino prosesses.

In that case it should be easy to implement. On the Arduino side you need to open a server socket and wait for incoming connections. Look for examples of Arduino based web servers to see what's involved in starting up the Ethernet interface using either DHCP or a static IP address, and opening a listening socket. You will need to decide which TCP port you are going to listen on. That might be specified by bitvoicer, or might be free for you to choose.

You sketch will accept the incoming connection requests and read bytes from the connected socket until the message is complete. I guess you already have logic in place to handle bytes received from a serial port and handling bytes received over a TCP connection would be essentially the same.

Once you have it working, you will need to figure out how the connection will be closed. Probably, bitvoicer will close the connection for you, and when the client closes the connection you need to close the associated socket - just as you'll see done in the web server examples.

ok, thanks for your help!

For those using BitVoicer Server, I'd like to say that the TCP connection works the other way aroung. BitVoicer Server uses a TCP/IP listener to accept incoming connections. In this case, you have to start a TCP connection from the client.