Emic2 Speech Synthesis Module Hello World Demo See https://developer.mbed.org/users/4180_1/notebook/emic-2-text-to-speech-engine/
Revision 0:2128ea16088c, committed 2015-11-25
- Comitter:
- 4180_1
- Date:
- Wed Nov 25 03:08:52 2015 +0000
- Commit message:
- ver 1.0
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/emic2.h Wed Nov 25 03:08:52 2015 +0000
@@ -0,0 +1,41 @@
+#define speakf printf
+class emic2 : public Stream
+{
+public :
+ emic2(PinName tx, PinName rx): _cmd(tx,rx) {
+ _cmd.baud(9600);
+ _cmd.putc('X'); //stop talking if reset and not a power on
+ _cmd.putc('\r'); // Send a CR in case the system is already up
+ wait(1); //delay for emic power on boot or reset respone
+ while (_cmd.getc() != ':'); // When the Emic 2 has initialized and is ready, it will send a single ':'
+ while (_cmd.readable()) _cmd.getc();//flush out buffer just in case
+ };
+ void ready() {
+ while (_cmd.getc() != ':');
+ while (_cmd.readable()) _cmd.getc();//flush out recieve buffer just in case
+ };
+ int readable() {
+ return _cmd.readable();
+ };
+ int getc() {
+ return _cmd.getc();
+ }
+ void volume(int x) {
+ speakf("V%D\r",x);
+ ready();
+ }
+ void voice(int x) {
+ speakf("N%D\r",x);
+ ready();
+ }
+protected :
+ Serial _cmd;
+ //used by printf - supply it and printf works!
+ virtual int _putc(int c) {
+ _cmd.putc(c);
+ return 0;
+ };
+ virtual int _getc() {
+ return -1;
+ };
+};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Nov 25 03:08:52 2015 +0000
@@ -0,0 +1,51 @@
+#include "mbed.h"
+//Emic 2 Hello Speech World Demo
+
+DigitalOut myled(LED1);
+#include "emic2.h"
+
+emic2 myTTS(p13, p14); //serial RX,TX pins to emic
+
+int main()
+{
+ myTTS.volume(18); //max volume
+ while(1) {
+ myled = 1;
+ //Plain text demo
+ myTTS.speakf("S");//Speak command starts with "S"
+ myTTS.speakf("Hello. My name is the Emic 2 Text-to-Speech module. I would like to sing you a song on m bed."); // Send the desired string to convert to speech
+ myTTS.speakf("\r"); //marks end of speak command
+ myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+ myled = 0;
+ myled = 1;
+ //Song Demo
+ myTTS.speakf("D1\r");//Sing Song Demo
+ myTTS.ready(); //member function wait
+ myled = 0;
+ //Voice Demo
+ for (int i=0; i<9 ; i++) { //demo different voices
+ myTTS.voice(i);
+ myTTS.speakf("SHello this is a sample of voice number, %D\r",i);
+ myTTS.ready();
+ }
+ myTTS.voice(0); //back to default voice
+ //Number demo
+ for (int i=10; i>=0 ; i--) { //demo different numbers
+ myTTS.speakf("S%D.\r",i);
+ myTTS.ready();
+ }
+ //Read Time (RTC) demo
+ set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37
+ wait(2); //let RTC advance two seconds after setting to confirm it works
+ time_t seconds = time(NULL);//read current time
+ myTTS.speakf("STime in seconds since January 1, 1970 =, %d\r", seconds);
+ myTTS.ready();
+ myTTS.speakf("STime as a basic string = %s\r", ctime(&seconds));
+ myTTS.ready();
+ char buffer[32];
+ strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
+ myTTS.speakf("SThe current time is %s\r", buffer);
+ myTTS.ready();
+
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Nov 25 03:08:52 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11 \ No newline at end of file
EMIC 2 Text to Speech Engine