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 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. #define SFLAG_PROMOTE_STRESS 0x40 // this unstressed word can be promoted to stressed
  41. // embedded command numbers
  42. #define EMBED_P 1 // pitch
  43. #define EMBED_S 2 // speed (used in setlengths)
  44. #define EMBED_A 3 // amplitude/volume
  45. #define EMBED_R 4 // pitch range/expression
  46. #define EMBED_H 5 // echo/reverberation
  47. #define EMBED_T 6 // different tone
  48. #define EMBED_I 7 // sound icon
  49. #define EMBED_S2 8 // speed (used in synthesize)
  50. #define EMBED_Y 9 // say-as commands
  51. #define EMBED_M 10 // mark name
  52. #define EMBED_U 11 // audio uri
  53. #define EMBED_B 12 // break
  54. #define EMBED_F 13 // emphasis
  55. #define N_EMBEDDED_VALUES 14
  56. extern int embedded_value[N_EMBEDDED_VALUES];
  57. extern int embedded_default[N_EMBEDDED_VALUES];
  58. #define N_PEAKS 9
  59. #define N_MARKERS 8
  60. typedef struct {
  61. short pkfreq;
  62. short pkheight;
  63. short pkwidth;
  64. short pkright;
  65. } peak_t;
  66. typedef struct {
  67. short frflags;
  68. unsigned char length;
  69. unsigned char rms;
  70. short ffreq[9];
  71. unsigned char fheight[9];
  72. unsigned char fwidth[6]; // width/4
  73. unsigned char fright[6]; // width/4
  74. } frame_t;
  75. // formant data used by wavegen
  76. typedef struct {
  77. int freq; // Hz<<16
  78. int height; // height<<15
  79. int left; // Hz<<16
  80. int right; // Hz<<16
  81. DOUBLEX freq1; // floating point versions of the above
  82. DOUBLEX height1;
  83. DOUBLEX left1;
  84. DOUBLEX right1;
  85. DOUBLEX freq_inc; // increment by this every 64 samples
  86. DOUBLEX height_inc;
  87. DOUBLEX left_inc;
  88. DOUBLEX right_inc;
  89. } wavegen_peaks_t;
  90. typedef struct {
  91. double a;
  92. double b;
  93. double c;
  94. double x1;
  95. double x2;
  96. } RESONATOR;
  97. typedef struct {
  98. short length;
  99. unsigned char n_frames;
  100. unsigned char flags;
  101. frame_t frame[N_SEQ_FRAMES]; // max. frames in a spectrum sequence
  102. } SPECT_SEQ;
  103. typedef struct {
  104. short length;
  105. short frflags;
  106. frame_t *frame;
  107. } frameref_t;
  108. typedef struct {
  109. PHONEME_TAB *ph;
  110. unsigned char env; // pitch envelope number
  111. unsigned char tone;
  112. unsigned char type;
  113. unsigned char prepause;
  114. unsigned char amp;
  115. unsigned char tone_ph; // tone phoneme to use with this vowel
  116. unsigned char newword; // bit 0=start of word, bit 1=end of clause, bit 2=start of sentence
  117. unsigned char synthflags;
  118. short length; // length_mod
  119. short pitch1; // pitch, 0-4095 within the Voice's pitch range
  120. short pitch2;
  121. unsigned short sourceix; // ix into the original source text string, only set at the start of a word
  122. } PHONEME_LIST;
  123. typedef struct {
  124. int name;
  125. int length;
  126. char *data;
  127. char *filename;
  128. } SOUND_ICON;
  129. typedef struct {
  130. int name;
  131. unsigned int next_phoneme;
  132. int mbr_name;
  133. int mbr_name2;
  134. int percent; // percentage length of first component
  135. int control;
  136. } MBROLA_TAB;
  137. // phoneme table
  138. extern PHONEME_TAB *phoneme_tab[N_PHONEME_TAB];
  139. // list of phonemes in a clause
  140. extern int n_phoneme_list;
  141. extern PHONEME_LIST phoneme_list[N_PHONEME_LIST];
  142. extern unsigned int embedded_list[];
  143. extern unsigned char env_fall[128];
  144. extern unsigned char env_rise[128];
  145. extern unsigned char env_frise[128];
  146. #define MAX_PITCH_VALUE 101
  147. extern unsigned char pitch_adjust_tab[MAX_PITCH_VALUE+1];
  148. // queue of commands for wavegen
  149. #define WCMD_AMPLITUDE 1
  150. #define WCMD_PITCH 2
  151. #define WCMD_SPECT 3
  152. #define WCMD_SPECT2 4
  153. #define WCMD_PAUSE 5
  154. #define WCMD_WAVE 6
  155. #define WCMD_WAVE2 7
  156. #define WCMD_MARKER 8
  157. #define WCMD_VOICE 9
  158. #define WCMD_EMBEDDED 10
  159. #define N_WCMDQ 160
  160. #define MIN_WCMDQ 20 // need this many free entries before adding new phoneme
  161. extern long wcmdq[N_WCMDQ][4];
  162. extern int wcmdq_head;
  163. extern int wcmdq_tail;
  164. // from Wavegen file
  165. int WcmdqFree();
  166. void WcmdqStop();
  167. int WcmdqUsed();
  168. void WcmdqInc();
  169. int WavegenOpenSound();
  170. int WavegenCloseSound();
  171. int WavegenInitSound();
  172. void WavegenInit(int rate, int wavemult_fact);
  173. int OpenWaveFile(const char *path, int rate);
  174. void CloseWaveFile(int rate);
  175. float polint(float xa[],float ya[],int n,float x);
  176. int WavegenFile(void);
  177. int WavegenFill(int fill_zeros);
  178. void MarkerEvent(int type, unsigned int char_position, int value, unsigned char *out_ptr);
  179. extern unsigned char *wavefile_data;
  180. extern int samplerate;
  181. extern int samplerate_native;
  182. extern int wavefile_ix;
  183. extern int wavefile_amp;
  184. extern int wavefile_ix2;
  185. extern int wavefile_amp2;
  186. extern int vowel_transition[4];
  187. extern int vowel_transition0, vowel_transition1;
  188. extern char mbrola_name[20];
  189. // from synthdata file
  190. unsigned int LookupSound(PHONEME_TAB *ph1, PHONEME_TAB *ph2, int which, int *match_level, int control);
  191. 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);
  192. unsigned char *LookupEnvelope(int ix);
  193. int LoadPhData();
  194. void SynthesizeInit(void);
  195. int Generate(PHONEME_LIST *phoneme_list, int *n_ph, int resume);
  196. void MakeWave2(PHONEME_LIST *p, int n_ph);
  197. int SynthOnTimer(void);
  198. int SpeakNextClause(FILE *f_text, const void *text_in, int control);
  199. int SynthStatus(void);
  200. void SetSpeed(int control);
  201. void SetEmbedded(int control, int value);
  202. void SelectPhonemeTable(int number);
  203. int SelectPhonemeTableName(const char *name);
  204. extern unsigned char *envelope_data[16];
  205. extern int formant_rate[]; // max rate of change of each formant
  206. extern int speed_factor1;
  207. extern int speed_factor2;
  208. extern long count_samples;
  209. extern int outbuf_size;
  210. extern unsigned char *out_ptr;
  211. extern unsigned char *out_start;
  212. extern unsigned char *out_end;
  213. extern int event_list_ix;
  214. extern espeak_EVENT *event_list;
  215. extern t_espeak_callback* synth_callback;
  216. extern int option_log_frames;
  217. extern const char *version_string;
  218. extern const int version_phdata;
  219. #define N_SOUNDICON_TAB 100
  220. extern int n_soundicon_tab;
  221. extern SOUND_ICON soundicon_tab[N_SOUNDICON_TAB];
  222. espeak_ERROR SetVoiceByName(const char *name);
  223. espeak_ERROR SetVoiceByProperties(espeak_VOICE *voice_selector);
  224. espeak_ERROR LoadMbrolaTable(const char *mbrola_voice, const char *phtrans, int srate);
  225. void SetParameter(int parameter, int value, int relative);
  226. void MbrolaTranslate(PHONEME_LIST *plist, int n_phonemes, FILE *f_mbrola);
  227. int MbrolaSynth(char *p_mbrola);
  228. int DoSample(PHONEME_TAB *ph1, PHONEME_TAB *ph2, int which, int length_mod, int amp);
  229. int DoSpect(PHONEME_TAB *this_ph, PHONEME_TAB *prev_ph, PHONEME_TAB *next_ph,
  230. int which, PHONEME_LIST *plist, int modulation);
  231. int PauseLength(int pause);
  232. void InitBreath(void);