Monday, 9 April 2012

Introducing the SpeakJet

Today I began work hooking up the SpeakJet chip to the Arduino. This juicy little IC takes commands over a serial interface that tell it to play a selection of around 40 different phonemes and a few other fun sounds. In addition, it allows you to control pitch, bend, volume and speed, add pauses and even control it as a pure 5 channel synthesizer. Baby steps though - my first challenge is just getting it to do something very basic.

I started this project with the help of this tutorial on the Practical Arduino web site. While useful, what it basically does it give you a list of components and then tell you to build this:

Now I'm sure to an experienced robotter this little circuit looks trivial, but to a novice like me it just made my brain hurt. I can follow it, but the idea of putting all those components together and keeping my fingers crossed that it'd all just work filled me with fear. So I decide to do things step by step and resort to the manual, which introduces me to demo mode!

The circuit above is taken from the SpeakJet manual. The bottom set of pins are all connected to ground, which if you just want speech will always be the way, as these are just the GND connection plus 8 event signals that can be left alone if you aren't doing fancy stuff with the synth.

Where it gets interesting is the top set of pins. In order from left to right we have:
  • A direct connection to a tiny speaker or head phones (i.e. no amplifier chip required)
  • 3 output pins that indicate Ready, Speaking, and Buffer Half Full
  • V+
  • 2 mode pins, both of which are connected to V+ for demo mode 
  • The reset pin, which should be held high, and only taken low to trigger a reset (important!)
  • The serial (RCX) pin which will be used later to communicate with the Arduino
So the first step is to hook the chip directly up to some batteries. As you can see here, I didn't have a female stereo jack  to plug headphones into, so I improvised with a couple of wires and some insulating tape :)

My makeshift 'mini jack connector' (aka insulating tape)

As soon as this is done I can hear the SpeakJet playing out a load of beeps, whistles and then all the different phoneoms and sounds it can make. Now the chip does something! Hurray!

SpeakJet hooked up to status LEDs

Next very simple step is to stay in demo mode, but power it off the arduino and hook up some LEDs to the 3 output pins so the chip can tell me what's going on. You can see the LEDs in the picture above - I highly recommend doing this if you're getting the SpeakJet working - it's reasurring if nothing else! I test again and unsurprisngly it's still alive.

Right, the circuit's powered off the Arduino and we can see the status of the chip, so it's time to get out of demo mode and start actually generating speech. Now the manual suggests that in order to do proper speaking you should hook the chip up to an Op Amp and all the crazy circuitry that goes with it:

Doing this results in the complex circuit I showed earlier (op amps need a lot of bits to set them up) and is an uncomfortably large step to take in my opinion. However I reason that if in demo mode you can just wire straight to some headphones, presumably you can do exactly this in normal mode, so I build the circuit below:

All that's really different here is the Mode 0 pin is now wired to ground, so it is no longer in demo mode, and I've connected the RCX (serial) pin to one of the Arduino's GPIO pins. I turn it on and the 'ready' LED activates, but nothing else happens. Which is unsurpring as i haven't programmed it to do anything yet...

So, to coding! First step is to get the example code from the tutorial I mentioned earlier. This is the code, unfortunately in image form as the blog doesn't seem to be able to handle code properly. You can get the actual text form here.

The first useful thing this showed me is the 'SoftwareSerial' utility that comes with the Arduino tool chain. The Arduino Uno only has 1 hardware serial device built in, which is handy to use for sending debug messages to the PC. However a software implementation comes with the package that can be wired to any pin. I changed the code so txPin points at GPIO pin 5 (the SpeakJet doesn't send messages back so rxPin is irrelevant).

I Run the code and lo and behold, serial communication kicks in and I hear 'hello my name is arduino' whispered out of my head phones! "It's Alive" I shout, and fellow programmer Dave wonders over to see what's happening, at which point I give him the headphones and tell him to listen very carefully... We fiddle with some numbers to change pitch and speed, but the very low volume makes things hard so it's time to get the amp hooked up, which means building the large and more complex circuit at the top. After pondering for a while I divide it into 3 sections:

  • The SpeakJet bit I already have most of and decide I can leave alone for now. The only stuff missing is some resistors that don't do too much (I hope...) and connections from all the data pins to the Arduino which is unnecesary.
  • The Middle Bit is a simple circuit I probably should have put in already, I assume either for filtering or noise protection. It's pretty easy to build and I knock it together in a few minutes. I test with the headphones again (this time connected to the end of the middle bit) and all is still good.
  • The amplifier isn't really speak jet specific. It's a standard setup for the LM386 audio amplifier, where the various capacitor and resistor configurations control it's behaviour.
Having done both the red and blue sections, the green bit seems a lot less scary and I get it all wired up:

So, having got everything connected together I place on my headphones and turn it on. Then I scream and take the headphones off again as the Arduino happily says HELLO MY NAME IS ARDUINO at ear drum splitting volume. The ringing in my ears has just about worn off now, and at least the amplifier worked. Really really really worked.

I'll leave the SpeakJet fun there for now. It's working but not much else. On the next post I'll be making use of the sensors and 'speaking' signal pin to do some more interesting talking.


No comments:

Post a Comment