Skip to content

Instantly share code, notes, and snippets.

@deladriere
Created February 8, 2014 08:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save deladriere/8878702 to your computer and use it in GitHub Desktop.
Save deladriere/8878702 to your computer and use it in GitHub Desktop.
SSI-263 Votrax SC_02 text to speech via Nanpy on Arduino
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Jean-Luc Deladriere
# Description: SSI-263 Votrax SC_02 text to speech via Nanpy on Arduino
# many thanks for the arpabet to unicode phoneme script : https://gist.github.com/liuyork/4556798
from nanpy import Arduino
from nanpy import serial_manager
import time
import nltk
#Define serial port to use with Nanpy (should be automatic but doesn't work yet)
serial_manager.connect('/dev/tty.usbmodem1d1371')
time.sleep(2)
#Acknoledge/Request pin
Arduino.pinMode(15, Arduino.INPUT)
#R/W Strobe pin
Arduino.pinMode(13, Arduino.OUTPUT)
Arduino.digitalWrite(13,1)
#Data & registers bus pins
for i in range(2,13):
Arduino.pinMode(i, Arduino.OUTPUT)
#phoneme strings adapted to match the SSI-263 phoneme chart and diphthong set
phons = {'AA': "0x0E", 'AE': "0x0C", 'AH':"0x1B", 'AO':"0x12,0x11,0x11", 'AR': "0x0C,0x1C",
'AW': '0x0F,0x10,0x11,0x16', 'AX':'0x0C,0x23', 'AY': '0x0F,0x0D,0x0B,0x03', 'B': '0x24', 'CH': '0x28,0x2D,0x32',
'D': '0x25', 'DH': '0x36', 'EH': '0x0A', 'EL': '0x0A,0x20', 'EN': '0x0A,0x38',
'ER': '0x1C', 'EY': '0x08,0x05,0x03', 'F': '0x34', 'G': '0x26', 'HH': '0x2C',
'IH': '0x07', 'IR': '0x07,0x1D', 'IY': '0x05', 'JH': '0x25,0x31', 'K': '0x29,0x2C',
'L': '0x20', 'M': '0x37', 'N': '0x38', 'NG': '0x39', 'OW': '0x11,0x16',
'OY': '0x11,0x19,0x0F,0x07,0x06', 'P': '0x27', 'R': '0x1D', 'S': '0x30', 'SH': '0x32',
'T': '0x28', 'TH': '0x35', 'UH': '0x15', 'UR': '0x16,0x1C', 'UW': '0x14,0x16,0x16',
'V': '0x33', 'W': '0x23', 'Y': '0x04', 'Z': '0x2F', 'ZH': '0x2F', 'SIL': '0'}
apb_dict = nltk.corpus.cmudict.dict()
def say_it(chaine):
rondelle=chaine.split(",")
for i in rondelle:
allo=int(i,16)
Command(0,allo)
def arpabet(word):
try:
arpabet = apb_dict[word]
return arpabet
except Exception, e:
print "Error ! cannot process : "+ str(e)
arpabet = apb_dict["error"]
return arpabet
def phoneme(apb):
s = ''
for p in apb:
print p,
if p.endswith(('0', '1', '2')):
s = phons[p[0:-1]]
print s
say_it(s)
else:
s = phons[p]
print s
say_it(s)
return
def Strobe():
Arduino.digitalWrite(13,0)
Arduino.digitalWrite(13,1)
def Command(register,value):
# writing the command's address
for i in range(4):
b=(int(register) & pow(2,i))/ pow(2,i)
Arduino.digitalWrite(i+10, b)
# writing the data
for i in range(8):
b=(int(value) & pow(2,i))/ pow(2,i)
Arduino.digitalWrite(i+2, b)
while True:
if Arduino.digitalRead(15)==0: # wait for the SSI to be done (A/R going low)
break
Strobe()
def set_voice(type):
temp=voices[type]
for i in temp:
Command(i[0],i[1])
#Prepare registers
Command(0,192) # load DR1 DR2 bit to 1 (to activate A/R request mode)
Command(3,127) # Control bit to 1
Command(3,0) # Control bit to 0 (to activate A/R request mode by going to 0)
#Additional registers settings
voices= {
"robot":[[3,110],[4,225],[2,80],[1,127]],
"normal":[[3,110],[4,231],[2,168],[1,127]]
}
set_voice('normal')
#Main loop
while True:
text=raw_input("\ntext : ")
text=text.lower()
words = nltk.word_tokenize(text)
for word in words:
print"-------------"
print word
phon = phoneme(arpabet(word)[0])
Command(0,0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment