class for emic 2 speech synthesis module

Dependents:   Alexa_Text BAT_senior_design_Azra BAT_senior_design_Nhi BAT_senior_design_Test ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers emic2.h Source File

emic2.h

00001 #define speakf printf
00002 class emic2 : public Stream
00003 {
00004 public :
00005     emic2(PinName tx, PinName rx): _cmd(tx,rx) {
00006         _cmd.baud(9600);
00007         _cmd.putc('X'); //stop talking if reset and not a power on
00008         _cmd.putc('\r'); // Send a CR in case the system is already up
00009         wait(1); //delay for emic power on boot or reset respone
00010         while (_cmd.getc() != ':');   // When the Emic 2 has initialized and is ready, it will send a single ':'
00011         while (_cmd.readable()) _cmd.getc();//flush out buffer just in case
00012     };
00013     void ready() {
00014         while (_cmd.getc() != ':');
00015         while (_cmd.readable()) _cmd.getc();//flush out recieve buffer just in case
00016     };
00017     int readable() {
00018         return _cmd.readable();
00019     };
00020     int getc() {
00021         return _cmd.getc();
00022     }
00023     void volume(int x) {
00024         speakf("V%D\r",x);
00025         ready();
00026     }
00027     void voice(int x) {
00028         speakf("N%D\r",x);
00029         ready();
00030     }
00031 protected :
00032     Serial     _cmd;
00033     //used by printf - supply it and printf works!
00034     virtual int _putc(int c) {
00035         _cmd.putc(c);
00036         return 0;
00037     };
00038     virtual int _getc() {
00039         return -1;
00040     };
00041 };