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.

synthesize.h 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. #define N_PHONEME_LIST 700 // enough for source[] full of text, else it will truncate
  20. #define MAX_HARMONIC 400 // 400 * 50Hz = 20 kHz, more than enough
  21. #define N_SEQ_FRAMES 25 // max frames in a spectrum sequence (real max is ablut 8)
  22. #define PITCHfall 0
  23. #define PITCHrise 1
  24. // flags set for frames within a spectrum sequence
  25. #define FRFLAG_VOWEL_CENTRE 0x02 // centre point of vowel
  26. #define FRFLAG_LEN_MOD 0x04 // reduce effect of length adjustment
  27. #define FRFLAG_BREAK_LF 0x08 // but keep f3 upwards
  28. #define FRFLAG_BREAK 0x10 // don't merge with next frame
  29. #define FRFLAG_BREAK_2 0x18 // FRFLAG_BREAK_LF or FRFLAG_BREAK
  30. #define FRFLAG_FORMANT_RATE 0x20 // Flag5 allow increased rate of change of formant freq
  31. #define FRFLAG_MODULATE 0x40 // Flag6 modulate amplitude of some cycles to give trill
  32. #define FRFLAG_DEFER_WAV 0x80 // Flag7 defer mixing WAV until the next frame
  33. #define FRFLAG_COPIED 0x8000 // This frame has been copied into temporary rw memory
  34. #define SFLAG_SEQCONTINUE 0x01 // a liquid or nasal after a vowel, but not followed by a vowel
  35. #define SFLAG_EMBEDDED 0x02 // there are embedded commands before this phoneme
  36. #define SFLAG_SYLLABLE 0x04 // vowel or syllabic consonant
  37. #define SFLAG_LENGTHEN 0x08 // lengthen symbol : included after this phoneme
  38. #define SFLAG_DICTIONARY 0x10 // the pronunciation of this word was listed in the xx_list dictionary
  39. #define SFLAG_SWITCHED_LANG 0x20 // this word uses phonemes from a different language
  40. // embedded command numbers
  41. #define EMBED_P 1 // pitch
  42. #define EMBED_S 2 // speed (used in setlengths)
  43. #define EMBED_A 3 // amplitude/volume
  44. #define EMBED_R 4 // pitch range/expression
  45. #define EMBED_H 5 // echo/reverberation
  46. #define EMBED_T 6 // different tone
  47. #define EMBED_I 7 // sound icon
  48. #define EMBED_S2 8 // speed (used in synthesize)
  49. #define EMBED_Y 9 // say-as commands
  50. #define EMBED_M 10 // mark name
  51. #define EMBED_U 11 // audio uri
  52. #define EMBED_B 12 // break
  53. #define EMBED_F 13 // emphasis
  54. #define N_EMBEDDED_VALUES 14
  55. extern int embedded_value[N_EMBEDDED_VALUES];
  56. extern int embedded_default[N_EMBEDDED_VALUES];
  57. // formant data used by wavegen
  58. typedef struct {
  59. int freq; // Hz<<16
  60. int height; // height<<15
  61. int left; // Hz<<16
  62. int right; // Hz<<16
  63. DOUBLEX freq1; // floating point versions of the above
  64. DOUBLEX height1;
  65. DOUBLEX left1;
  66. DOUBLEX right1;
  67. DOUBLEX freq_inc; // increment by this every 64 samples
  68. DOUBLEX height_inc;
  69. DOUBLEX left_inc;
  70. DOUBLEX right_inc;
  71. } wavegen_peaks_t;
  72. typedef struct {
  73. double a;
  74. double b;
  75. double c;
  76. double x1;
  77. double x2;
  78. } RESONATOR;
  79. typedef struct {
  80. short length;
  81. unsigned char n_frames;
  82. unsigned char flags;
  83. frame_t frame[N_SEQ_FRAMES]; // max. frames in a spectrum sequence
  84. } SPECT_SEQ;
  85. typedef struct {
  86. short length;
  87. short frflags;
  88. frame_t *frame;
  89. } frameref_t;
  90. typedef struct {
  91. PHONEME_TAB *ph;
  92. unsigned char env; // pitch envelope number
  93. unsigned char tone;
  94. unsigned char type;
  95. unsigned char prepause;
  96. unsigned char amp;
  97. unsigned char tone_ph; // tone phoneme to use with this vowel
  98. unsigned char newword; // bit 0=start of word, bit 1=end of clause, bit 2=start of sentence
  99. unsigned char synthflags;
  100. short length; // length_mod
  101. short pitch1; // pitch, 0-4095 within the Voice's pitch range
  102. short pitch2;
  103. unsigned short sourceix; // ix into the original source text string, only set at the start of a word
  104. } PHONEME_LIST;
  105. typedef struct {
  106. int name;
  107. int length;
  108. char *data;
  109. char *filename;
  110. } SOUND_ICON;
  111. typedef struct {
  112. int name;
  113. unsigned int next_phoneme;
  114. int mbr_name;
  115. int mbr_name2;
  116. int percent; // percentage length of first component
  117. int control;
  118. } MBROLA_TAB;
  119. // phoneme table
  120. extern PHONEME_TAB *phoneme_tab[N_PHONEME_TAB];
  121. // list of phonemes in a clause
  122. extern int n_phoneme_list;
  123. extern PHONEME_LIST phoneme_list[N_PHONEME_LIST];
  124. extern unsigned int embedded_list[];
  125. extern unsigned char env_fall[128];
  126. extern unsigned char env_rise[128];
  127. extern unsigned char env_frise[128];
  128. #define MAX_PITCH_VALUE 101
  129. extern unsigned char pitch_adjust_tab[MAX_PITCH_VALUE+1];
  130. // queue of commands for wavegen
  131. #define WCMD_AMPLITUDE 1
  132. #define WCMD_PITCH 2
  133. #define WCMD_SPECT 3
  134. #define WCMD_SPECT2 4
  135. #define WCMD_PAUSE 5
  136. #define WCMD_WAVE 6
  137. #define WCMD_WAVE2 7
  138. #define WCMD_MARKER 8
  139. #define WCMD_VOICE 9
  140. #define WCMD_EMBEDDED 10
  141. #define N_WCMDQ 160
  142. #define MIN_WCMDQ 20 // need this many free entries before adding new phoneme
  143. extern long wcmdq[N_WCMDQ][4];
  144. extern int wcmdq_head;
  145. extern int wcmdq_tail;
  146. // from Wavegen file
  147. int WcmdqFree();
  148. void WcmdqStop();
  149. int WcmdqUsed();
  150. void WcmdqInc();
  151. int WavegenOpenSound();
  152. int WavegenCloseSound();
  153. int WavegenInitSound();
  154. void WavegenInit(int rate, int wavemult_fact);
  155. int OpenWaveFile(const char *path, int rate);
  156. void CloseWaveFile(int rate);
  157. float polint(float xa[],float ya[],int n,float x);
  158. int WavegenFile(void);
  159. int WavegenFill(int fill_zeros);
  160. void MarkerEvent(int type, unsigned int char_position, int value, unsigned char *out_ptr);
  161. extern unsigned char *wavefile_data;
  162. extern int samplerate;
  163. extern int samplerate_native;
  164. extern int wavefile_ix;
  165. extern int wavefile_amp;
  166. extern int wavefile_ix2;
  167. extern int wavefile_amp2;
  168. extern int vowel_transition[4];
  169. extern int vowel_transition0, vowel_transition1;
  170. extern char mbrola_name[20];
  171. // from synthdata file
  172. unsigned int LookupSound(PHONEME_TAB *ph1, PHONEME_TAB *ph2, int which, int *match_level, int control);
  173. frameref_t *LookupSpect(PHONEME_TAB *ph1, PHONEME_TAB *prev_ph, PHONEME_TAB *next_ph, int which, int *match_level, int *n_frames, PHONEME_LIST *plist);
  174. unsigned char *LookupEnvelope(int ix);
  175. int LoadPhData();
  176. void SynthesizeInit(void);
  177. int Generate(PHONEME_LIST *phoneme_list, int *n_ph, int resume);
  178. void MakeWave2(PHONEME_LIST *p, int n_ph);
  179. int SynthOnTimer(void);
  180. int SpeakNextClause(FILE *f_text, const void *text_in, int control);
  181. int SynthStatus(void);
  182. void SetSpeed(int control);
  183. void SetEmbedded(int control, int value);
  184. void SelectPhonemeTable(int number);
  185. int SelectPhonemeTableName(const char *name);
  186. extern unsigned char *envelope_data[16];
  187. extern int formant_rate[]; // max rate of change of each formant
  188. extern int speed_factor1;
  189. extern int speed_factor2;
  190. extern long count_samples;
  191. extern int outbuf_size;
  192. extern unsigned char *out_ptr;
  193. extern unsigned char *out_start;
  194. extern unsigned char *out_end;
  195. extern int event_list_ix;
  196. extern espeak_EVENT *event_list;
  197. extern t_espeak_callback* synth_callback;
  198. #define N_SOUNDICON_TAB 100
  199. extern int n_soundicon_tab;
  200. extern SOUND_ICON soundicon_tab[N_SOUNDICON_TAB];
  201. espeak_ERROR SetVoiceByName(const char *name);
  202. espeak_ERROR SetVoiceByProperties(espeak_VOICE *voice_selector);
  203. espeak_ERROR LoadMbrolaTable(const char *mbrola_voice, const char *phtrans);
  204. void SetParameter(int parameter, int value, int relative);
  205. void MbrolaTranslate(PHONEME_LIST *plist, int n_phonemes, FILE *f_mbrola);
  206. int MbrolaSynth(char *p_mbrola);
  207. int DoSample(PHONEME_TAB *ph1, PHONEME_TAB *ph2, int which, int length_mod, int amp);
  208. int DoSpect(PHONEME_TAB *this_ph, PHONEME_TAB *prev_ph, PHONEME_TAB *next_ph,
  209. int which, PHONEME_LIST *plist, int modulation);
  210. int PauseLength(int pause);
  211. void InitBreath(void);