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.cpp 17KB

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