Saturday, April 6, 2013

Text to Speech with a EMIC2 & a Raspberry Pi

The EMIC2 text to speech module does not require any special libraries and it communicates with the controller using a serial connection, so it is not difficult to get it working with a Raspberry Pi. Below is an example that uses Python to send messages to the EMIC2.  

The EMIC2 is a 5V device, so a logic level converter is required on the serial connection to and from the Raspberry Pi.

For audio output, I have used a cheap thin speaker from Sparkfun, but you can also use the headphone jack on the module.

The RXD and TXD pins on the Pi connect to the Linux serial device ttyAMA0. By default, though, this device is used for console output. Follow the 3 steps on the Adafruit Learning System page, "Freeing UART on the Pi."

Connections


EMIC2  Logic Level Converter  Raspberry Pi
GND    HV GND     ----->      GND
5V     HV HV      ----->      5V
SOUT   HV RXI     LV RXO      RXD
SIN    HV TXO     LV TXI      TXD
                  LV LV       3V3
                  LV GND      GND

Connect SP- & SP+ to the speaker.

    

Python Code


The following demonstration code counts out load. Depending on your actual output, ou may need to experiment with the time.sleep() calls to get the values right.

import serial
import time

serial = serial.Serial("/dev/ttyAMA0", baudrate=9600)
serial.open()
serial.write("\n")
time.sleep(1)
serial.write("V15\n") # Adjust volume
c = 0
while True:
        serial.write("\n")
        time.sleep(0.75)
        data = serial.read()
        if data == ':':
                buffer = "S%d" % (c)
                c = c + 1
                serial.write(buffer)
                time.sleep(0.5)
        else:
                time.sleep(0.5)

serial.close()

For documentation on the various EMIC2 commands, see the manual.
      




No comments:

Post a Comment