Emic2 Speech Synthesis Module Hello World Demo See https://developer.mbed.org/users/4180_1/notebook/emic-2-text-to-speech-engine/

Dependencies:   mbed

Committer:
4180_1
Date:
Wed Nov 25 03:08:52 2015 +0000
Revision:
0:2128ea16088c
ver 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 0:2128ea16088c 1 #define speakf printf
4180_1 0:2128ea16088c 2 class emic2 : public Stream
4180_1 0:2128ea16088c 3 {
4180_1 0:2128ea16088c 4 public :
4180_1 0:2128ea16088c 5 emic2(PinName tx, PinName rx): _cmd(tx,rx) {
4180_1 0:2128ea16088c 6 _cmd.baud(9600);
4180_1 0:2128ea16088c 7 _cmd.putc('X'); //stop talking if reset and not a power on
4180_1 0:2128ea16088c 8 _cmd.putc('\r'); // Send a CR in case the system is already up
4180_1 0:2128ea16088c 9 wait(1); //delay for emic power on boot or reset respone
4180_1 0:2128ea16088c 10 while (_cmd.getc() != ':'); // When the Emic 2 has initialized and is ready, it will send a single ':'
4180_1 0:2128ea16088c 11 while (_cmd.readable()) _cmd.getc();//flush out buffer just in case
4180_1 0:2128ea16088c 12 };
4180_1 0:2128ea16088c 13 void ready() {
4180_1 0:2128ea16088c 14 while (_cmd.getc() != ':');
4180_1 0:2128ea16088c 15 while (_cmd.readable()) _cmd.getc();//flush out recieve buffer just in case
4180_1 0:2128ea16088c 16 };
4180_1 0:2128ea16088c 17 int readable() {
4180_1 0:2128ea16088c 18 return _cmd.readable();
4180_1 0:2128ea16088c 19 };
4180_1 0:2128ea16088c 20 int getc() {
4180_1 0:2128ea16088c 21 return _cmd.getc();
4180_1 0:2128ea16088c 22 }
4180_1 0:2128ea16088c 23 void volume(int x) {
4180_1 0:2128ea16088c 24 speakf("V%D\r",x);
4180_1 0:2128ea16088c 25 ready();
4180_1 0:2128ea16088c 26 }
4180_1 0:2128ea16088c 27 void voice(int x) {
4180_1 0:2128ea16088c 28 speakf("N%D\r",x);
4180_1 0:2128ea16088c 29 ready();
4180_1 0:2128ea16088c 30 }
4180_1 0:2128ea16088c 31 protected :
4180_1 0:2128ea16088c 32 Serial _cmd;
4180_1 0:2128ea16088c 33 //used by printf - supply it and printf works!
4180_1 0:2128ea16088c 34 virtual int _putc(int c) {
4180_1 0:2128ea16088c 35 _cmd.putc(c);
4180_1 0:2128ea16088c 36 return 0;
4180_1 0:2128ea16088c 37 };
4180_1 0:2128ea16088c 38 virtual int _getc() {
4180_1 0:2128ea16088c 39 return -1;
4180_1 0:2128ea16088c 40 };
4180_1 0:2128ea16088c 41 };