eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

synth_mbrola.c 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /*
  2. * Copyright (C) 2005 to 2013 by Jonathan Duddington
  3. * email: [email protected]
  4. * Copyright (C) 2015 Reece H. Dunn
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see: <http://www.gnu.org/licenses/>.
  18. */
  19. #include "config.h"
  20. #include <stdio.h>
  21. #include <ctype.h>
  22. #include <wctype.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <math.h>
  26. #if HAVE_STDINT_H
  27. #include <stdint.h>
  28. #endif
  29. #include "speak_lib.h"
  30. #include "speech.h"
  31. #include "phoneme.h"
  32. #include "synthesize.h"
  33. #include "translate.h"
  34. #include "voice.h"
  35. #ifdef INCLUDE_MBROLA
  36. extern int Read4Bytes(FILE *f);
  37. extern void SetPitch2(voice_t *voice, int pitch1, int pitch2, int *pitch_base, int *pitch_range);
  38. extern unsigned char *outbuf;
  39. #ifndef PLATFORM_WINDOWS
  40. #include "mbrowrap.h"
  41. #else
  42. #include <windows.h>
  43. typedef void (WINAPI *PROCVV)(void);
  44. typedef void (WINAPI *PROCVI)(int);
  45. typedef void (WINAPI *PROCVF)(float);
  46. typedef int (WINAPI *PROCIV)();
  47. typedef int (WINAPI *PROCIC)(char *);
  48. typedef int (WINAPI *PROCISI)(short *,int);
  49. typedef char* (WINAPI *PROCVCI)(char *,int);
  50. PROCIC init_MBR;
  51. PROCIC write_MBR;
  52. PROCIV flush_MBR;
  53. PROCISI read_MBR;
  54. PROCVV close_MBR;
  55. PROCVV reset_MBR;
  56. PROCIV lastError_MBR;
  57. PROCVCI lastErrorStr_MBR;
  58. PROCVI setNoError_MBR;
  59. PROCIV getFreq_MBR;
  60. PROCVF setVolumeRatio_MBR;
  61. HINSTANCE hinstDllMBR = NULL;
  62. BOOL load_MBR()
  63. {
  64. if(hinstDllMBR != NULL)
  65. return TRUE; // already loaded
  66. if ((hinstDllMBR=LoadLibraryA("mbrola.dll")) == 0)
  67. return FALSE;
  68. init_MBR =(PROCIC) GetProcAddress(hinstDllMBR,"init_MBR");
  69. write_MBR =(PROCIC) GetProcAddress(hinstDllMBR,"write_MBR");
  70. flush_MBR =(PROCIV) GetProcAddress(hinstDllMBR,"flush_MBR");
  71. read_MBR =(PROCISI) GetProcAddress(hinstDllMBR,"read_MBR");
  72. close_MBR =(PROCVV) GetProcAddress(hinstDllMBR,"close_MBR");
  73. reset_MBR =(PROCVV) GetProcAddress(hinstDllMBR,"reset_MBR");
  74. lastError_MBR =(PROCIV) GetProcAddress(hinstDllMBR,"lastError_MBR");
  75. lastErrorStr_MBR =(PROCVCI) GetProcAddress(hinstDllMBR,"lastErrorStr_MBR");
  76. setNoError_MBR =(PROCVI) GetProcAddress(hinstDllMBR,"setNoError_MBR");
  77. setVolumeRatio_MBR =(PROCVF) GetProcAddress(hinstDllMBR,"setVolumeRatio_MBR");
  78. return TRUE;
  79. }
  80. void unload_MBR()
  81. {
  82. if (hinstDllMBR)
  83. {
  84. FreeLibrary (hinstDllMBR);
  85. hinstDllMBR=NULL;
  86. }
  87. }
  88. #endif // windows
  89. static MBROLA_TAB *mbrola_tab = NULL;
  90. static int mbrola_control = 0;
  91. static int mbr_name_prefix = 0;
  92. espeak_ERROR LoadMbrolaTable(const char *mbrola_voice, const char *phtrans, int *srate)
  93. {
  94. // Load a phoneme name translation table from espeak-data/mbrola
  95. int size;
  96. int ix;
  97. int *pw;
  98. FILE *f_in;
  99. char path[sizeof(path_home)+15];
  100. mbrola_name[0] = 0;
  101. mbrola_delay = 0;
  102. mbr_name_prefix = 0;
  103. if(mbrola_voice == NULL)
  104. {
  105. samplerate = samplerate_native;
  106. SetParameter(espeakVOICETYPE,0,0);
  107. return(EE_OK);
  108. }
  109. sprintf(path,"%s/mbrola/%s",path_home,mbrola_voice);
  110. #ifdef PLATFORM_POSIX
  111. // if not found, then also look in
  112. // usr/share/mbrola/xx, /usr/share/mbrola/xx/xx, /usr/share/mbrola/voices/xx
  113. if(GetFileLength(path) <= 0)
  114. {
  115. sprintf(path,"/usr/share/mbrola/%s",mbrola_voice);
  116. if(GetFileLength(path) <= 0)
  117. {
  118. sprintf(path,"/usr/share/mbrola/%s/%s",mbrola_voice,mbrola_voice);
  119. if(GetFileLength(path) <= 0)
  120. {
  121. sprintf(path,"/usr/share/mbrola/voices/%s",mbrola_voice);
  122. }
  123. }
  124. }
  125. close_MBR();
  126. #endif
  127. #ifdef PLATFORM_WINDOWS
  128. if(load_MBR() == FALSE) // load mbrola.dll
  129. {
  130. fprintf(stderr, "Can't load mbrola.dll\n");
  131. return(EE_INTERNAL_ERROR);
  132. }
  133. #endif
  134. if(init_MBR(path) != 0) // initialise the required mbrola voice
  135. return(EE_NOT_FOUND);
  136. setNoError_MBR(1); // don't stop on phoneme errors
  137. // read eSpeak's mbrola phoneme translation data, eg. en1_phtrans
  138. sprintf(path,"%s/mbrola_ph/%s",path_home,phtrans);
  139. size = GetFileLength(path);
  140. if((f_in = fopen(path,"rb")) == NULL) {
  141. close_MBR();
  142. return(EE_NOT_FOUND);
  143. }
  144. if((mbrola_tab = (MBROLA_TAB *)realloc(mbrola_tab,size)) == NULL)
  145. {
  146. fclose(f_in);
  147. close_MBR();
  148. return(EE_INTERNAL_ERROR);
  149. }
  150. mbrola_control = Read4Bytes(f_in);
  151. pw = (int *)mbrola_tab;
  152. for(ix=4; ix<size; ix+=4)
  153. {
  154. *pw++ = Read4Bytes(f_in);
  155. }
  156. size = fread(mbrola_tab,1,size,f_in);
  157. fclose(f_in);
  158. setVolumeRatio_MBR((float)(mbrola_control & 0xff) /16.0f);
  159. samplerate = *srate = getFreq_MBR();
  160. if(*srate == 22050)
  161. SetParameter(espeakVOICETYPE,0,0);
  162. else
  163. SetParameter(espeakVOICETYPE,1,0);
  164. strcpy(mbrola_name,mbrola_voice);
  165. mbrola_delay = 1000; // improve synchronization of events
  166. return(EE_OK);
  167. }
  168. static int GetMbrName(PHONEME_LIST *plist, PHONEME_TAB *ph, PHONEME_TAB *ph_prev, PHONEME_TAB *ph_next, int *name2, int *split, int *control)
  169. {
  170. // Look up a phoneme in the mbrola phoneme name translation table
  171. // It may give none, 1, or 2 mbrola phonemes
  172. MBROLA_TAB *pr;
  173. PHONEME_TAB *other_ph;
  174. int found = 0;
  175. static int mnem;
  176. // control
  177. // bit 0 skip the next phoneme
  178. // bit 1 match this and Previous phoneme
  179. // bit 2 only at the start of a word
  180. // bit 3 don't match two phonemes across a word boundary
  181. // bit 4 add this phoneme name as a prefix to the next phoneme name (used for de4 phoneme prefix '?')
  182. // bit 5 only in stressed syllable
  183. // bit 6 only at the end of a word
  184. *name2=0;
  185. *split=0;
  186. *control=0;
  187. mnem = ph->mnemonic;
  188. pr = mbrola_tab;
  189. while(pr->name != 0)
  190. {
  191. if(mnem == pr->name)
  192. {
  193. if(pr->next_phoneme == 0)
  194. found = 1;
  195. else
  196. if((pr->next_phoneme == ':') && (plist->synthflags & SFLAG_LENGTHEN))
  197. {
  198. found = 1;
  199. }
  200. else
  201. {
  202. if(pr->control & 2)
  203. other_ph = ph_prev;
  204. else
  205. if((pr->control & 8) && ((plist+1)->newword))
  206. other_ph = phoneme_tab[phPAUSE]; // don't match the next phoneme over a word boundary
  207. else
  208. other_ph = ph_next;
  209. if((pr->next_phoneme == other_ph->mnemonic) ||
  210. ((pr->next_phoneme == 2) && (other_ph->type == phVOWEL)) ||
  211. ((pr->next_phoneme == '_') && (other_ph->type == phPAUSE)))
  212. {
  213. found = 1;
  214. }
  215. }
  216. if((pr->control & 4) && (plist->newword == 0)) // only at start of word
  217. found = 0;
  218. if((pr->control & 0x40) && (plist[1].newword == 0)) // only at the end of a word
  219. found = 0;
  220. if((pr->control & 0x20) && (plist->stresslevel < plist->wordstress))
  221. found = 0; // only in stressed syllables
  222. if(found)
  223. {
  224. *name2 = pr->mbr_name2;
  225. *split = pr->percent;
  226. *control = pr->control;
  227. if(pr->control & 0x10)
  228. {
  229. mbr_name_prefix = pr->mbr_name;
  230. return(0);
  231. }
  232. mnem = pr->mbr_name;
  233. break;
  234. }
  235. }
  236. pr++;
  237. }
  238. if(mbr_name_prefix != 0)
  239. {
  240. mnem = (mnem << 8) | (mbr_name_prefix & 0xff);
  241. }
  242. mbr_name_prefix = 0;
  243. return(mnem);
  244. }
  245. static char *WritePitch(int env, int pitch1, int pitch2, int split, int final)
  246. {
  247. // final=1: only give the final pitch value.
  248. int x;
  249. int ix;
  250. int pitch_base;
  251. int pitch_range;
  252. int p1,p2,p_end;
  253. unsigned char *pitch_env;
  254. int max = -1;
  255. int min = 999;
  256. int y_max=0;
  257. int y_min=0;
  258. int env100 = 80; // apply the pitch change only over this proportion of the mbrola phoneme(s)
  259. int y2;
  260. int y[4];
  261. int env_split;
  262. char buf[50];
  263. static char output[50];
  264. output[0] = 0;
  265. pitch_env = envelope_data[env];
  266. SetPitch2(voice, pitch1, pitch2, &pitch_base, &pitch_range);
  267. env_split = (split * 128)/100;
  268. if(env_split < 0)
  269. env_split = 0-env_split;
  270. // find max and min in the pitch envelope
  271. for(x=0; x<128; x++)
  272. {
  273. if(pitch_env[x] > max)
  274. {
  275. max = pitch_env[x];
  276. y_max = x;
  277. }
  278. if(pitch_env[x] < min)
  279. {
  280. min = pitch_env[x];
  281. y_min = x;
  282. }
  283. }
  284. // set an additional pitch point half way through the phoneme.
  285. // but look for a maximum or a minimum and use that instead
  286. y[2] = 64;
  287. if((y_max > 0) && (y_max < 127))
  288. {
  289. y[2] = y_max;
  290. }
  291. if((y_min > 0) && (y_min < 127))
  292. {
  293. y[2] = y_min;
  294. }
  295. y[1] = y[2] / 2;
  296. y[3] = y[2] + (127 - y[2])/2;
  297. // set initial pitch
  298. p1 = ((pitch_env[0]*pitch_range)>>8) + pitch_base; // Hz << 12
  299. p_end = ((pitch_env[127]*pitch_range)>>8) + pitch_base;
  300. if(split >= 0)
  301. {
  302. sprintf(buf," 0 %d",p1/4096);
  303. strcat(output,buf);
  304. }
  305. // don't use intermediate pitch points for linear rise and fall
  306. if(env > 1)
  307. {
  308. for(ix=1; ix<4; ix++)
  309. {
  310. p2 = ((pitch_env[y[ix]]*pitch_range)>>8) + pitch_base;
  311. if(split > 0)
  312. {
  313. y2 = (y[ix] * env100)/env_split;
  314. }
  315. else
  316. if(split < 0)
  317. {
  318. y2 = ((y[ix]-env_split) * env100)/env_split;
  319. }
  320. else
  321. {
  322. y2 = (y[ix] * env100)/128;
  323. }
  324. if((y2 > 0) && (y2 <= env100))
  325. {
  326. sprintf(buf," %d %d",y2,p2/4096);
  327. strcat(output,buf);
  328. }
  329. }
  330. }
  331. p_end = p_end/4096;
  332. if(split <= 0)
  333. {
  334. sprintf(buf," %d %d",env100,p_end);
  335. strcat(output,buf);
  336. }
  337. if(env100 < 100)
  338. {
  339. sprintf(buf," %d %d",100,p_end);
  340. strcat(output,buf);
  341. }
  342. strcat(output,"\n");
  343. if(final)
  344. sprintf(output,"\t100 %d\n",p_end);
  345. return(output);
  346. }
  347. int MbrolaTranslate(PHONEME_LIST *plist, int n_phonemes, int resume, FILE *f_mbrola)
  348. {
  349. // Generate a mbrola pho file
  350. unsigned int name;
  351. int len;
  352. int len1;
  353. PHONEME_TAB *ph;
  354. PHONEME_TAB *ph_next;
  355. PHONEME_TAB *ph_prev;
  356. PHONEME_LIST *p;
  357. PHONEME_LIST *next;
  358. PHONEME_DATA phdata;
  359. FMT_PARAMS fmtp;
  360. int pause = 0;
  361. int released;
  362. int name2;
  363. int control;
  364. int done;
  365. int len_percent;
  366. const char *final_pitch;
  367. char *ptr;
  368. char mbr_buf[120];
  369. static int phix;
  370. static int embedded_ix;
  371. static int word_count;
  372. if (!resume) {
  373. phix = 1;
  374. embedded_ix = 0;
  375. word_count = 0;
  376. }
  377. while (phix < n_phonemes)
  378. {
  379. if (WcmdqFree() < MIN_WCMDQ)
  380. return 1;
  381. ptr = mbr_buf;
  382. p = &plist[phix];
  383. next = &plist[phix+1];
  384. ph = p->ph;
  385. ph_prev = plist[phix-1].ph;
  386. ph_next = plist[phix+1].ph;
  387. if(p->synthflags & SFLAG_EMBEDDED)
  388. {
  389. DoEmbedded(&embedded_ix, p->sourceix);
  390. }
  391. if(p->newword & 4)
  392. DoMarker(espeakEVENT_SENTENCE, (p->sourceix & 0x7ff) + clause_start_char, 0, count_sentences);
  393. if(p->newword & 1)
  394. DoMarker(espeakEVENT_WORD, (p->sourceix & 0x7ff) + clause_start_char, p->sourceix >> 11, clause_start_word + word_count++);
  395. name = GetMbrName(p,ph,ph_prev,ph_next,&name2,&len_percent,&control);
  396. if(control & 1)
  397. phix++;
  398. if(name == 0) {
  399. phix++;
  400. continue; // ignore this phoneme
  401. }
  402. if((ph->type == phPAUSE) && (name == ph->mnemonic))
  403. {
  404. // a pause phoneme, which has not been changed by the translation
  405. name = '_';
  406. len = (p->length * speed.pause_factor)/256;
  407. if(len == 0)
  408. len = 1;
  409. }
  410. else
  411. len = (80 * speed.wav_factor)/256;
  412. if(ph->code != phonEND_WORD)
  413. {
  414. char phoneme_name[16];
  415. WritePhMnemonic(phoneme_name, p->ph, p, option_phoneme_events & espeakINITIALIZE_PHONEME_IPA, NULL);
  416. DoPhonemeMarker(espeakEVENT_PHONEME, (p->sourceix & 0x7ff) + clause_start_char, 0, phoneme_name);
  417. }
  418. ptr += sprintf(ptr,"%s\t",WordToString(name));
  419. if(name2 == '_')
  420. {
  421. // add a pause after this phoneme
  422. pause = len_percent;
  423. name2 = 0;
  424. }
  425. done = 0;
  426. final_pitch = "";
  427. switch(ph->type)
  428. {
  429. case phVOWEL:
  430. len = ph->std_length;
  431. if(p->synthflags & SFLAG_LENGTHEN)
  432. len += phoneme_tab[phonLENGTHEN]->std_length; // phoneme was followed by an extra : symbol
  433. if(ph_next->type == phPAUSE)
  434. len += 50; // lengthen vowels before a pause
  435. len = (len * p->length)/256;
  436. if(name2 == 0)
  437. {
  438. char *pitch = WritePitch(p->env,p->pitch1,p->pitch2,0,0);
  439. ptr += sprintf(ptr,"%d\t%s", len, pitch);
  440. }
  441. else
  442. {
  443. char *pitch;
  444. pitch = WritePitch(p->env,p->pitch1,p->pitch2,len_percent,0);
  445. len1 = (len * len_percent)/100;
  446. ptr += sprintf(ptr,"%d\t%s", len1, pitch);
  447. pitch = WritePitch(p->env,p->pitch1,p->pitch2,-len_percent,0);
  448. ptr += sprintf(ptr,"%s\t%d\t%s", WordToString(name2), len-len1, pitch);
  449. }
  450. done = 1;
  451. break;
  452. case phSTOP:
  453. released = 0;
  454. if(next->type==phVOWEL) released = 1;
  455. if(next->type==phLIQUID && !next->newword) released = 1;
  456. if(released == 0)
  457. p->synthflags |= SFLAG_NEXT_PAUSE;
  458. InterpretPhoneme(NULL, 0, p, &phdata, NULL);
  459. len = DoSample3(&phdata, 0, -1);
  460. len = (len * 1000)/samplerate; // convert to mS
  461. len += PauseLength(p->prepause,1);
  462. break;
  463. case phVSTOP:
  464. len = (80 * speed.wav_factor)/256;
  465. break;
  466. case phFRICATIVE:
  467. len = 0;
  468. InterpretPhoneme(NULL, 0, p, &phdata, NULL);
  469. if(p->synthflags & SFLAG_LENGTHEN)
  470. len = DoSample3(&phdata, p->length, -1); // play it twice for [s:] etc.
  471. len += DoSample3(&phdata, p->length, -1);
  472. len = (len * 1000)/samplerate; // convert to mS
  473. break;
  474. case phNASAL:
  475. if(next->type != phVOWEL)
  476. {
  477. memset(&fmtp, 0, sizeof(fmtp));
  478. InterpretPhoneme(NULL, 0, p, &phdata, NULL);
  479. fmtp.fmt_addr = phdata.sound_addr[pd_FMT];
  480. len = DoSpect2(p->ph, 0, &fmtp, p, -1);
  481. len = (len * 1000)/samplerate;
  482. if(next->type == phPAUSE)
  483. len += 50;
  484. final_pitch = WritePitch(p->env,p->pitch1,p->pitch2,0,1);
  485. }
  486. break;
  487. case phLIQUID:
  488. if(next->type == phPAUSE)
  489. {
  490. len += 50;
  491. final_pitch = WritePitch(p->env,p->pitch1,p->pitch2,0,1);
  492. }
  493. break;
  494. }
  495. if(!done)
  496. {
  497. if(name2 != 0)
  498. {
  499. len1 = (len * len_percent)/100;
  500. ptr += sprintf(ptr,"%d\n%s\t",len1,WordToString(name2));
  501. len -= len1;
  502. }
  503. ptr += sprintf(ptr,"%d%s\n",len,final_pitch);
  504. }
  505. if(pause)
  506. {
  507. len += PauseLength(pause,0);
  508. ptr += sprintf(ptr,"_ \t%d\n",PauseLength(pause,0));
  509. pause = 0;
  510. }
  511. if(f_mbrola)
  512. {
  513. fwrite(mbr_buf,1,(ptr-mbr_buf),f_mbrola); // write .pho to a file
  514. }
  515. else
  516. {
  517. int res = write_MBR(mbr_buf);
  518. if (res < 0)
  519. return 0; /* don't get stuck on error */
  520. if (res == 0)
  521. return 1;
  522. wcmdq[wcmdq_tail][0] = WCMD_MBROLA_DATA;
  523. wcmdq[wcmdq_tail][1] = len;
  524. WcmdqInc();
  525. }
  526. phix++;
  527. }
  528. if(!f_mbrola)
  529. {
  530. flush_MBR();
  531. // flush the mbrola output buffer
  532. wcmdq[wcmdq_tail][0] = WCMD_MBROLA_DATA;
  533. wcmdq[wcmdq_tail][1] = 500;
  534. WcmdqInc();
  535. }
  536. return 0;
  537. }
  538. int MbrolaGenerate(PHONEME_LIST *phoneme_list, int *n_ph, int resume)
  539. {
  540. FILE *f_mbrola = NULL;
  541. if(*n_ph == 0)
  542. return(0);
  543. if(option_phonemes & espeakPHONEMES_MBROLA)
  544. {
  545. // send mbrola data to a file, not to the mbrola library
  546. f_mbrola = f_trans;
  547. }
  548. int again = MbrolaTranslate(phoneme_list, *n_ph, resume, f_mbrola);
  549. if (!again)
  550. *n_ph = 0;
  551. return again;
  552. }
  553. int MbrolaFill(int length, int resume, int amplitude)
  554. {
  555. // Read audio data from Mbrola (length is in millisecs)
  556. static int n_samples;
  557. int req_samples, result;
  558. int ix;
  559. short value16;
  560. int value;
  561. if (!resume)
  562. n_samples = samplerate * length / 1000;
  563. req_samples = (out_end - out_ptr)/2;
  564. if (req_samples > n_samples)
  565. req_samples = n_samples;
  566. result = read_MBR((short *)out_ptr, req_samples);
  567. if (result <= 0)
  568. return 0;
  569. for(ix=0; ix < result; ix++)
  570. {
  571. value16 = out_ptr[0] + (out_ptr[1] << 8);
  572. value = value16 * amplitude;
  573. value = value / 40; // adjust this constant to give a suitable amplitude for mbrola voices
  574. if(value > 0x7fff)
  575. value = 0x7fff;
  576. if(value < -0x8000)
  577. value = 0x8000;
  578. out_ptr[0] = value;
  579. out_ptr[1] = value >> 8;
  580. out_ptr += 2;
  581. }
  582. n_samples -= result;
  583. return n_samples ? 1 : 0;
  584. }
  585. void MbrolaReset(void)
  586. {
  587. // Reset the Mbrola engine and flush the pending audio
  588. reset_MBR();
  589. }
  590. #else // INCLUDE_MBROLA
  591. // mbrola interface is not compiled, provide dummy functions.
  592. espeak_ERROR LoadMbrolaTable(const char *mbrola_voice, const char *phtrans, int *srate)
  593. {
  594. return(EE_INTERNAL_ERROR);
  595. }
  596. int MbrolaGenerate(PHONEME_LIST *phoneme_list, int *n_ph, int resume)
  597. {
  598. return(0);
  599. }
  600. int MbrolaFill(int length, int resume, int amplitude)
  601. {
  602. return(0);
  603. }
  604. void MbrolaReset(void)
  605. {
  606. }
  607. #endif // INCLUDE_MBROLA