A while back, I bought the Emic TTS module from Parallax, but I ended up not using it. Well, now I need to implement it into a project, but this time I am going to be interfacing it with the Arduino instead of the BASIC Stamp. I have tried and tried and tried to get it to work with the Arduino, but each time I have failed. I haven't been able to find code on the web that uses the Arduino with the Emic TTS, so I had to try to 'translate' the BS2 code that talks to the Emic, into Arduino code. Here's the BS2 Code:
' =========================================================================
'
' File...... EasyEmic.BS2
' Purpose... Simple Emic TTS demonstration
' Author.... Parallax, Inc. (Copyright (c) 2004, All Rights Reserved)
' E-mail.... support@parallax.com
' Started...
' Updated... 28 APR 2004
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
'
' Simple Emic TTS speech demo. Be sure to set both Emic DIP switches to
' the OFF (down) position.
' -----[ I/O Definitions ]-------------------------------------------------
Tx PIN 0 ' connects to Emic SIn
Rx PIN 1 ' connects to Emic SOut
Busy PIN 2 ' 1 = busy
' -----[ Constants ]-------------------------------------------------------
#SELECT $STAMP
#CASE BS2, BS2E, BS2PE
Baud CON 396 ' 2400 baud, N81
#CASE BS2SX, BS2P
Baud CON 1021
#ENDSELECT
Yes CON 1
No CON 0
' Emic Commands (Hex Mode)
Say CON $00 ' say Engish text
Volume CON $01 ' set volume, 0 - 7
Speed CON $02 ' set speed, 0 - 4
Pitch CON $03 ' set pitch, 0 - 6
AddAbbr CON $04 ' add abbreviation
DelAbbr CON $05 ' delete abbreviation
ListAbbr CON $06 ' list abbreviations
Version CON $07 ' get version
Reset CON $08 ' soft reset
Audio CON $09 ' enable audio in
PhT CON $10 ' start of phonetic text
Help CON $FE ' display help
EOM CON $AA ' end of message
OK CON $55 ' "okay" for hex mode
' -----[ Program Code ]----------------------------------------------------
Main:
DO
GOSUB Check_Busy
SEROUT Tx, Baud, [Say, "Hello world. I am Emic. Hear me roar.", EOM]
PAUSE 2000
LOOP
END
' -----[ Subroutines ]-----------------------------------------------------
' Check status of Emic TTS module
' -- wait until Busy line released by Emic
' -- code as written does not timeout
Check_Busy:
PAUSE 1 ' allow busy to activate
DO WHILE (Busy = Yes) : LOOP ' wait until not busy
RETURN
...And here's my implementation of that code in an Arduino sketch:
// Emic TTS Commands
#define Say 0x00
#define Volume 0x01
#define Speed 0x02
#define Reset 0x08
#define PhT 0x10
#define Help 0xFE
#define EOM 0xAA
#define OK 0x55
#define Yes 1
#define No 0
byte vol;
byte spd;
byte ptch;
boolean Busy;
int timeout;
int Data;
void setup() {
Serial.begin(2400); //Emic communicates at 2400Baud
pinMode(BusyPin, INPUT);
}
void loop() {
Check_Busy();
Serial.begin(2400);
Serial.print(Say);
Serial.print("Hello");
Serial.print(EOM);
delay(5000);
}
void Check_Busy() {
Serial.begin(9600);
Serial.println("Checking Busy...");
//Serial.begin(2400);
delay(1);
Busy = digitalRead(BusyPin);
do {
Serial.println(Busy, DEC);
Busy = digitalRead(BusyPin);
} while(Busy, DEC == 1);
Serial.begin(9600);
Serial.println("Busy Done");
}