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

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