Home‎ > ‎DroidBuilder's Tutorials‎ > ‎

Programming the SpeakJet Shield Basic

Please note:
As of Arduino 1.0 some changes were made to the print function and byte keyword. Therefore some changes are required in the code presented below to get them to run in Arduino 1.0! Lines such as speakJet.print(223, BYTE); need to be changed to speakJet.write(223); (essentially "print" changes to "write"; and "BYTE" is removed). Also note that the .pde extension in the filename has been changed to .ino in Arduino 1.0 (the .pde extension was also used in Processing sketches and the extension changed  in Arduino 1.0 to avoid further confusion)!

Notes for SpeakJet Shield v1.3 or later:
wherever #define txPin 2  appears, change it to #define txPin 6
wherever #define rxPin 3 appears, change it to #define rxPin 5
wherever #define busyPin 4 appears, change it to #define busyPin 7


Without software, the SpeakJet Shield does little more than say "ready" when the reset button is pressed. Below is an example of how to write a talking "Hello World" program, which you can use as a guide to writing your own programs to get your Arduino talking.

Configure the SpeakJet Shield Basic for use:

The photo below shows where the post shunts are pushed onto the board for normal use of the SpeakJet Shield Basic.

SpeakJet Shield Versions 1.0 - 1.2  (Click on photo to enlarge.)

Confirm that the shunts installed during assembly are in the proper positions. A post shunt should already be installed on the two pin header labeled "SJTest" near R3. This puts the SpeakJet into its normal running mode (when the shunt is removed, the SpeakJet is in a self-test mode). For the software examples below to work, this shunt MUST be installed!

A post shunt should be installed on the two pins at the "SJ" labeled side of the three post header near IC2 (the SpeakJet chip). This connects serial communication from digital pin 2 of the Arduino directly to the SpeakJet. The proper position of this  shunt is shown in the photo below.


A post shunt may also be installed to signal either a SpeakJet buffer half-full (BHalf) or SpeakJet busy (Busy) condition to your Arduino. This can be used as a form of flow-control if you need it in your programs. Some programs you write may not need flow control so this shunt may be removed if you desire. For the software examples used on this page, the shunt is plugged onto the two pins at the "Busy" side of the three post header near R3 as shown in the photo below.


Writing Software for the SpeakJet Shield "Basic":

Writing software for the "basic" version of the SpeakJet Shield is a bit more difficult than for the TTS version. The TTS version of the shield has a processor with an internal program that does text-to-speech translation for you. The SpeakJet Shield Basic version does not have this processor; therefore you must put codes in your software that tell the SpeakJet what sounds to make. This is not especially hard to do but if you are a beginning programmer you might find this a bit challenging! The good news here is that, in the Basic version, you have more control over what the speech will sound like.

Note: If you have the TTS version, or upgrade to it later - you can still make use of any software you write for the Basic version. The SpeakJet TTS can be easily configured to behave just like the "Basic" version! Just install the post shunts as directed in the "Configure" step above. By placing the shunt in the SJ side, the text-to-code processor is bypassed. The text-to-code processor chip does not need to be removed.

First things first: You either need the owner's manual for the SpeakJet or download some software to help you with putting the appropriate speech codes together. The SpeakJet manual  is in pdf format, and you can download it from http://www.magnevation.com/pdfs/speakjetusermanual.pdf. Before you can do much of anything useful with the SpeakJet, you need to read the section called  "Allophone Speech Synthesis Primer." In my copy of the manual, this begins on page 12.

You may also want to download and install a program named Phrase-A-Lator and the manual for Phrase-A-Lator. This program has a dictionary of commonly used English words and phrases, and displays the appropriate codes you will need to put into your program for them.

For your first program, use Phrase-A-Lator to create a classic "Hello world". You could also build this by hand from the SpeakJet manual, but I want to get you going fast! I will save that exercise for another tutorial. :-) Once Phrase-A-Lator is started, you will see this dialog box.


Click on the "Phrase Editor" button. The following control panel will pop up.
In it you will see near the bottom that I've already typed in "Hello world!" into the "Say Data" box.


Click on photo for a larger version.

Once you've typed something in to the "Say Data" box, click on the "View Codes" button just to the right of the box. When you click, you will see a dialog box like this.


Press the "Copy to Clipboard" button.

Stack your Arduino and SpeakJet Shield together; connect your stereo headphone (I-Pod ear-buds work great!) or speaker to the SpeakJet Shield headphone jack. Connect power to the Arduino.

Start up the Arduino code editor, and create a sketch like the following. The codes in the clipboard need to be pasted into the script (I highlighted them in yellow, below, so you can see where to paste them).

// SpeakJet HelloWorld sketch (5-4-2010, revised for SJ shield v1.3 1-8-2013)
// a demo showing a minimal sketch for the SpeakJet Basic Shield
// written by Galen Raben / www.droidbuilder.com

// set up a new software serial port
#include <SoftwareSerial.h>
//rxPin: the pin on which to receive serial data
//txPin: the pin on which to transmit serial data
// SpeakJet shield versions 1.0 thru 1.2 uses these pins
//#define txPin 2

//#define rxPin 3
// SpeakJet shield version 1.3 or later uses these pins
#define rxPin 5
#define txPin 6
// set up the SoftwareSerial port to connect to the SpeakJet
SoftwareSerial speakJet = SoftwareSerial(rxPin, txPin);

void setup()
{
  // define pin modes for tx, rx pins:
  // pinMode(rxPin, INPUT); //not needed for this simple demo
  pinMode(txPin, OUTPUT);
  speakJet.begin(9600);
  delay(1000); // wait a second for the Arduino resets to finish (says "ready")

  /* HELLO WORLD SpeakJet MSA phonemes (see page 16 of SpeakJet User Manual)
   20, 96, 21, 114, 22, 88, 23, 5, 183, 7, 159, 146, 164, 147, 151, 145, 176
   v       s        p       b       H   f   E    L    O    W    A    L    E
   o       p        i       e       E   a   H    O    W    W    X    E    D
   l       e        t       n           s   L         W         R
           e        c       d           t   L         W         R
           d        h
  */

  // byte array holding speech data
  byte sayThis[] = {20, 96, 21, 114, 22, 88, 23, 5, 183, 7, 159, 146, 164, 147, 151, 145, 176}; //say "hello world"
  // send it to the SpeakJet
  for (int i=0; i<sizeof(sayThis); i++) {
    speakJet.print(sayThis[i], BYTE);
  }
}

void loop()
{}


At this point, save the script and clicke the "Upload" button in the Arduino editor.

After a few moments, the Arduino will reset and you will hear "ready".

After that, it very shortly should say "Hello world!"

Press the "Reset" button to hear it again...

Note: The script above has been tested on Arduino 15, 17 and 18 software. It has not been tested on earlier versions. It may or may not function on older Arduino software.

Long Sentences...

Long sentences can be problematic. If the SpeakJet Shield stutters or skips words you may have overrun the SpeakJet buffer. This requires insertion of either "delay" statements or writing some code to handle the SpeakJet handshake. Usually a delay of 3-5 seconds will suffice (to create a delay of 5 seconds insert "delay(5000);" into your program). How to write handshake code will also be covered in a later tutorial.

Using NewSoftSerial library...
In most examples on this website, the Arduino softwares' built-in SoftwareSerial library is used to communicate with the SpeakJet. If you are needing more serial connections, or you are having strange behavior with the speech when other shields are being used, you may want to give NewSoftSerial library a try. This library can be substituted for SoftwareSerial to add more serial ports (for example, say you want to use a GPS with the SpeakJet Shield) or to resolve timing issues. I myself saw an interrupt/timing problem when using the SpeakJet Shield with a Nuelectronics Nokia 3310 LCD shield - switching to NewSoftSerial resolved the issues I was seeing!

Once you have downloaded and installed NewSoftSerial library, to use it you need only change two lines in your sketch.

Change:
#include <SoftwareSerial.h>
and
SoftwareSerial speakJet =  SoftwareSerial(rxPin, txPin);

To:
#include <NewSoftSerial.h>
and
NewSoftSerial speakJet =  NewSoftSerial(rxPin, txPin);

No other changes are needed!

Creative Commons License
SpeakJet Shield TTS/Basic by Galen Raben is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
Permissions beyond the scope of this license may be available at http://www.droidbuilder.com.

Code samples given in this document are released into the public domain.

© 2013 Galen Raben/DroidBuilder.com
ċ
HelloWorld.pde
(1k)
Galen Raben,
May 4, 2010, 8:47 PM