Today was another busy day, but I took a little time at lunch and then a little more after work to hook up the Emic2 speech chip and see if I could program some voice into the robot.
The reason I picked the Emic2 was because I can feed it strings and it will speak whatever I type with very little fuss.
There are a few other speech chips available, and I actually have the original Hero Jr. speech chip, but it has such limited capability compared to the newer technology, that I thought I would give this one a try.
The installation of the chip is pretty simple, there are really only 4 wires. You have +5V and Ground to power the chip, then Sin and Sout where you pass the serial in and serial out commands from the microprocessor. Since I am using Arduino boards as my processors, I grabbed an Arduino Mega and plugged in the 4 wires, found an old speaker and connected the 2 wires from that to the Speaker + and - leads. There is also a headphone jack where you can plug in an external speaker as well.
After a short bit of coding, I had the Emic2 speaking and running his demos in English and in Spanish! Then he sings a song...
Once I finish learning the speech commands, I will make a speech library of phrases and place them on an SD card and have those phrases available to be read in response to other commands. I will likely number the responses and then make an array of (n) units and each time I need a phrase, I can command emicSerial.print(n); and it will call the phrase I need.
Other speech can be live as it is parsed from the voice recognition...which I will get to later on.
The code I used is below.
/*
This program provides a simple demonstration of the Emic 2 Text-to-Speech
Module. Please refer to the product manual for full details of system
functionality and capabilities. You can program this chip in a variety
of ways and they have examples for Parallax, and Arduino.
*/
// include the SoftwareSerial library so we can use it to talk to the Emic 2 module
#include <SoftwareSerial.h>
#define rxPin 50 // Serial input (connects to Emic 2 SOUT)
#define txPin 51 // 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
/*
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
{
// Speak some text
//emicSerial.print("N1\n"); //Change the Voice Tone here...1-9 are valid voices.
emicSerial.print("V15\n");
emicSerial.print('S');
// Send the desired string to convert to speech
emicSerial.print("Holy Crap spackel!");
emicSerial.print("Hello. I would like to demonstrate some of my features.");
emicSerial.print("Now that I can talk, I might not shut up!");
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(500); // 1/2 second delay
// Run 3 demos...
emicSerial.print("D0\n"); // Demo 1 in english.
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);
emicSerial.print("D2\n"); // Demo 2 in spanish.
digitalWrite(ledPin, HIGH);
while (emicSerial.read() != ':');
digitalWrite(ledPin, LOW);
emicSerial.print("D1\n"); // Demo 3 is Emic singing 'Daisy'
digitalWrite(ledPin, HIGH);
while (emicSerial.read() != ':');
digitalWrite(ledPin, LOW);
// Below is a loop to keep the Emic from repeating over and over...basically it just flashes the led on and off...
while(1) // Demonstration complete!
{
delay(500);
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
}
}
No comments:
Post a Comment