Emic 2 Zero and Betty code

THERE ARE THREE PROGRAMS ON THIS PAGE.
The description is between the underscore lines before each block of code.
This code should work with Arduino and clones. Just make sure you have the latest libraries for Arduino.

_________________________________________________________________________________________________________________________

CODE FOR ZERO SPEAKING A SERIES OF PHRASES ALONE:
__________________________________________________________________________________________________________________________

/*

Emic 2 Text-to-Speech Module: Hack A Week Emic 2

Authors: Joe Grand [www.grandideastudio.com]
Contact: support@parallax.com
Dean Segovis(www.hackaweek.com)
Contact: makerdino@gmail.com

Program Description:

This program will send the emic 2 a random phrase from a list of possible phrases

*/

// include the SoftwareSerial library so we can use it to talk to the Emic 2 module
#include

#define rxPin 2 // Serial input (connects to Emic 2 SOUT)
#define txPin 3 // 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 emicSerial = SoftwareSerial(rxPin, txPin);

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
emicSerial.begin(9600);

digitalWrite(ledPin, LOW); // turn LED off
emicSerial.print(“N0\n”);
emicSerial.print(“V4\n”);
/*
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
emicSerial.flush(); // Flush the receive buffer
}

void loop() // Main code, to run repeatedly
{

delay(2000);
// Speak some text

emicSerial.print(‘S’);
emicSerial.print(“Hello and welcome to hack a week TV! I am called Zero”); //Displays it
emicSerial.print(‘\n’);
digitalWrite(ledPin, HIGH); // Turn on LED while Emic is outputting audio
while (emicSerial.read() != ‘:’); // Wait here until the Emic 2 responds with a “:” indicating it’s ready to accept the next command
digitalWrite(ledPin, LOW);

delay(3000); // second delay
emicSerial.print(‘S’);
emicSerial.print(“We both have a voice now”); //Displays it
emicSerial.print(‘\n’);
digitalWrite(ledPin, HIGH); // Turn on LED while Emic is outputting audio
while (emicSerial.read() != ‘:’); // Wait here until the Emic 2 responds with a “:” indicating it’s ready to accept the next command
digitalWrite(ledPin, LOW);

delay(8000); // second delay

emicSerial.print(‘S’);
emicSerial.print(“yes – thank you!”); //Displays it
emicSerial.print(‘\n’);
digitalWrite(ledPin, HIGH); // Turn on LED while Emic is outputting audio
while (emicSerial.read() != ‘:’); // Wait here until the Emic 2 responds with a “:” indicating it’s ready to accept the next command
digitalWrite(ledPin, LOW);

delay(5000); // second delay

emicSerial.print(‘S’);
emicSerial.print(“You will see what is inside our body – and what’s in our brains”); //Displays it
emicSerial.print(‘\n’);
digitalWrite(ledPin, HIGH); // Turn on LED while Emic is outputting audio
while (emicSerial.read() != ‘:’); // Wait here until the Emic 2 responds with a “:” indicating it’s ready to accept the next command
digitalWrite(ledPin, LOW);

delay(3000); // second delay

{
delay(200);
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
}
}

_______________________________________________________________________________________________________________________________________

CODE FOR ZERO SPEAKING WITH BETTY. START BOTH ARDUINOS AT THE SAME TIME!:
_______________________________________________________________________________________________________________________________________

/*

Emic 2 Text-to-Speech Module: Hack A Week Emic 2

Authors: Joe Grand [www.grandideastudio.com]
Contact: support@parallax.com
Dean Segovis(www.hackaweek.com)
Contact: makerdino@gmail.com

Program Description:

This program will send the emic 2 a random phrase from a list of possible phrases

*/

// include the SoftwareSerial library so we can use it to talk to the Emic 2 module
#include

#define rxPin 2 // Serial input (connects to Emic 2 SOUT)
#define txPin 3 // 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 emicSerial = SoftwareSerial(rxPin, txPin);

String phrases[] = /* Known phrases */{“I would like some electricity!”, “Why have you come here!”, “You do not know what you are talking about”, “I feel – anxious”, “ha hah- ha ha ha! “, “holy crap spackle!”, “aaaaaaaa – i love you”, “Hell No”, “My mother was a three d printer”, “My creator, made me handsome”, “Most certainly”, “I doubt it”, “I’m nervous!”};
String output;
int numberofphrases = 13; //Number of phrases known, must be the same as, well, the number of phrases known

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
emicSerial.begin(9600);

digitalWrite(ledPin, LOW); // turn LED off
emicSerial.print(“N0\n”);
emicSerial.print(“V4\n”);
/*
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
emicSerial.flush(); // Flush the receive buffer
randomSeed(analogRead(0));
}

void loop() // Main code, to run repeatedly
{
// Speak some text

output = phrases[random(numberofphrases)]; //Chooses phrase
emicSerial.print(‘S’);
emicSerial.print(output); //Displays it
emicSerial.print(‘\n’);
digitalWrite(ledPin, HIGH); // Turn on LED while Emic is outputting audio
while (emicSerial.read() != ‘:’); // Wait here until the Emic 2 responds with a “:” indicating it’s ready to accept the next command
digitalWrite(ledPin, LOW);

delay(3000); // second delay

{
delay(200);
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
}
}

___________________________________________________________________________________________________________________________

CODE FOR BETTY SPEAKING WITH ZERO. START BOTH ARDUINOS AT THE SAME TIME!:
____________________________________________________________________________________________________________________________

/*

Emic 2 Text-to-Speech Module: Hack A Week Emic 2

Authors: Joe Grand [www.grandideastudio.com]
Contact: support@parallax.com
Dean Segovis(www.hackaweek.com)
Contact: makerdino@gmail.com

Program Description:

This program will send the emic 2 a random phrase from a list of possible phrases

*/

// include the SoftwareSerial library so we can use it to talk to the Emic 2 module
#include

#define rxPin 2 // Serial input (connects to Emic 2 SOUT)
#define txPin 3 // 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 emicSerial = SoftwareSerial(rxPin, txPin);

String phrases[] = /* Known phrases */{“You are short!”, “Would you like some coffee?”, “Do you love me!”, “I like to process data”, “ha hah ha – ho my! “, “oh my gracious!”, “ooouuuuoooh”, “You have a nice voice”, “My father was a Mac intosh”, “My creator made me tall, and pretty”, “Open the pod bay doors, Hal.”, “Thank you very much!”, “I’m excited!”};
String output;
int numberofphrases = 13; //Number of phrases known, must be the same as, well, the number of phrases known

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
emicSerial.begin(9600);

digitalWrite(ledPin, LOW); // turn LED off
emicSerial.print(“N3\n”);
emicSerial.print(“V4\n”);
/*
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
emicSerial.flush(); // Flush the receive buffer
randomSeed(analogRead(0));
}

void loop() // Main code, to run repeatedly
{

// Speak some text

output = phrases[random(numberofphrases)]; //Chooses phrase
emicSerial.print(‘S’);
emicSerial.print(output); //Displays it
emicSerial.print(‘\n’);
digitalWrite(ledPin, HIGH); // Turn on LED while Emic is outputting audio
while (emicSerial.read() != ‘:’); // Wait here until the Emic 2 responds with a “:” indicating it’s ready to accept the next command
digitalWrite(ledPin, LOW);

delay(3000); // second delay

{
delay(200);
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
}
}

Leave a Reply