Emic2 transactions using Arduino UNO
I have my Emic2 working very well with the Emic2_Demo.ino.
I would like to use the Arduino's Serial Monitor to send text to the Emic2 and receive replays from it.
Any thoughts?
Irv
Here is the Arduino Sketch that I have tried. (I am not very well experienced in C++)
Using the Sketch 'Serial Monitor', I can enter text to be spoken. That works but If the text is over 64 characters long the speech is truncated.
Also, If I enter an 'H' (to get the listing of commands) I only get one line of text.
Any help will be most welcome.
/*
Based on Emic 2 Text-to-Speech Module: Basic Demonstration
Author: Joe Grand [www.grandideastudio.com]
Contact: support@parallax.com
*/
//First 'text in' based on linux-utils.blogspot.com/2010/10/arduino-serial-read-line.html
// also forums.adafruit.com/viewtopic.php?f=8&t=9918
// include the SoftwareSerial library so we can use it to talk to the Emic 2 module
#include <SoftwareSerial.h>
#define rxPin 8 // Serial input (connects to Emic 2 SOUT)
#define txPin 9 // Serial output (connects to Emic 2 SIN)
#define ledPin 13 // Most Arduino boards have an on-board LED on this pin
// set up a new serial port
SoftwareSerial mySerial = SoftwareSerial(RXPin, TXPin);
SoftwareSerial emicSerial = SoftwareSerial(rxPin, txPin);
boolean stringComplete = false;
boolean emicStringComplete = false;
void setup() // Set up code called once on start-up
{
// define pin modes
pinMode(ledPin, OUTPUT);
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
// set the data rate for the SoftwareSerial port
Serial.begin(57600);
Serial.println("Goodnight moon!"); // PC Port OK
mySerial.begin(57600); // set the data rate for the SoftwareSerial ports
emicSerial.begin(9600);
digitalWrite(ledPin, LOW); // turn LED off
/*
When the Emic 2 powers on, it takes about 3 seconds for it to successfully
intialize. It then sends a ":" character to indicate it's ready to accept
commands. If the Emic 2 is already initialized, a CR will also cause it
to send a ":"
*/
emicSerial.print('\n'); // Send a CR in case the system is already up
while (emicSerial.read() != ':'); // When the Emic 2 has initialized and is ready, it will send a single ':' character, so wait here until we receive it
delay(10); // Short delay
// Set Emic parameters
emicSerial.print("V-5\n"); // loudness (db)
emicSerial.print("N1\n"); // Voice
emicSerial.print("W150\n"); //Speed
emicSerial.print("P1\n"); // Parser 0=DECtalk 1=Epson
emicSerial.print("");
emicSerial.print('\n');
emicSerial.flush(); // Flush the receive buffer
Serial.flush();
}
void loop() // Main code, to run repeatedly
{
// Start text in
int i=0;
char textbuffer[500];
if(Serial.available() && stringComplete == false){
delay(20);
while(Serial.available() && i<499){
textbuffer[i++]= Serial.read();
if (textbuffer=='/n') break;
}
textbuffer[i++]='\0';
stringComplete == true;
if (i>0)
Serial.println((char*)textbuffer);
i=0;
emicSerial.print((char*)textbuffer); // Send the desired string to convert to speech // Send the desired string to convert to speech
emicSerial.print('\n');
stringComplete == false;
char emicTextbuffer[500];
int ix=0;
if(emicSerial.available() && emicStringComplete == false){
while (emicSerial.read() != ':');
delay(10);
while(emicSerial.available() && ix<499){
emicTextbuffer[ix++]= emicSerial.read();
if (emicTextbuffer[ix]=='/n') break;
}
emicTextbuffer[ix++]='\0';
emicStringComplete == true;
if (ix>0)
Serial.println((char*)emicTextbuffer);
ix=0;
delay(10);
emicStringComplete == false;
}
}
}
I would like to use the Arduino's Serial Monitor to send text to the Emic2 and receive replays from it.
Any thoughts?
Irv
Here is the Arduino Sketch that I have tried. (I am not very well experienced in C++)
Using the Sketch 'Serial Monitor', I can enter text to be spoken. That works but If the text is over 64 characters long the speech is truncated.
Also, If I enter an 'H' (to get the listing of commands) I only get one line of text.
Any help will be most welcome.
/*
Based on Emic 2 Text-to-Speech Module: Basic Demonstration
Author: Joe Grand [www.grandideastudio.com]
Contact: support@parallax.com
*/
//First 'text in' based on linux-utils.blogspot.com/2010/10/arduino-serial-read-line.html
// also forums.adafruit.com/viewtopic.php?f=8&t=9918
// include the SoftwareSerial library so we can use it to talk to the Emic 2 module
#include <SoftwareSerial.h>
#define rxPin 8 // Serial input (connects to Emic 2 SOUT)
#define txPin 9 // Serial output (connects to Emic 2 SIN)
#define ledPin 13 // Most Arduino boards have an on-board LED on this pin
// set up a new serial port
SoftwareSerial mySerial = SoftwareSerial(RXPin, TXPin);
SoftwareSerial emicSerial = SoftwareSerial(rxPin, txPin);
boolean stringComplete = false;
boolean emicStringComplete = false;
void setup() // Set up code called once on start-up
{
// define pin modes
pinMode(ledPin, OUTPUT);
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
// set the data rate for the SoftwareSerial port
Serial.begin(57600);
Serial.println("Goodnight moon!"); // PC Port OK
mySerial.begin(57600); // set the data rate for the SoftwareSerial ports
emicSerial.begin(9600);
digitalWrite(ledPin, LOW); // turn LED off
/*
When the Emic 2 powers on, it takes about 3 seconds for it to successfully
intialize. It then sends a ":" character to indicate it's ready to accept
commands. If the Emic 2 is already initialized, a CR will also cause it
to send a ":"
*/
emicSerial.print('\n'); // Send a CR in case the system is already up
while (emicSerial.read() != ':'); // When the Emic 2 has initialized and is ready, it will send a single ':' character, so wait here until we receive it
delay(10); // Short delay
// Set Emic parameters
emicSerial.print("V-5\n"); // loudness (db)
emicSerial.print("N1\n"); // Voice
emicSerial.print("W150\n"); //Speed
emicSerial.print("P1\n"); // Parser 0=DECtalk 1=Epson
emicSerial.print("");
emicSerial.print('\n');
emicSerial.flush(); // Flush the receive buffer
Serial.flush();
}
void loop() // Main code, to run repeatedly
{
// Start text in
int i=0;
char textbuffer[500];
if(Serial.available() && stringComplete == false){
delay(20);
while(Serial.available() && i<499){
textbuffer[i++]= Serial.read();
if (textbuffer=='/n') break;
}
textbuffer[i++]='\0';
stringComplete == true;
if (i>0)
Serial.println((char*)textbuffer);
i=0;
emicSerial.print((char*)textbuffer); // Send the desired string to convert to speech // Send the desired string to convert to speech
emicSerial.print('\n');
stringComplete == false;
char emicTextbuffer[500];
int ix=0;
if(emicSerial.available() && emicStringComplete == false){
while (emicSerial.read() != ':');
delay(10);
while(emicSerial.available() && ix<499){
emicTextbuffer[ix++]= emicSerial.read();
if (emicTextbuffer[ix]=='/n') break;
}
emicTextbuffer[ix++]='\0';
emicStringComplete == true;
if (ix>0)
Serial.println((char*)emicTextbuffer);
ix=0;
delay(10);
emicStringComplete == false;
}
}
}
Comments
I'm no Arduino expert but I wanted to use the new Pixy in UART mode but I learned doing so required a Mega (IIRC) type board in order to sure the "serial1" library (I'm not sure if I'm using terms correctly).