Sound - Text to Speech

2.10. Sound - Text to Speech#

The speech library converts text to speech using a system called SAM (Software Automated Mouth) originally released in 1982 for the Commodore 64.

The system works by translating text to a sequence of “phonemes”, which are small sounds that make up the pronunciation of words. Playing the phenomes quickly in order approximates speech.

2.10.1. Speaking#

You can use

speech.say(words, pitch=64, speed=72, mouth=128, throat=128)

to say the English words where:

  • words is a string of English

  • pitch controls the frequency of the voice used

  • speed is the playback speed

  • mouth controls the amount of mouth movement (0-255), with lower values having less movement

  • throat controls the throat tension (0-255), with lower values being more relaxed

Example#

from microbit import *
import speech

while True:
    speech.say("EXTERMINATE", speed=120, pitch=100, throat=100, mouth=200)
    sleep(500)