Kiyoteru Hayama
/
VoiceRecorder_for_datafile
voice recorder to make data file for the speech synthesisizer
Revision 0:0e35751b8409, committed 2014-08-18
- Comitter:
- hayama
- Date:
- Mon Aug 18 11:33:21 2014 +0000
- Commit message:
- voice recorder to make data file for the speech synthesis
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 0e35751b8409 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Aug 18 11:33:21 2014 +0000 @@ -0,0 +1,76 @@ +#include "mbed.h" +#define NUMDAT 15000 +#define DLY 250 +float micCB; +char st[10]; +short dat[NUMDAT]; +int i; +int k=0; + +LocalFileSystem local("local"); +DigitalIn sw(p5); +AnalogIn micC(p16); +AnalogOut spOut(p18); +BusOut leds( LED4, LED3, LED2, LED1 ); +Ticker timer; + +void offset(){ + micCB=0; + for(i=0;i<100;i++) micCB+=micC; + micCB/=100; +} + +void fout(){ + FILE *fp = fopen("/local/out.txt", "w"); + for(i=0;i<NUMDAT; i++){ + fprintf(fp,"%d\n",dat[i]); + } + fclose(fp); +} + +void fin(){ + FILE *fp = fopen("/local/out.txt", "r"); + for(i=0;i<NUMDAT; i++){ + fgets(st,10,fp); + dat[i]=atoi(st); + } + fclose(fp); +} + +void record(){ + for(i=0;i<NUMDAT; i++){ + dat[i]=(int)((micC-micCB)*32768); + wait_us(DLY); + } +} + +void speak(){ + for(i=0;i<NUMDAT; i++){ + spOut=((float)dat[i])/32768*10+0.5; + wait_us(DLY); + } +} + + +int main() { + fin(); + speak(); + + leds=0; + offset(); + + while(1){ + while(sw); + wait(2); + leds=1; + record(); + leds=0; + wait(1); + speak(); + fout(); + } +} + + + +
diff -r 000000000000 -r 0e35751b8409 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Aug 18 11:33:21 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae \ No newline at end of file