Speech synthesisizer for Japanese. But, it's bad sounds. Please make datafile by yourself.

Dependencies:   mbed

connect PC serial port. type japanese by roma-ji, press enter then talk. Voice data is defined in header file. first numer is the length of the data, the following are voice data by 4kHz sampling, short int values.

/media/uploads/hayama/speechsynthesis.jpg

Committer:
hayama
Date:
Mon Aug 18 11:38:46 2014 +0000
Revision:
0:0a40320fda6b
Speech synthesisizer for Japanese. But, it's bad sounds. Please make datafile by yourself.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hayama 0:0a40320fda6b 1 #define NUMDAT 15000
hayama 0:0a40320fda6b 2 #define DLY 250
hayama 0:0a40320fda6b 3
hayama 0:0a40320fda6b 4 #include <string.h>
hayama 0:0a40320fda6b 5 #include "mbed.h"
hayama 0:0a40320fda6b 6 #include "voicedata.h"
hayama 0:0a40320fda6b 7
hayama 0:0a40320fda6b 8 float micCB;
hayama 0:0a40320fda6b 9 //char st[10];
hayama 0:0a40320fda6b 10 volatile short dat[NUMDAT];
hayama 0:0a40320fda6b 11 volatile int num;
hayama 0:0a40320fda6b 12 volatile int bufsize=0;
hayama 0:0a40320fda6b 13 volatile int bufDly=0;
hayama 0:0a40320fda6b 14 volatile int m=0; // buffer index
hayama 0:0a40320fda6b 15 volatile int n=0;
hayama 0:0a40320fda6b 16
hayama 0:0a40320fda6b 17 Serial pc(USBTX, USBRX); // tx, rx
hayama 0:0a40320fda6b 18 AnalogOut spOut(p18);
hayama 0:0a40320fda6b 19 BusOut leds( LED4, LED3, LED2, LED1 );
hayama 0:0a40320fda6b 20 Ticker timer;
hayama 0:0a40320fda6b 21
hayama 0:0a40320fda6b 22
hayama 0:0a40320fda6b 23 short readBuffer(){
hayama 0:0a40320fda6b 24 short tmp;
hayama 0:0a40320fda6b 25 tmp=dat[m];
hayama 0:0a40320fda6b 26 m++; if (m>(NUMDAT-1)) m=0;
hayama 0:0a40320fda6b 27 bufsize--;
hayama 0:0a40320fda6b 28 return(tmp);
hayama 0:0a40320fda6b 29 }
hayama 0:0a40320fda6b 30
hayama 0:0a40320fda6b 31 void writeBuffer(int tmp){
hayama 0:0a40320fda6b 32 while(bufsize>(NUMDAT-2));
hayama 0:0a40320fda6b 33 dat[n]=(short)tmp;
hayama 0:0a40320fda6b 34 n++; if (n>(NUMDAT-1)) n=0;
hayama 0:0a40320fda6b 35 if (bufsize==0) bufDly=5000;
hayama 0:0a40320fda6b 36 bufsize++;
hayama 0:0a40320fda6b 37 }
hayama 0:0a40320fda6b 38
hayama 0:0a40320fda6b 39
hayama 0:0a40320fda6b 40 void recvStr(char *buf){
hayama 0:0a40320fda6b 41 int i = 0;
hayama 0:0a40320fda6b 42 char c;
hayama 0:0a40320fda6b 43 leds=1;
hayama 0:0a40320fda6b 44 while (1) {
hayama 0:0a40320fda6b 45 if (pc.readable()) {
hayama 0:0a40320fda6b 46 c = pc.getc();
hayama 0:0a40320fda6b 47 pc.putc(c);
hayama 0:0a40320fda6b 48 buf[i] = c;
hayama 0:0a40320fda6b 49 if (c == 13) break;
hayama 0:0a40320fda6b 50 i++;
hayama 0:0a40320fda6b 51 }
hayama 0:0a40320fda6b 52 }
hayama 0:0a40320fda6b 53 buf[i] = '\0';
hayama 0:0a40320fda6b 54 pc.putc('\n');
hayama 0:0a40320fda6b 55 }
hayama 0:0a40320fda6b 56
hayama 0:0a40320fda6b 57
hayama 0:0a40320fda6b 58 void setVoice(int code){
hayama 0:0a40320fda6b 59 int i;
hayama 0:0a40320fda6b 60 switch(code){
hayama 0:0a40320fda6b 61 case 0: for(i=1;i<=B[0]; i++) writeBuffer(B[i]); break;
hayama 0:0a40320fda6b 62 case 1: for(i=1;i<=a[0]; i++) writeBuffer(a[i]); break;
hayama 0:0a40320fda6b 63 case 2: for(i=1;i<=ii[0]; i++) writeBuffer(ii[i]); break;
hayama 0:0a40320fda6b 64 case 3: for(i=1;i<=u[0]; i++) writeBuffer(u[i]); break;
hayama 0:0a40320fda6b 65 case 4: for(i=1;i<=e[0]; i++) writeBuffer(e[i]); break;
hayama 0:0a40320fda6b 66 case 5: for(i=1;i<=o[0]; i++) writeBuffer(o[i]); break;
hayama 0:0a40320fda6b 67 case 6: for(i=1;i<=ka[0]; i++) writeBuffer(ka[i]); break;
hayama 0:0a40320fda6b 68 case 7: for(i=1;i<=ki[0]; i++) writeBuffer(ki[i]); break;
hayama 0:0a40320fda6b 69 case 8: for(i=1;i<=ku[0]; i++) writeBuffer(ku[i]); break;
hayama 0:0a40320fda6b 70 case 9: for(i=1;i<=ke[0]; i++) writeBuffer(ke[i]); break;
hayama 0:0a40320fda6b 71 case 10: for(i=1;i<=ko[0]; i++) writeBuffer(ko[i]); break;
hayama 0:0a40320fda6b 72 case 11: for(i=1;i<=sa[0]; i++) writeBuffer(sa[i]); break;
hayama 0:0a40320fda6b 73 case 12: for(i=1;i<=si[0]; i++) writeBuffer(si[i]); break;
hayama 0:0a40320fda6b 74 case 13: for(i=1;i<=su[0]; i++) writeBuffer(su[i]); break;
hayama 0:0a40320fda6b 75 case 14: for(i=1;i<=se[0]; i++) writeBuffer(se[i]); break;
hayama 0:0a40320fda6b 76 case 15: for(i=1;i<=so[0]; i++) writeBuffer(so[i]); break;
hayama 0:0a40320fda6b 77 case 16: for(i=1;i<=ta[0]; i++) writeBuffer(ta[i]); break;
hayama 0:0a40320fda6b 78 case 17: for(i=1;i<=ti[0]; i++) writeBuffer(ti[i]); break;
hayama 0:0a40320fda6b 79 case 18: for(i=1;i<=tu[0]; i++) writeBuffer(tu[i]); break;
hayama 0:0a40320fda6b 80 case 19: for(i=1;i<=te[0]; i++) writeBuffer(te[i]); break;
hayama 0:0a40320fda6b 81 case 20: for(i=1;i<=to[0]; i++) writeBuffer(to[i]); break;
hayama 0:0a40320fda6b 82 case 21: for(i=1;i<=na[0]; i++) writeBuffer(na[i]); break;
hayama 0:0a40320fda6b 83 case 22: for(i=1;i<=ni[0]; i++) writeBuffer(ni[i]); break;
hayama 0:0a40320fda6b 84 case 23: for(i=1;i<=nu[0]; i++) writeBuffer(nu[i]); break;
hayama 0:0a40320fda6b 85 case 24: for(i=1;i<=ne[0]; i++) writeBuffer(ne[i]); break;
hayama 0:0a40320fda6b 86 case 25: for(i=1;i<=no[0]; i++) writeBuffer(no[i]); break;
hayama 0:0a40320fda6b 87 case 26: for(i=1;i<=ha[0]; i++) writeBuffer(ha[i]); break;
hayama 0:0a40320fda6b 88 case 27: for(i=1;i<=hi[0]; i++) writeBuffer(hi[i]); break;
hayama 0:0a40320fda6b 89 case 28: for(i=1;i<=hu[0]; i++) writeBuffer(hu[i]); break;
hayama 0:0a40320fda6b 90 case 29: for(i=1;i<=he[0]; i++) writeBuffer(he[i]); break;
hayama 0:0a40320fda6b 91 case 30: for(i=1;i<=ho[0]; i++) writeBuffer(ho[i]); break;
hayama 0:0a40320fda6b 92 case 31: for(i=1;i<=ma[0]; i++) writeBuffer(ma[i]); break;
hayama 0:0a40320fda6b 93 case 32: for(i=1;i<=mi[0]; i++) writeBuffer(mi[i]); break;
hayama 0:0a40320fda6b 94 case 33: for(i=1;i<=mu[0]; i++) writeBuffer(mu[i]); break;
hayama 0:0a40320fda6b 95 case 34: for(i=1;i<=me[0]; i++) writeBuffer(me[i]); break;
hayama 0:0a40320fda6b 96 case 35: for(i=1;i<=mo[0]; i++) writeBuffer(mo[i]); break;
hayama 0:0a40320fda6b 97 case 36: for(i=1;i<=ya[0]; i++) writeBuffer(ya[i]); break;
hayama 0:0a40320fda6b 98 case 37: for(i=1;i<=yu[0]; i++) writeBuffer(yu[i]); break;
hayama 0:0a40320fda6b 99 case 38: for(i=1;i<=yo[0]; i++) writeBuffer(yo[i]); break;
hayama 0:0a40320fda6b 100 case 39: for(i=1;i<=ra[0]; i++) writeBuffer(ra[i]); break;
hayama 0:0a40320fda6b 101 case 40: for(i=1;i<=ri[0]; i++) writeBuffer(ri[i]); break;
hayama 0:0a40320fda6b 102 case 41: for(i=1;i<=ru[0]; i++) writeBuffer(ru[i]); break;
hayama 0:0a40320fda6b 103 case 42: for(i=1;i<=re[0]; i++) writeBuffer(re[i]); break;
hayama 0:0a40320fda6b 104 case 43: for(i=1;i<=ro[0]; i++) writeBuffer(ro[i]); break;
hayama 0:0a40320fda6b 105 case 44: for(i=1;i<=wa[0]; i++) writeBuffer(wa[i]); break;
hayama 0:0a40320fda6b 106 case 45: for(i=1;i<=wo[0]; i++) writeBuffer(wo[i]); break;
hayama 0:0a40320fda6b 107 case 46: for(i=1;i<=nn[0]; i++) writeBuffer(nn[i]); break;
hayama 0:0a40320fda6b 108 case 47: for(i=1;i<=ga[0]; i++) writeBuffer(ga[i]); break;
hayama 0:0a40320fda6b 109 case 48: for(i=1;i<=gi[0]; i++) writeBuffer(gi[i]); break;
hayama 0:0a40320fda6b 110 case 49: for(i=1;i<=gu[0]; i++) writeBuffer(gu[i]); break;
hayama 0:0a40320fda6b 111 case 50: for(i=1;i<=ge[0]; i++) writeBuffer(ge[i]); break;
hayama 0:0a40320fda6b 112 case 51: for(i=1;i<=go[0]; i++) writeBuffer(go[i]); break;
hayama 0:0a40320fda6b 113 case 52: for(i=1;i<=za[0]; i++) writeBuffer(za[i]); break;
hayama 0:0a40320fda6b 114 case 53: for(i=1;i<=zi[0]; i++) writeBuffer(zi[i]); break;
hayama 0:0a40320fda6b 115 case 54: for(i=1;i<=zu[0]; i++) writeBuffer(zu[i]); break;
hayama 0:0a40320fda6b 116 case 55: for(i=1;i<=ze[0]; i++) writeBuffer(ze[i]); break;
hayama 0:0a40320fda6b 117 case 56: for(i=1;i<=zo[0]; i++) writeBuffer(zo[i]); break;
hayama 0:0a40320fda6b 118 case 57: for(i=1;i<=da[0]; i++) writeBuffer(da[i]); break;
hayama 0:0a40320fda6b 119 case 58: for(i=1;i<=di[0]; i++) writeBuffer(di[i]); break;
hayama 0:0a40320fda6b 120 case 59: for(i=1;i<=du[0]; i++) writeBuffer(du[i]); break;
hayama 0:0a40320fda6b 121 case 60: for(i=1;i<=de[0]; i++) writeBuffer(de[i]); break;
hayama 0:0a40320fda6b 122 case 61: for(i=1;i<=dho[0]; i++) writeBuffer(dho[i]); break;
hayama 0:0a40320fda6b 123 case 62: for(i=1;i<=ba[0]; i++) writeBuffer(ba[i]); break;
hayama 0:0a40320fda6b 124 case 63: for(i=1;i<=bi[0]; i++) writeBuffer(bi[i]); break;
hayama 0:0a40320fda6b 125 case 64: for(i=1;i<=bu[0]; i++) writeBuffer(bu[i]); break;
hayama 0:0a40320fda6b 126 case 65: for(i=1;i<=be[0]; i++) writeBuffer(be[i]); break;
hayama 0:0a40320fda6b 127 case 66: for(i=1;i<=bo[0]; i++) writeBuffer(bo[i]); break;
hayama 0:0a40320fda6b 128 case 67: for(i=1;i<=pa[0]; i++) writeBuffer(pa[i]); break;
hayama 0:0a40320fda6b 129 case 68: for(i=1;i<=pi[0]; i++) writeBuffer(pi[i]); break;
hayama 0:0a40320fda6b 130 case 69: for(i=1;i<=pu[0]; i++) writeBuffer(pu[i]); break;
hayama 0:0a40320fda6b 131 case 70: for(i=1;i<=pe[0]; i++) writeBuffer(pe[i]); break;
hayama 0:0a40320fda6b 132 case 71: for(i=1;i<=po[0]; i++) writeBuffer(po[i]); break;
hayama 0:0a40320fda6b 133 case 72: for(i=1;i<=kya[0]; i++) writeBuffer(kya[i]); break;
hayama 0:0a40320fda6b 134 case 73: for(i=1;i<=kyu[0]; i++) writeBuffer(kyu[i]); break;
hayama 0:0a40320fda6b 135 case 74: for(i=1;i<=kyo[0]; i++) writeBuffer(kyo[i]); break;
hayama 0:0a40320fda6b 136 case 75: for(i=1;i<=sya[0]; i++) writeBuffer(sya[i]); break;
hayama 0:0a40320fda6b 137 case 76: for(i=1;i<=syu[0]; i++) writeBuffer(syu[i]); break;
hayama 0:0a40320fda6b 138 case 77: for(i=1;i<=syo[0]; i++) writeBuffer(syo[i]); break;
hayama 0:0a40320fda6b 139 case 78: for(i=1;i<=tya[0]; i++) writeBuffer(tya[i]); break;
hayama 0:0a40320fda6b 140 case 79: for(i=1;i<=tyu[0]; i++) writeBuffer(tyu[i]); break;
hayama 0:0a40320fda6b 141 case 80: for(i=1;i<=tyo[0]; i++) writeBuffer(tyo[i]); break;
hayama 0:0a40320fda6b 142 case 81: for(i=1;i<=nya[0]; i++) writeBuffer(nya[i]); break;
hayama 0:0a40320fda6b 143 case 82: for(i=1;i<=nyu[0]; i++) writeBuffer(nyu[i]); break;
hayama 0:0a40320fda6b 144 case 83: for(i=1;i<=nyo[0]; i++) writeBuffer(nyo[i]); break;
hayama 0:0a40320fda6b 145 case 84: for(i=1;i<=hya[0]; i++) writeBuffer(hya[i]); break;
hayama 0:0a40320fda6b 146 case 85: for(i=1;i<=hyu[0]; i++) writeBuffer(hyu[i]); break;
hayama 0:0a40320fda6b 147 case 86: for(i=1;i<=hyo[0]; i++) writeBuffer(hyo[i]); break;
hayama 0:0a40320fda6b 148 case 87: for(i=1;i<=mya[0]; i++) writeBuffer(mya[i]); break;
hayama 0:0a40320fda6b 149 case 88: for(i=1;i<=myu[0]; i++) writeBuffer(myu[i]); break;
hayama 0:0a40320fda6b 150 case 89: for(i=1;i<=myo[0]; i++) writeBuffer(myo[i]); break;
hayama 0:0a40320fda6b 151 case 90: for(i=1;i<=gya[0]; i++) writeBuffer(gya[i]); break;
hayama 0:0a40320fda6b 152 case 91: for(i=1;i<=gyu[0]; i++) writeBuffer(gyu[i]); break;
hayama 0:0a40320fda6b 153 case 92: for(i=1;i<=gyo[0]; i++) writeBuffer(gyo[i]); break;
hayama 0:0a40320fda6b 154 case 93: for(i=1;i<=jya[0]; i++) writeBuffer(jya[i]); break;
hayama 0:0a40320fda6b 155 case 94: for(i=1;i<=jyu[0]; i++) writeBuffer(jyu[i]); break;
hayama 0:0a40320fda6b 156 case 95: for(i=1;i<=jyo[0]; i++) writeBuffer(jyo[i]); break;
hayama 0:0a40320fda6b 157 case 96: for(i=1;i<=bya[0]; i++) writeBuffer(bya[i]); break;
hayama 0:0a40320fda6b 158 case 97: for(i=1;i<=byu[0]; i++) writeBuffer(byu[i]); break;
hayama 0:0a40320fda6b 159 case 98: for(i=1;i<=byo[0]; i++) writeBuffer(byo[i]); break;
hayama 0:0a40320fda6b 160 case 99: for(i=1;i<=pya[0]; i++) writeBuffer(pya[i]); break;
hayama 0:0a40320fda6b 161 case 100: for(i=1;i<=pyu[0]; i++) writeBuffer(pyu[i]); break;
hayama 0:0a40320fda6b 162 case 101: for(i=1;i<=pyo[0]; i++) writeBuffer(pyo[i]); break;
hayama 0:0a40320fda6b 163 }
hayama 0:0a40320fda6b 164 }
hayama 0:0a40320fda6b 165
hayama 0:0a40320fda6b 166 void errVoice(){
hayama 0:0a40320fda6b 167 setVoice(0);
hayama 0:0a40320fda6b 168 setVoice(4);
hayama 0:0a40320fda6b 169 setVoice(39);
hayama 0:0a40320fda6b 170 //setVoice(1);
hayama 0:0a40320fda6b 171 }
hayama 0:0a40320fda6b 172
hayama 0:0a40320fda6b 173 void speech(){
hayama 0:0a40320fda6b 174 short tmp;
hayama 0:0a40320fda6b 175 if (bufDly>0){
hayama 0:0a40320fda6b 176 bufDly--;
hayama 0:0a40320fda6b 177 return;
hayama 0:0a40320fda6b 178 }
hayama 0:0a40320fda6b 179 if (bufsize>0){
hayama 0:0a40320fda6b 180 tmp=readBuffer();
hayama 0:0a40320fda6b 181 spOut=(float)tmp/32768*10+0.5;
hayama 0:0a40320fda6b 182 }
hayama 0:0a40320fda6b 183 }
hayama 0:0a40320fda6b 184
hayama 0:0a40320fda6b 185 int main() {
hayama 0:0a40320fda6b 186 int i,k,len;
hayama 0:0a40320fda6b 187 timer.attach_us(speech,250);
hayama 0:0a40320fda6b 188
hayama 0:0a40320fda6b 189 /*
hayama 0:0a40320fda6b 190 // test voice output
hayama 0:0a40320fda6b 191 for (i=1;i<102;i++) setVoice(i);
hayama 0:0a40320fda6b 192 */
hayama 0:0a40320fda6b 193
hayama 0:0a40320fda6b 194 while(1){
hayama 0:0a40320fda6b 195 char str[20];
hayama 0:0a40320fda6b 196 recvStr(str);
hayama 0:0a40320fda6b 197 len=strlen(str);
hayama 0:0a40320fda6b 198 while(strlen(str)!=0){
hayama 0:0a40320fda6b 199 for(i=0;i<102;i++){
hayama 0:0a40320fda6b 200 if (strstr(str,voice[i])==str){
hayama 0:0a40320fda6b 201 k=strlen(voice[i]);
hayama 0:0a40320fda6b 202 setVoice(i);
hayama 0:0a40320fda6b 203 strcpy(str, &str[k]);
hayama 0:0a40320fda6b 204 break;
hayama 0:0a40320fda6b 205 }
hayama 0:0a40320fda6b 206 }
hayama 0:0a40320fda6b 207 if (i==102){
hayama 0:0a40320fda6b 208 errVoice();
hayama 0:0a40320fda6b 209 break;
hayama 0:0a40320fda6b 210 }
hayama 0:0a40320fda6b 211 }
hayama 0:0a40320fda6b 212 }
hayama 0:0a40320fda6b 213 }
hayama 0:0a40320fda6b 214
hayama 0:0a40320fda6b 215
hayama 0:0a40320fda6b 216
hayama 0:0a40320fda6b 217
hayama 0:0a40320fda6b 218