BBC micro:bit
The Speech Module

Introduction

In 1982, a program called SAM (Software Automated Mouth) was released for the Commodore 64 personal computer. This was a pretty early version of a 'text to speech' program and the quality is not amazing. It is, as the MicroPython team say, 'good enough' and a nice feature to have on a microcontroller. Text-to-speech in a microcontroller project usually means buying a £20 integrated circuit and the quality is no better, and the programming not easier.

In order to use the speech module, you will need to connect a speaker. A piezo buzzer isn't going to work for this. You can use the headphones hack for this though. Connect your speaker to pin 0, the default audio pin.

Programming

There are lots of ways to configure the nature of the speaking voice, all wonderfully documented in the MicroPython Documentation. The easiest way to kick off is with the speech.say() statement.

from microbit import *
import speech

speech.say("microbit speaking to you")

Notice that you need to import a separate module to use the speech module. You can use punctuation with your text and appropriate pauses will be used in the speech.

Check out the documentation to read about more of the statements in this module. You can control the style of the speaking voice as well as the speed of delivery. You can also get the micro:bit to pronounce 'phonemes' (the units of sound used to express ourselves in our language). This can give a much more accurate representation than the software's best guess. One final possiblity is to make the micro:bir voice sing - a matter of time before someone uses this for a geeky Rick Roll.

The Quality

The quality of the speech is not, as previously stated, amazing. It is quite usable though. Speech synthesis that is as rough and ready as this is quite interesting in itself though. Let's say that you try this out with the example program above. You will not have any problem recognising that the phrase you wrote was said out loud by the micro:bit. So, all excited, you write some hilariously funny jokes and play it to somebody else. Surprisingly, they don't seem to be able to work out what is being said.

Your first reaction might be to listen yourself. You'll say it sounds fine, the words are crystal clear. They still say they can't quite capture every word. Maybe you start to think that there is something not quite right about them or their hearing. You will be wrong.

This shows us something about the way that our brains process speech. One of the early attempts at speech synthesis was called Sine Wave Speech. Search the WWW and you can find examples. If you play one of these files to someone saying only 'What Is This?', they will probably tell you it is some whistling. If they are old enough, they will tell you it's a clanger. Tell them it is meant to be speech and ask them to listen again. This time they might make out some words or parts of words. Tell them what is being said and they will hear it clearly. Processing of speech and language is a complex thing. Knowing that we are listening for words seems to change the way we process the sensory input in our brains. Knowing what those words are is an even greater change for us.

The SAM program on the micro:bit is very similar. It's easier to tell that it's speech you are listening to but still tough to make out the words sometimes. If you write the program, you already know what is going to be said and you will always hear it more clearly than someone who doesn't know the words. This is obviously something to bear in mind when developing your projects.

Challenges

  1. First, get over the fun of making it say rude words, insults and so on. Speech could be used in lots of different ways in your exisiting projects, pretty much any time you want to output information.
  2. You can write a genuine Magic 8 Ball program which speaks out loud its answer to your questions. The program should wait until the micro:bit is shaken. Then it should output one of the answers that you can find if you look for this information online. The idea is that the user asks a questions and shakes the micro:bit to hear an answer. If the shaking is messing up your circuit, go for a button press instead.
  3. In the MicroPython Documentation, there is an example of a limerick generator. You could adapt this version for a different set of rhyming words (keep it clean though). You could go a little further and try some different formats. There are several ways to go about planning something like that. My preferred method is to start with an example of a complete verse. This could be something you write or something you use as a model. Then you need to think about the things you want to vary and the things you keep the same. If you are using rhyme (which makes more impressive results), you can use the same sounds in all your variations or write a more complex program that can select words to rhyme with previously chosen ones.
  4. If the poetry isn't you, think of something else that has a formula to it. Post-match interviews with sportspeople tend to be full of clichés.