Has anyone gotten Bitvoicer to work with the Adafruit Wave S

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
isaace
 
Posts: 48
Joined: Mon Sep 08, 2014 11:18 pm

Has anyone gotten Bitvoicer to work with the Adafruit Wave S

Post by isaace »

I have used Bitvoicer (voice recognition library and interface) for a little over a year now on simple Arduino projects. I am not much of a programmer and I am (rather clumsily) trying to use some Bitvoicer sample sketch with the 6 button Adafruit wav shield sample sketch found here: https://learn.adafruit.com/system/asset ... ce.pde.txt.

I can use each sketch independently of the other, so I know that Bitvoicer works and the wav shield works. I am using the microphone on my laptop and the bitvoicer software interface. It isn't until I try to merge the two (I want to talk to my Arduino and have it reply with prerecorded responses) that I have problems. The problem I am facing is that once I compile the code and upload it to my Arduino Uno, (does not show any errors) the button does not work, and the commands that Bitvoicer sends don't seem to work either. I just tested Bitvoicer with an old project I did last year and it works fine. I also tested the wav shield with the 6 button sketch mentioned above and that works fine.

Now I am just saying "hello" to Bitvoicer and trying to get the Wav Shield to play a hello.wav file in response.

I posted the code that I am working with. I left as many comments from the original writers as possible.

Isaac

Code: Select all

#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"
#include <BitVoicer11.h>

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

SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f;      // This holds the information for the file we're play

WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

#define DEBOUNCE 5  // button debouncer

// here is where we define the buttons that we'll use. button "1" is the first, button "6" is the 6th, etc
byte buttons[] = {14, 15, 16, 17, 18, 19};
// This handy macro lets us determine how big the array up above is, by checking the size
#define NUMBUTTONS sizeof(buttons)
// we will track if a button is just pressed, just released, or 'pressed' (the current state
volatile byte pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];

// this handy function will return the number of bytes currently free in RAM, great for debugging!   
int freeRam(void)
{
  extern int  __bss_end; 
  extern int  *__brkval; 
  int free_memory; 
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end); 
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval); 
  }
  return free_memory; 
} 

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}

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(1);
  //Starts serial communication at 115200 bps//  Serial.begin(9600);  
  Serial.begin(115200);  //Sets up the pinModes
  
  
  byte i;
  
  // set up serial port
  Serial.begin(9600);
  putstring_nl("WaveHC with ");
  Serial.print(NUMBUTTONS, DEC);
  putstring_nl("buttons");
  
  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam());      // if this is under 150 bytes it may spell trouble!
  
  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
 
  // pin13 LED
  pinMode(13, OUTPUT);
 
  // Make input & enable pull-up resistors on switch pins
  for (i=0; i< NUMBUTTONS; i++) {
    pinMode(buttons[i], INPUT);
    digitalWrite(buttons[i], HIGH);
  }
  
  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!)  
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
  }
  
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
// Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part)) 
      break;                             // we found one, lets bail
  }
  if (part == 5) {                       // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }
  
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?
  
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }
  
  // Whew! We got past the tough parts.
  putstring_nl("Ready!");
  
  TCCR2A = 0;
  TCCR2B = 1<<CS22 | 1<<CS21 | 1<<CS20;

  //Timer2 Overflow Interrupt Enable
  TIMSK2 |= 1<<TOIE2;


}

SIGNAL(TIMER2_OVF_vect) {
  check_switches();
}

void check_switches()
{
  static byte previousstate[NUMBUTTONS];
  static byte currentstate[NUMBUTTONS];
  byte index;

  for (index = 0; index < NUMBUTTONS; index++) {
    currentstate[index] = digitalRead(buttons[index]);   // read the button
    
    /*     
    Serial.print(index, DEC);
    Serial.print(": cstate=");
    Serial.print(currentstate[index], DEC);
    Serial.print(", pstate=");
    Serial.print(previousstate[index], DEC);
    Serial.print(", press=");
    */
    
    if (currentstate[index] == previousstate[index]) {
      if ((pressed[index] == LOW) && (currentstate[index] == LOW)) {
          // just pressed
          justpressed[index] = 1;
      }
      else if ((pressed[index] == HIGH) && (currentstate[index] == HIGH)) {
          // just released
          justreleased[index] = 1;
      }
      pressed[index] = !currentstate[index];  // remember, digital HIGH means NOT pressed
    }
    //Serial.println(pressed[index], DEC);
    previousstate[index] = currentstate[index];   // keep a running tally of the buttons
  }
}


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.BANNED(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.BANNED(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 == "hello")
  
  
  
  byte i;
  
  if (justpressed[0]) {
      justpressed[0] = 0;
      playcomplete("Hello.WAV");
  }
  if (justpressed[1]) {
      justpressed[1] = 0;
      playcomplete("RE.WAV");
  }
  if (justpressed[2]) {
      justpressed[2] = 0;
      playcomplete("MI.WAV");
  }
  if (justpressed[3]) {
      justpressed[3] = 0;
      playcomplete("FA.WAV");
  } 
  if (justpressed[4]) {
      justpressed[4] = 0;
      playcomplete("SO.WAV");
  } 
  if (justpressed[5]) {
      justpressed[5] = 0;
      playcomplete("LA.WAV");
  }
}



// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
  // call our helper to find and play this name
  playfile(name);
  while (wave.isplaying) {
  // do nothing while its playing
  }
  // now its done playing
}

void playfile(char *name) {
  // see if the wave object is currently doing something
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file "); Serial.print(name); return;
  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  }
  
  // ok time to play! start playback
  wave.play();
}

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: Has anyone gotten Bitvoicer to work with the Adafruit Wa

Post by pburgess »

Any idea what the memory requirements of Bitvoicer are like? Anything using the Wave Shield is pretty intensive, and might leave only 500-ish bytes free for other libraries and the sketch's own needs. If you're using a mic on the Arduino (rather than the PC side), I suspect this won't fit.

User avatar
isaace
 
Posts: 48
Joined: Mon Sep 08, 2014 11:18 pm

Re: Has anyone gotten Bitvoicer to work with the Adafruit Wa

Post by isaace »

This is the response that I received from BitSofia:

"Most of the functions in our Arduino library would use up to 184 bytes at running time. However, if you use the function sendToBV(String s), memory usage will vary based on the size of the String object."

User avatar
isaace
 
Posts: 48
Joined: Mon Sep 08, 2014 11:18 pm

Re: Has anyone gotten Bitvoicer to work with the Adafruit Wa

Post by isaace »

Ok, an engineer at work helped me fix it.

The problem was this: The reference to the 9600 baud rate should be removed. It conflicts with the 115200 baud rate needed for the Bitvoicer serial connection. I thought I removed it earlier, but I overlooked that one. Sometimes a second set of eyes can really help.

If you choose to use this code, remember that the button needs to be depressed while you talk to the Arduino through the Bitvoicer interface software. If you don't want buttons, then remove or comment out the button code. You can use the free AT&T text to speech software to get a fairly realistic human - robotish voice.

It works! Now I can talk to my Arduino and my Arduino will respond in a robot voice.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”