Hardware Reference
In-Depth Information
if __name__ == '__main__':
main()
Run try_espeak.py and check that you hear “Hello World” from the speakers.
Try espeak with different pronunciation options, such as American or caricatures of British
accents such as Northern, West Midlands or Scottish. The codes needed are described in
the espeak documentation at http://espeak.sourceforge.net/languages.html . You could add
another argument to the say function and pass information to set the accent. If you are really
adventurous, you could try passing pitch, speed and voice arguments, and you'll get some
very silly sounding voices.
YOUR TURN!
Making It Move
The next step is to turn on the motors of the toy to make the mouth move while it is speak-
ing. To control the motors, you'll use PiFace Digital. You should have set up PiFace Digital as
specified in Chapter 1, “Test Your Reactions”. Because there are LEDs on the board, these will
indicate that the outputs are active so you can test the code before connecting the chicken.
Create a new file named chicken.py and enter the following:
import piface.pfio as pfio
import espeak as talker
VERBOSE_MODE = True
class Chicken():
#The wobbling/talking chicken
def __init__(self, pfio, pin):
pfio.init()
self.pfio = pfio
self.relay_pin = pin
def start_wobble(self):
#Starts wobbling the chicken
self.pfio.digital_write(self.relay_pin,1)
if VERBOSE_MODE:
print “Chicken has started wobbling.”
def stop_wobble(self):
#Stops wobbling the chicken
self.pfio.digital_write(self.relay_pin,0)
continued
 
Search WWH ::




Custom Search