1 /*************************************************************************/
2 /*                                                                       */
3 /*                Centre for Speech Technology Research                  */
4 /*                     University of Edinburgh, UK                       */
5 /*                       Copyright (c) 1996,1997                         */
6 /*                        All Rights Reserved.                           */
7 /*                                                                       */
8 /*  Permission is hereby granted, free of charge, to use and distribute  */
9 /*  this software and its documentation without restriction, including   */
10 /*  without limitation the rights to use, copy, modify, merge, publish,  */
11 /*  distribute, sublicense, and/or sell copies of this work, and to      */
12 /*  permit persons to whom this work is furnished to do so, subject to   */
13 /*  the following conditions:                                            */
14 /*   1. The code must retain the above copyright notice, this list of    */
15 /*      conditions and the following disclaimer.                         */
16 /*   2. Any modifications must be clearly marked as such.                */
17 /*   3. Original authors' names are not deleted.                         */
18 /*   4. The authors' names are not used to endorse or promote products   */
19 /*      derived from this software without specific prior written        */
20 /*      permission.                                                      */
21 /*                                                                       */
22 /*  THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK        */
23 /*  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING      */
24 /*  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   */
25 /*  SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE     */
26 /*  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    */
27 /*  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   */
28 /*  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          */
29 /*  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       */
30 /*  THIS SOFTWARE.                                                       */
31 /*                                                                       */
32 /*************************************************************************/
33 /*             Author :  Alistair Conkie and Steve Isard                 */
34 /*-----------------------------------------------------------------------*/
35 
36 #ifndef _T2S_H_
37 #define _T2S_H_
38 #define NDIPHS 3000
39 #define NFRAMES 23000
40 #define FR_DATA 16  /* shorts per frame, coeffs + assorted  */
41 
42 #define FW 1
43 #define CW 2
44 #define PUNCT 3
45 
46 #define DEF_F0 125
47 #define SR 10000	/* sample rate  */
48 #define FR_SZ 132	/* standard frame size  */
49 
50 /* malloc defaults  */
51 #define DEF_BUFFER 1024
52 #define DEF_LING_LIST 100
53 #define DEF_SPL 100
54 #define DEF_PHONS 100
55 #define DEF_TARGS 100
56 #define DEF_FRAMES 100
57 #define DEF_PM 100
58 
59 #define PHON_SZ 5
60 #define DIPH_SZ 10
61 
62 #define OUT_BUF 2048
63 
64 #define NCOEFFS 12
65 
66 /* non-rhotic vowel classification for assim.c */
67 #define V_DEL_R 0
68 #define V_AIR 1
69 #define V_EER 2
70 #define V_OOR 3
71 #define V_R2SCHWA 4
72 
73 /* various typedefs  */
74 
75 typedef struct {
76 	char *input_file;
77 	char *output_file;
78 	char *index_file;
79 	char *diphone_file;
80 	char *hash_file;
81 	char *format;
82 	int type;	/* format by any other name  */
83 	FILE *ifd;
84 	FILE *ofd;
85 	FILE *xfd;
86 	FILE *dfd;
87 	void *db;
88 	int fw_num;
89 	int sonority_num;
90 	int dur0_num;
91 } CONFIG;
92 
93 typedef struct {
94 	int max;
95 	int sz;
96 	char *ptr;
97 } BUFFER;
98 
99 typedef struct {
100 	char *word;
101 	int type;
102 	char *transcription;
103 } LING;
104 
105 typedef struct {
106 	int max;
107 	int sz;
108 	LING **text;
109 } LING_LIST;
110 
111 typedef struct key {
112 	char *keyword;
113 	int keycount;
114 } KEY;
115 
116 typedef struct {
117 	char phoneme[5];
118 	int syll;
119 	int dur;
120 	char *sprosod1;
121 	char *sprosod2;
122 	float strength1;
123 	float strength2;	/* for combined elements  */
124 } SPROSOD;
125 
126 typedef struct {
127 	int max;
128 	int sz;
129 	SPROSOD **phoneme;
130 } SPROSOD_LIST;
131 
132 typedef struct {
133         char diph[10];
134         int beg;
135         int mid;
136         int end;
137 } ENTRY;
138 
139 typedef struct {
140         short frame[FR_DATA];
141 } FRAME;
142 
143 typedef struct {
144 	int p_sz;
145 	int p_max;
146 	int t_sz;
147 	int t_max;
148 	char **phons;
149 	int *duration;
150 	int *cum_dur;
151 	int *pc_targs;
152 	int *targ_phon;
153 	int *targ_freq;
154 	int *abs_targ; /* maybe in samples  */
155 	int *pb;
156 	float *scale;
157 	char **diphs;
158 } SPN;
159 
160 typedef struct {
161 	int f_sz;
162 	int p_sz;
163 	int f_max;
164 	int p_max;
165 	FRAME **mcebuf;
166 	short *duration; /* since variants may be required  */
167 	short *pitch;
168 } ACOUSTIC;
169 
170 
171 extern KEY fw[];
172 extern KEY son[];
173 extern KEY dur0[];
174 
175 /* now definitions of global data  */
176 
177 /* awb -- deleted */
178 /* extern ENTRY indx[NDIPHS]; */
179 /* extern FRAME dico[NFRAMES]; */
180 extern int nindex;
181 extern char *dbName;
182 
183 /* program prototypes  */
184 
185 /* audio.c  */
186 void audio_open(CONFIG *config);
187 void audio_play(short *start,int sz,int number,CONFIG *config);
188 void audio_close(CONFIG *config);
189 void audio_flush(CONFIG *config);
190 
191 /* makewave.c  */
192 void makewave(CONFIG *config, ACOUSTIC *as);
193 
194 /* coeffs.c  */
195 void rfctolpc(float *buf);
196 
197 /* conv.c  */
198 void conv(CONFIG *config, LING_LIST *ling_list, SPROSOD_LIST *spl);
199 void spl_cpy(int index,int syll, char *phon, int dur, char *type, float strength, SPROSOD_LIST *spl);
200 void spl_cat(int index,char *type, float strength, SPROSOD_LIST *spl);
201 int vowel(char *ph) ;
202 
203 /* durations.c  */
204 void durations(SPN *ps, ACOUSTIC *as);
205 
206 /* excitation.c  */
207 float iexc(short voiced, ACOUSTIC *as, short *wkspace);
208 
209 /* go.c  */
210 void go(CONFIG *config, BUFFER *buffer, LING_LIST *ling_list, SPROSOD_LIST *spl, SPN *ps, ACOUSTIC *as);
211 
212 /* grammar.c  */
213 void grammar(LING_LIST *ling_list);
214 
215 /* interface.c  */
216 char *nrl_rules(char *in);
217 
218 /* load_diphs.c  */
219 int load_speech(CONFIG *config);
220 int lookup(char *diph);
221 void phonstoframes(SPN *ps, ACOUSTIC *as);
222 
223 /* nrl_edin.c  */
224 void nrl_edin_conv(char *str, char *str2);
225 
226 /* pitch.c  */
227 void calc_pitch(SPN *ps, ACOUSTIC *as);
228 
229 /* prosody.c  */
230 void prosody(SPROSOD_LIST *spl, SPN *ps);
231 
232 /* space.c  */
233 void init(CONFIG *config, BUFFER *buffer, LING_LIST *ling_list, SPROSOD_LIST *spl, SPN *ps, ACOUSTIC *as);
234 void terminate(CONFIG *config, BUFFER *buffer, LING_LIST *ling_list, SPROSOD_LIST *spl, SPN *ps, ACOUSTIC *as);
235 void buffer_malloc(int num,BUFFER *buffer);
236 void buffer_realloc(int num, BUFFER *buffer);
237 void buffer_free(BUFFER *buffer);
238 void ling_list_malloc(int num, LING_LIST *ling_list);
239 void ling_list_realloc(int num, LING_LIST *ling_list);
240 void ling_list_free(LING_LIST *ling_list);
241 void spl_malloc(int num, SPROSOD_LIST *spl);
242 void spl_realloc(int num, SPROSOD_LIST *spl);
243 void spl_free(SPROSOD_LIST *spl);
244 void ps_malloc(int nphons, int ntargs, SPN *ps);
245 void ps_realloc(int nphons, int ntargs, SPN *ps);
246 void ps_free(SPN *ps);
247 void as_malloc(int nframes, int npp, ACOUSTIC *as);
248 void as_realloc(int nframes, int npp, ACOUSTIC *as);
249 void as_free(ACOUSTIC *as);
250 
251 /* syllab.c  */
252 char *syllabify(char *string, CONFIG *config);
253 char *stress(char *input);
254 
255 /* t2s.c  */
256 void process_sentence(CONFIG *config, BUFFER *buffer, LING_LIST *ling_list, SPROSOD_LIST *spl, SPN *ps, ACOUSTIC *as);
257 
258 /* tags.c  */
259 void tags(CONFIG *config, BUFFER *buffer, LING_LIST *ling_list);
260 
261 /* transcribe.c  */
262 void transcribe(CONFIG *config, LING_LIST *ling_list);
263 
264 /* utils.c  */
265 char **split(char *in);
266 void tidy_split(char **root);
267 KEY *binary(char *word, KEY tab[], int n);
268 
269 /* library prototypes
270 int fprintf(FILE *stream, char *format, ...  );
271 int printf(const char *format, ...  );
272 int getopt(int argc,char **argv, char *optstring);
273 int sscanf(char *s,char * format, ... );
274 int fread (char *ptr, int size, int nitems, FILE *stream);
275 int fwrite (char *ptr, int size, int nitems, FILE *stream);
276 int fclose(FILE *stream);
277 */
278 
279 
280 #endif /* _T2S_H_ */
281