EasyVR Speech Recogniton and Speech Synthesis Demo

Dependencies:   mbed

Committer:
4180_1
Date:
Sun May 29 00:44:38 2011 +0000
Revision:
1:5cf36d70a7d2
Parent:
0:2fda8809cd0e

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 0:2fda8809cd0e 1 #include "mbed.h"
4180_1 0:2fda8809cd0e 2 // EasyVR Speech Recognition and Speech Synthesis Demo
4180_1 0:2fda8809cd0e 3 DigitalOut led1(LED1);
4180_1 0:2fda8809cd0e 4 DigitalOut led2(LED2);
4180_1 0:2fda8809cd0e 5 DigitalOut led3(LED3);
4180_1 0:2fda8809cd0e 6 DigitalOut led4(LED4);
4180_1 0:2fda8809cd0e 7 Serial device(p13, p14); // tx, rx
4180_1 0:2fda8809cd0e 8 Serial pc(USBTX,USBRX); //USB virtual com port can be used to watch VR command responses
4180_1 0:2fda8809cd0e 9
4180_1 0:2fda8809cd0e 10 // Function to play a sound file on speaker
4180_1 0:2fda8809cd0e 11 void speak(int num) {
4180_1 0:2fda8809cd0e 12 device.putc('w');
4180_1 0:2fda8809cd0e 13 // small delay is needed between characters
4180_1 0:2fda8809cd0e 14 wait(.001);
4180_1 1:5cf36d70a7d2 15 device.putc('A' + num/32);
4180_1 0:2fda8809cd0e 16 wait(.001);
4180_1 1:5cf36d70a7d2 17 device.putc('A' + num%32);
4180_1 0:2fda8809cd0e 18 wait(.001);
4180_1 0:2fda8809cd0e 19 device.putc('P');
4180_1 0:2fda8809cd0e 20 while (device.getc()!='o') {}
4180_1 0:2fda8809cd0e 21 wait(.25);
4180_1 0:2fda8809cd0e 22 }
4180_1 0:2fda8809cd0e 23
4180_1 0:2fda8809cd0e 24 int main() {
4180_1 0:2fda8809cd0e 25 char rchar=0;
4180_1 0:2fda8809cd0e 26 char echar=0;
4180_1 0:2fda8809cd0e 27 led1=0;
4180_1 0:2fda8809cd0e 28 led2=0;
4180_1 0:2fda8809cd0e 29 led3=0;
4180_1 0:2fda8809cd0e 30 led4=0;
4180_1 0:2fda8809cd0e 31 // wake up EasyVR
4180_1 0:2fda8809cd0e 32 device.putc('b');
4180_1 0:2fda8809cd0e 33 while (device.getc()!='o') {
4180_1 0:2fda8809cd0e 34 device.putc('b');
4180_1 0:2fda8809cd0e 35 wait(0.1);
4180_1 0:2fda8809cd0e 36 }
4180_1 0:2fda8809cd0e 37 // play reset message
4180_1 0:2fda8809cd0e 38 speak(3);
4180_1 0:2fda8809cd0e 39 // Use SD recogniton and wait for password (mbed)
4180_1 0:2fda8809cd0e 40 while (rchar!='A') {
4180_1 0:2fda8809cd0e 41 wait(.001);
4180_1 0:2fda8809cd0e 42 device.putc('d');
4180_1 0:2fda8809cd0e 43 // a small delay is needed when sending EasyVR several characters
4180_1 0:2fda8809cd0e 44 wait(.001);
4180_1 0:2fda8809cd0e 45 device.putc('B');
4180_1 0:2fda8809cd0e 46 while (device.readable()!=0) {}
4180_1 0:2fda8809cd0e 47 rchar=device.getc();
4180_1 0:2fda8809cd0e 48 pc.putc(rchar);
4180_1 0:2fda8809cd0e 49 // word recognized
4180_1 0:2fda8809cd0e 50 if (rchar=='r') {
4180_1 0:2fda8809cd0e 51 wait(.001);
4180_1 0:2fda8809cd0e 52 device.putc(' ');
4180_1 0:2fda8809cd0e 53 rchar=device.getc();
4180_1 0:2fda8809cd0e 54 pc.putc(rchar);
4180_1 0:2fda8809cd0e 55 // error
4180_1 0:2fda8809cd0e 56 } else if (rchar=='e') {
4180_1 0:2fda8809cd0e 57 wait(.001);
4180_1 0:2fda8809cd0e 58 device.putc(' ');
4180_1 0:2fda8809cd0e 59 rchar=device.getc();
4180_1 0:2fda8809cd0e 60 device.putc(' ');
4180_1 0:2fda8809cd0e 61 rchar=device.getc();
4180_1 0:2fda8809cd0e 62 }
4180_1 0:2fda8809cd0e 63 }
4180_1 0:2fda8809cd0e 64 // voice ack for password
4180_1 0:2fda8809cd0e 65 speak(5);
4180_1 0:2fda8809cd0e 66 wait(1);
4180_1 0:2fda8809cd0e 67 // loop forever waiting for number commands
4180_1 0:2fda8809cd0e 68 while (1) {
4180_1 0:2fda8809cd0e 69 // voice prompt for input - don't prompt after a timeout or error
4180_1 0:2fda8809cd0e 70 if ((rchar!='t')&&(rchar!='e')) speak(1);
4180_1 0:2fda8809cd0e 71 wait(.002);
4180_1 0:2fda8809cd0e 72 // SI recog of numbers 0..10
4180_1 0:2fda8809cd0e 73 device.putc('i');
4180_1 0:2fda8809cd0e 74 wait(.001);
4180_1 0:2fda8809cd0e 75 device.putc('D');
4180_1 0:2fda8809cd0e 76 while (device.readable()!=0) {}
4180_1 0:2fda8809cd0e 77 rchar=device.getc();
4180_1 0:2fda8809cd0e 78 pc.putc(rchar);
4180_1 0:2fda8809cd0e 79 // number was recognized
4180_1 0:2fda8809cd0e 80 if (rchar=='s') {
4180_1 0:2fda8809cd0e 81 wait(.001);
4180_1 0:2fda8809cd0e 82 device.putc(' ');
4180_1 0:2fda8809cd0e 83 rchar=device.getc();
4180_1 0:2fda8809cd0e 84 pc.putc(rchar);
4180_1 0:2fda8809cd0e 85 if (rchar=='B') led1 = !led1;
4180_1 0:2fda8809cd0e 86 if (rchar=='C') led2 = !led2;
4180_1 0:2fda8809cd0e 87 if (rchar=='D') led3 = !led3;
4180_1 0:2fda8809cd0e 88 if (rchar=='E') led4 = !led4;
4180_1 0:2fda8809cd0e 89 // voice ack
4180_1 0:2fda8809cd0e 90 speak(2);
4180_1 0:2fda8809cd0e 91 // recognition error
4180_1 0:2fda8809cd0e 92 } else if (rchar=='e') {
4180_1 0:2fda8809cd0e 93 wait(.001);
4180_1 0:2fda8809cd0e 94 device.putc(' ');
4180_1 0:2fda8809cd0e 95 echar=device.getc();
4180_1 0:2fda8809cd0e 96 device.putc(' ');
4180_1 0:2fda8809cd0e 97 echar=device.getc();
4180_1 0:2fda8809cd0e 98 // prompt user to restate command
4180_1 0:2fda8809cd0e 99 speak(4);
4180_1 0:2fda8809cd0e 100 }
4180_1 0:2fda8809cd0e 101 }
4180_1 0:2fda8809cd0e 102 }