Home‎ > ‎DroidBuilder's Tutorials‎ > ‎

Programming the RoboVoice Shield

Thanks to its text-to-speech capability the RoboVoice Shield / Break-Out kit is easily programmed to say just about anything you want it to

A simple Arduino sketch using the RoboVoice Shield  looks like this:

Arduino code

/* SP0-512 singtest.ino sketch
 created 12/20/2012
 by Galen Raben
 
 This example code is in the public domain.
 
 http://www.droidbuilder.com
 
 Tested on Arduino 1.0.1
*/

//set up a SoftwareSerial port for SP0-512 RoboVoice Shield
//rxPin: the pin on which to receive serial data from SP0-512 (TX of SP0-512)
//txPin: the pin on which to transmit serial data to the SP0-512 (RX of SP0-512)
//spkPin: the pin on which the SP0-512 indicates it is speaking (goes hi when speaking)
#include <SoftwareSerial.h>
#define rxPin 5 // not implemented in this example
#define txPin 6
#define spkPin 7

SoftwareSerial Speak(rxPin, txPin);

void setup(){
  // initialize the serial communications with the SP0512
  Speak.begin(9600);// set the data rate for the SoftwareSerial port
  delay(250); // wait quarter second for resets to finish (speaks "ready")
}

void loop()
{
  Speak.println("[G2]This [A2]is [B2]a [D3]test"); // send text to be spoken/sung to the SP0512
  delay(3000);
}

void waitspeak() // function to wait for 512 to finish speaking
{
  delay(100); // pause 0.1 sec for speaking line to go high
  while(digitalRead(spkPin)) // wait until 512's busy line goes low
  delay (100); // pause 0.1 second after speaking line goes low
}

You can copy and paste this code into your Arduino editor and upload it to hear your RoboVoice sing "This a test" forever - or at least until you get tired of it and unplug it. :-) You can also download it from the bottom of this page.

The details of this sketch are as follows...
At the top of the sketch you will find the following line:
    #include <SoftwareSerial.h>    // this loads in the SotwareSerial library we will use to communicate with the RoboVoice IC.
The following three  lines define the pins we use to communicate with the RoboVoice IC:
    #define rxPin 5    // the pin on which to receive serial data from SP0-512 (TX of SP0-512) - this pin is not really implemented in most examples
    #define txPin 6    // the pin on which to transmit serial data to the SP0-512 (RX of SP0-512)
    #define spkPin 7    // the pin on which the SP0-512 indicates it is speaking (goes hi while speaking)

    SoftwareSerial Speak(rxPin, txPin);    // this instantiates the SoftwareSerial port object  we use to communicate with the RoboVoice IC.

In the Setup section of the sketch we setup the communication speed with which to communicate with the RoboVoice IC:
    Speak.begin(9600);// set the data rate for the SoftwareSerial port

You will note that we set this to 9600 baud (ie 9600 characters per second). This is the rate expected by the RoboVoice IC.
I ususally throw in a 1/4 second delay after setting the data rate to give the RoboVoice IC time to say "REady", which you will probably notice it says many times after you first plug your Arduino USB cable into your PC or Mac.

In the main loop section of our sketch I send what I want it to say:

    Speak.println("This is a test"); // send text to be spoken/sung to the SP0512

If I also add some RoboVoice commands in my speech text line using [] to tell the RoboVoice IC what pitch to sing the word out in (more details on on programming the RoboVoice IC itself can be found at http://www.speechchips.com/downloads/SP0-512-Datasheet.pdf ).

    Speak.println("[G2]This [A2]is [B2]a [D3]test"); // send text to be spoken/sung to the SP0512

See! Getting it to sing is very E-A-S-Y!

To hear the only sound effect included in the RoboVoice, you can also replace with line above with 

    Speak.println("[BEEP]"); // send text to be spoken/sung to the SP0512

The final line of importance is this:
      waitspeak();

This calls a function we use to wait while the RoboVoice is speaking. You could also simply tell the Arduino to wait using a delay function like delay(2500); The actual value you use for the delay would have to be found by experimentation - whereas if you use the waitspeak() function as shown, the wait is calculated on the fly. You will note the other examples attached to the bottom of this tutorial that both methods are used.

This is the definintion of the actual waitspeak function:
    void waitspeak() // function to wait for 512 to finish speaking
    {
      delay(100); // pause 0.1 sec for speaking line to go high
      while(digitalRead(spkPin)) // wait until 512's busy line goes low
      delay (100); // pause 0.1 second after speaking line goes low
    }

Programming the RoboVoice Shield/Break-Out on the Stamp BS2:
A simple program using the RoboVoice Shield /Break-Out looks like this:

Stamp BS2 code

' {$STAMP BS2}
' {$PBASIC 2.5}
' BS2 DAISY for SP0-512 chip
serStr VAR Byte(16)
serStr(15) = 0

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T9600       CON     84
  #CASE BS2SX, BS2P
    T9600       CON     240
#ENDSELECT
INPUT 7 ' speaking line from 512
OUTPUT 6 ' 9600 true 8N1 data to 512
PAUSE 1000
SEROUT 6,84,[CR] 'initialize SPO-512
GOSUB waitspeak

main:
  SEROUT 6,84,["[G2]This [A2]is [B2]a [D3]test",CR]
  PAUSE 3000
  GOTO main

  waitspeak: ' wait subroutine
  PAUSE 100  ' wait 0.1 sec for speaking line to go high
  test: IF IN8=1 THEN test  ' wait until speaking line goes low
  PAUSE 100      ' wait 0.1 sec agter speaking line goes low
  RETURN

You can copy and paste this code into your Stamp editor and upload it to hear your RoboVoice sing "This a test" forever - or at least until you get tired of it and unplug it. :-) You can also download it from the bottom of this page.

The details of this code are as follows...
Near the top of the sketch you will find the following lines:
#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T9600       CON     84
  #CASE BS2SX, BS2P
    T9600       CON     240
#ENDSELECT
These are used to determine which version of the Stamp the code is being compiled for. Which is used is determined by which button you pressed in the Stamp Editor to start the compile and run.

The following line determines which pins are used for communication to the RoboVoice and set the proper data rate , the first number is the pin number, the second number is the baud mode (which in this case is 9600 characters per second (see the Stamp Editor Help for definitions of the baudmode):
  SEROUT 6,84,

In section of our command I send what I want it to say followed by a carriage return.:
["This is a test",CR]  'send text to be spoken/sung to the SP0512

If I also add some RoboVoice commands in my speech text line using [] to tell the RoboVoice IC what pitch to sing the word out in (more details on on programming the RoboVoice IC itself can be found at http://www.speechchips.com/downloads/SP0-512-Datasheet.pdf ).
["[G2]This [A2]is [B2]a [D3]test",CR]  'send text to be spoken/sung to the SP0512

See! Getting it to sing is very E-A-S-Y!
To hear the only sound effect included in the RoboVoice, you can also replace with line above with 

["[BEEP]",CR]  'send text to be spoken/sung to the SP0512

The final line of importance is this (although not used in this example):
      waitspeak();

This calls a function we use to wait while the RoboVoice is speaking. You could also simply tell the Arduino to wait using a delay function like delay(2500); The actual value you use for the delay would have to be found by experimentation - whereas if you use the waitspeak() function as shown, the wait is calculated on the fly. You will note the other examples attached to the bottom of this tutorial that both methods are used.

This is the definintion of the actual waitspeak function:
  waitspeak: ' wait subroutine
  PAUSE 100  ' wait 0.1 sec for speaking line to go high
  test: IF IN8=1 THEN test  ' wait until speaking line goes low
  PAUSE 100      ' wait 0.1 sec agter speaking line goes low
  RETURN

More examples are attached at the bottom of this page, more examples for other Microcontrollers will be written as I find time.


RoboVoice Shield Break-Out by Galen Raben is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
Permissions beyond the scope of this license may be available at email DroidBuilder.com

The example softwares on this page are released into the public domain and are as-is. No statement is made as to whether they will even function or are suitable for any purpose whatsoever. What you make of them (or make from them) is up to you...
Copyright ©2012 Galen Raben / DroidBuilder.com
ċ
DaisyDemo.bs2
(1k)
Galen Raben,
Jan 28, 2013, 12:25 AM
ċ
RowRowRowDemo.bs2
(1k)
Galen Raben,
Jan 27, 2013, 11:34 PM
ċ
RowRowRowDemo.ino
(1k)
Galen Raben,
Dec 20, 2012, 1:10 PM
ċ
daisy_bell.ino
(2k)
Galen Raben,
Dec 20, 2012, 1:10 PM
ċ
singtest.bs2
(1k)
Galen Raben,
Jan 28, 2013, 12:26 AM
ċ
singtest.ino
(1k)
Galen Raben,
Dec 20, 2012, 2:13 PM
Comments