EasyVR Speech Recogniton and Speech Synthesis Demo

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 // EasyVR Speech Recognition and Speech Synthesis Demo
00003 DigitalOut led1(LED1);
00004 DigitalOut led2(LED2);
00005 DigitalOut led3(LED3);
00006 DigitalOut led4(LED4);
00007 Serial device(p13, p14);  // tx, rx
00008 Serial pc(USBTX,USBRX); //USB virtual com port can be used to watch VR command responses
00009 
00010 // Function to play a sound file on speaker
00011 void speak(int num) {
00012     device.putc('w');
00013     // small delay is needed between characters
00014     wait(.001);
00015     device.putc('A' + num/32);
00016     wait(.001);
00017     device.putc('A' + num%32);
00018     wait(.001);
00019     device.putc('P');
00020     while (device.getc()!='o') {}
00021     wait(.25);
00022 }
00023 
00024 int main() {
00025     char rchar=0;
00026     char echar=0;
00027     led1=0;
00028     led2=0;
00029     led3=0;
00030     led4=0;
00031 // wake up EasyVR
00032     device.putc('b');
00033     while (device.getc()!='o') {
00034         device.putc('b');
00035         wait(0.1);
00036     }
00037     // play reset message
00038     speak(3);
00039 // Use SD recogniton and wait for password (mbed)
00040     while (rchar!='A') {
00041         wait(.001);
00042         device.putc('d');
00043 // a small delay is needed when sending EasyVR several characters
00044         wait(.001);
00045         device.putc('B');
00046         while (device.readable()!=0) {}
00047         rchar=device.getc();
00048         pc.putc(rchar);
00049         // word recognized
00050         if (rchar=='r') {
00051             wait(.001);
00052             device.putc(' ');
00053             rchar=device.getc();
00054             pc.putc(rchar);
00055         // error
00056         } else if (rchar=='e') {
00057             wait(.001);
00058             device.putc(' ');
00059             rchar=device.getc();
00060             device.putc(' ');
00061             rchar=device.getc();
00062         }
00063     }
00064 // voice ack for password
00065     speak(5);
00066     wait(1);
00067 // loop forever waiting for number commands
00068     while (1) {
00069     // voice prompt for input - don't prompt after a timeout or error
00070         if ((rchar!='t')&&(rchar!='e')) speak(1);
00071         wait(.002);
00072     // SI recog of numbers 0..10
00073         device.putc('i');
00074         wait(.001);
00075         device.putc('D');
00076         while (device.readable()!=0) {}
00077         rchar=device.getc();
00078         pc.putc(rchar);
00079     // number was recognized
00080         if (rchar=='s') {
00081             wait(.001);
00082             device.putc(' ');
00083             rchar=device.getc();
00084             pc.putc(rchar);
00085             if (rchar=='B') led1 = !led1;
00086             if (rchar=='C') led2 = !led2;
00087             if (rchar=='D') led3 = !led3;
00088             if (rchar=='E') led4 = !led4;
00089             // voice ack
00090             speak(2);
00091     // recognition error
00092         } else if (rchar=='e') {
00093             wait(.001);
00094             device.putc(' ');
00095             echar=device.getc();
00096             device.putc(' ');
00097             echar=device.getc();
00098             // prompt user to restate command
00099             speak(4);
00100         }
00101     }
00102 }