voice recorder to make data file for the speech synthesisizer

Dependencies:   mbed

Committer:
hayama
Date:
Mon Aug 18 11:33:21 2014 +0000
Revision:
0:0e35751b8409
voice recorder to make data file for the speech synthesis

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hayama 0:0e35751b8409 1 #include "mbed.h"
hayama 0:0e35751b8409 2 #define NUMDAT 15000
hayama 0:0e35751b8409 3 #define DLY 250
hayama 0:0e35751b8409 4 float micCB;
hayama 0:0e35751b8409 5 char st[10];
hayama 0:0e35751b8409 6 short dat[NUMDAT];
hayama 0:0e35751b8409 7 int i;
hayama 0:0e35751b8409 8 int k=0;
hayama 0:0e35751b8409 9
hayama 0:0e35751b8409 10 LocalFileSystem local("local");
hayama 0:0e35751b8409 11 DigitalIn sw(p5);
hayama 0:0e35751b8409 12 AnalogIn micC(p16);
hayama 0:0e35751b8409 13 AnalogOut spOut(p18);
hayama 0:0e35751b8409 14 BusOut leds( LED4, LED3, LED2, LED1 );
hayama 0:0e35751b8409 15 Ticker timer;
hayama 0:0e35751b8409 16
hayama 0:0e35751b8409 17 void offset(){
hayama 0:0e35751b8409 18 micCB=0;
hayama 0:0e35751b8409 19 for(i=0;i<100;i++) micCB+=micC;
hayama 0:0e35751b8409 20 micCB/=100;
hayama 0:0e35751b8409 21 }
hayama 0:0e35751b8409 22
hayama 0:0e35751b8409 23 void fout(){
hayama 0:0e35751b8409 24 FILE *fp = fopen("/local/out.txt", "w");
hayama 0:0e35751b8409 25 for(i=0;i<NUMDAT; i++){
hayama 0:0e35751b8409 26 fprintf(fp,"%d\n",dat[i]);
hayama 0:0e35751b8409 27 }
hayama 0:0e35751b8409 28 fclose(fp);
hayama 0:0e35751b8409 29 }
hayama 0:0e35751b8409 30
hayama 0:0e35751b8409 31 void fin(){
hayama 0:0e35751b8409 32 FILE *fp = fopen("/local/out.txt", "r");
hayama 0:0e35751b8409 33 for(i=0;i<NUMDAT; i++){
hayama 0:0e35751b8409 34 fgets(st,10,fp);
hayama 0:0e35751b8409 35 dat[i]=atoi(st);
hayama 0:0e35751b8409 36 }
hayama 0:0e35751b8409 37 fclose(fp);
hayama 0:0e35751b8409 38 }
hayama 0:0e35751b8409 39
hayama 0:0e35751b8409 40 void record(){
hayama 0:0e35751b8409 41 for(i=0;i<NUMDAT; i++){
hayama 0:0e35751b8409 42 dat[i]=(int)((micC-micCB)*32768);
hayama 0:0e35751b8409 43 wait_us(DLY);
hayama 0:0e35751b8409 44 }
hayama 0:0e35751b8409 45 }
hayama 0:0e35751b8409 46
hayama 0:0e35751b8409 47 void speak(){
hayama 0:0e35751b8409 48 for(i=0;i<NUMDAT; i++){
hayama 0:0e35751b8409 49 spOut=((float)dat[i])/32768*10+0.5;
hayama 0:0e35751b8409 50 wait_us(DLY);
hayama 0:0e35751b8409 51 }
hayama 0:0e35751b8409 52 }
hayama 0:0e35751b8409 53
hayama 0:0e35751b8409 54
hayama 0:0e35751b8409 55 int main() {
hayama 0:0e35751b8409 56 fin();
hayama 0:0e35751b8409 57 speak();
hayama 0:0e35751b8409 58
hayama 0:0e35751b8409 59 leds=0;
hayama 0:0e35751b8409 60 offset();
hayama 0:0e35751b8409 61
hayama 0:0e35751b8409 62 while(1){
hayama 0:0e35751b8409 63 while(sw);
hayama 0:0e35751b8409 64 wait(2);
hayama 0:0e35751b8409 65 leds=1;
hayama 0:0e35751b8409 66 record();
hayama 0:0e35751b8409 67 leds=0;
hayama 0:0e35751b8409 68 wait(1);
hayama 0:0e35751b8409 69 speak();
hayama 0:0e35751b8409 70 fout();
hayama 0:0e35751b8409 71 }
hayama 0:0e35751b8409 72 }
hayama 0:0e35751b8409 73
hayama 0:0e35751b8409 74
hayama 0:0e35751b8409 75
hayama 0:0e35751b8409 76