| 1 |
/*************************************************************************/ |
| 2 |
/* */ |
| 3 |
/* Language Technologies Institute */ |
| 4 |
/* Carnegie Mellon University */ |
| 5 |
/* Copyright (c) 2001 */ |
| 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 |
/* CARNEGIE MELLON UNIVERSITY 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 CARNEGIE MELLON UNIVERSITY 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: Alan W Black ([email protected]) */ |
| 34 |
/* Date: January 2001 */ |
| 35 |
/*************************************************************************/ |
| 36 |
/* */ |
| 37 |
/* CMU Lexicon definition */ |
| 38 |
/* */ |
| 39 |
/*************************************************************************/ |
| 40 |
|
| 41 |
#include "flite.h" |
| 42 |
|
| 43 |
#include "cmu_lex.h" |
| 44 |
|
| 45 |
extern const int cmu_lex_entry[]; |
| 46 |
extern const unsigned char cmu_lex_data[]; |
| 47 |
extern const int cmu_lex_num_entries; |
| 48 |
extern const int cmu_lex_num_bytes; |
| 49 |
extern const char * const cmu_lex_phone_table[54]; |
| 50 |
extern const char * const cmu_lex_phones_huff_table[]; |
| 51 |
extern const char * const cmu_lex_entries_huff_table[]; |
| 52 |
|
| 53 |
static int cmu_is_vowel(const char *p); |
| 54 |
static int cmu_is_silence(const char *p); |
| 55 |
static int cmu_has_vowel_in_list(const cst_val *v); |
| 56 |
static int cmu_has_vowel_in_syl(const cst_item *i); |
| 57 |
static int cmu_sonority(const char *p); |
| 58 |
|
| 59 |
static const char * const addenda0[] = { "p,", NULL }; |
| 60 |
static const char * const addenda1[] = { "p.", NULL }; |
| 61 |
static const char * const addenda2[] = { "p(", NULL }; |
| 62 |
static const char * const addenda3[] = { "p)", NULL }; |
| 63 |
static const char * const addenda4[] = { "p[", NULL }; |
| 64 |
static const char * const addenda5[] = { "p]", NULL }; |
| 65 |
static const char * const addenda6[] = { "p{", NULL }; |
| 66 |
static const char * const addenda7[] = { "p}", NULL }; |
| 67 |
static const char * const addenda8[] = { "p:", NULL }; |
| 68 |
static const char * const addenda9[] = { "p;", NULL }; |
| 69 |
static const char * const addenda10[] = { "p?", NULL}; |
| 70 |
static const char * const addenda11[] = { "p!", NULL }; |
| 71 |
static const char * const addenda12[] = { "n@", "ae1", "t", NULL }; |
| 72 |
static const char * const addenda13[] = { "n#", "hh", "ae1","sh", NULL }; |
| 73 |
static const char * const addenda14[] = { "n$", "d", "aa1", "l", "er", NULL }; |
| 74 |
static const char * const addenda15[] = { "n%", "p", "er", "s", "eh1", "n", "t", NULL }; |
| 75 |
static const char * const addenda16[] = { "n^", "k", "eh1", "r", "eh1", "t", NULL }; |
| 76 |
static const char * const addenda17[] = { "n&","ae1","m","p","er","s","ae1","n","d", NULL }; |
| 77 |
static const char * const addenda18[] = { "n*","ae1","s","t","er","ih1","s","k",NULL }; |
| 78 |
static const char * const addenda19[] = { "n|","b","aa1","r",NULL }; |
| 79 |
static const char * const addenda20[] = { "n\\","b","ae1","k","s","l","ae1","sh",NULL }; |
| 80 |
static const char * const addenda21[] = { "n=","iy1","k","w","ax","l","z",NULL}; |
| 81 |
static const char * const addenda22[] = { "n+","p","l","ah1","s",NULL}; |
| 82 |
static const char * const addenda23[] = { "n~","t","ih1","l","d","ax",NULL}; |
| 83 |
static const char * const addenda24[] = { "p'",NULL}; |
| 84 |
static const char * const addenda25[] = { "p`",NULL}; |
| 85 |
static const char * const addenda26[] = { "p\"",NULL}; |
| 86 |
static const char * const addenda27[] = { "p-",NULL}; |
| 87 |
static const char * const addenda28[] = { "p<",NULL}; |
| 88 |
static const char * const addenda29[] = { "p>",NULL}; |
| 89 |
static const char * const addenda30[] = { "n_","ah1","n","d","er","s","k","ao1","r",NULL}; |
| 90 |
static const char * const addenda31[] = { "s's","z",NULL}; |
| 91 |
static const char * const addenda32[] = { "nim","ay1","m",NULL}; |
| 92 |
static const char * const addenda33[] = { "vdoesnt","d","ah1","z","n","t",NULL}; |
| 93 |
static const char * const addenda34[] = { "vyoull","y","uw1","l",NULL}; |
| 94 |
static const char * const addenda35[] = { "n/","s","l","ae1","sh",NULL}; |
| 95 |
|
| 96 |
static const char * const addenda36[] = { "nin","ih","n",NULL}; |
| 97 |
static const char * const addenda37[] = { "nto","t","ax",NULL}; |
| 98 |
static const char * const addenda38[] = { "0_a","ey",NULL}; |
| 99 |
static const char * const addenda39[] = { "vhavent","hh","ae1","v","ax","n","t",NULL}; |
| 100 |
static const char * const addenda40[] = { "nemail","iy1","m","ey1","l",NULL}; |
| 101 |
static const char * const addenda41[] = { "nshit","sh","ih1","t",NULL}; |
| 102 |
|
| 103 |
static const char * const * const addenda[] = { |
| 104 |
addenda0, |
| 105 |
addenda1, |
| 106 |
addenda2, |
| 107 |
addenda3, |
| 108 |
addenda4, |
| 109 |
addenda5, |
| 110 |
addenda6, |
| 111 |
addenda7, |
| 112 |
addenda8, |
| 113 |
addenda9, |
| 114 |
addenda10, |
| 115 |
addenda11, |
| 116 |
addenda12, |
| 117 |
addenda13, |
| 118 |
addenda14, |
| 119 |
addenda15, |
| 120 |
addenda16, |
| 121 |
addenda17, |
| 122 |
addenda18, |
| 123 |
addenda19, |
| 124 |
addenda20, |
| 125 |
addenda21, |
| 126 |
addenda22, |
| 127 |
addenda23, |
| 128 |
addenda24, |
| 129 |
addenda25, |
| 130 |
addenda26, |
| 131 |
addenda27, |
| 132 |
addenda28, |
| 133 |
addenda29, |
| 134 |
addenda30, |
| 135 |
addenda31, |
| 136 |
addenda32, |
| 137 |
addenda33, |
| 138 |
addenda34, |
| 139 |
addenda35, |
| 140 |
|
| 141 |
addenda36, |
| 142 |
addenda37, |
| 143 |
addenda38, |
| 144 |
addenda39, |
| 145 |
addenda40, |
| 146 |
addenda41, |
| 147 |
NULL }; |
| 148 |
|
| 149 |
static int cmu_is_silence(const char *p) |
| 150 |
{ |
| 151 |
if (cst_streq(p,"pau")) |
| 152 |
return TRUE; |
| 153 |
else |
| 154 |
return FALSE; |
| 155 |
} |
| 156 |
|
| 157 |
static int cmu_has_vowel_in_list(const cst_val *v) |
| 158 |
{ |
| 159 |
const cst_val *t; |
| 160 |
|
| 161 |
for (t=v; t; t=val_cdr(t)) |
| 162 |
if (cmu_is_vowel(val_string(val_car(t)))) |
| 163 |
return TRUE; |
| 164 |
return FALSE; |
| 165 |
} |
| 166 |
|
| 167 |
static int cmu_has_vowel_in_syl(const cst_item *i) |
| 168 |
{ |
| 169 |
const cst_item *n; |
| 170 |
|
| 171 |
for (n=i; n; n=item_prev(n)) |
| 172 |
if (cmu_is_vowel(item_feat_string(n,"name"))) |
| 173 |
return TRUE; |
| 174 |
return FALSE; |
| 175 |
} |
| 176 |
|
| 177 |
static int cmu_is_vowel(const char *p) |
| 178 |
{ |
| 179 |
/* this happens to work for US English phoneset */ |
| 180 |
if (strchr("aeiou",p[0]) == NULL) |
| 181 |
return FALSE; |
| 182 |
else |
| 183 |
return TRUE; |
| 184 |
} |
| 185 |
|
| 186 |
static int cmu_sonority(const char *p) |
| 187 |
{ |
| 188 |
/* A bunch of hacks for US English phoneset */ |
| 189 |
if (cmu_is_vowel(p) || (cmu_is_silence(p))) |
| 190 |
return 5; |
| 191 |
else if (strchr("wylr",p[0]) != NULL) |
| 192 |
return 4; /* glides/liquids */ |
| 193 |
else if (strchr("nm",p[0]) != NULL) |
| 194 |
return 3; /* nasals */ |
| 195 |
else if (strchr("bdgjlmnnnrvwyz",p[0]) != NULL) |
| 196 |
return 2; /* voiced obstruents */ |
| 197 |
else |
| 198 |
return 1; |
| 199 |
} |
| 200 |
|
| 201 |
int cmu_syl_boundary(const cst_item *i,const cst_val *rest) |
| 202 |
{ |
| 203 |
/* Returns TRUE if this should be a syllable boundary */ |
| 204 |
/* This is of course phone set dependent */ |
| 205 |
int p, n, nn; |
| 206 |
|
| 207 |
if (rest == NULL) |
| 208 |
return TRUE; |
| 209 |
else if (cmu_is_silence(val_string(val_car(rest)))) |
| 210 |
return TRUE; |
| 211 |
else if (!cmu_has_vowel_in_list(rest)) /* no more vowels so rest *all* coda */ |
| 212 |
return FALSE; |
| 213 |
else if (!cmu_has_vowel_in_syl(i)) /* need a vowel */ |
| 214 |
return FALSE; |
| 215 |
else if (cmu_is_vowel(val_string(val_car(rest)))) |
| 216 |
return TRUE; |
| 217 |
else if (val_cdr(rest) == NULL) |
| 218 |
return FALSE; |
| 219 |
else |
| 220 |
{ /* so there is following vowel, and multiple phones left */ |
| 221 |
p = cmu_sonority(item_feat_string(i,"name")); |
| 222 |
n = cmu_sonority(val_string(val_car(rest))); |
| 223 |
nn = cmu_sonority(val_string(val_car(val_cdr(rest)))); |
| 224 |
|
| 225 |
if ((p <= n) && (n <= nn)) |
| 226 |
return TRUE; |
| 227 |
else |
| 228 |
return FALSE; |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
static int cmulex_dist_to_vowel(const cst_val *rest) |
| 233 |
{ |
| 234 |
if (rest == 0) |
| 235 |
return 0; /* shouldn't get here */ |
| 236 |
else if (cmu_is_vowel(val_string(val_car(rest)))) |
| 237 |
return 0; |
| 238 |
else |
| 239 |
return 1+cmulex_dist_to_vowel(val_cdr(rest)); |
| 240 |
} |
| 241 |
|
| 242 |
static const char * const cmulex_onset_trigrams[] = { |
| 243 |
"str", "spy", "spr", "spl", "sky", "skw", "skr", "skl", NULL |
| 244 |
}; |
| 245 |
static const char * const cmulex_onset_bigrams[] = { |
| 246 |
"zw", "zl", |
| 247 |
"vy", "vr", "vl", |
| 248 |
"thw", "thr", |
| 249 |
"ty", "tw", |
| 250 |
"tr", /* "ts", */ |
| 251 |
"shw", "shr", "shn", "shm", "shl", |
| 252 |
"sw", "sv", "st", "sr", "sp", "sn", "sm", "sl", "sk", "sf", |
| 253 |
"py", "pw", "pr", "pl", |
| 254 |
"ny", |
| 255 |
"my", "mr", |
| 256 |
"ly", |
| 257 |
"ky", "kw", "kr", "kl", |
| 258 |
"hhy", "hhw", "hhr", "hhl", |
| 259 |
"gy", "gw", "gr", "gl", |
| 260 |
"fy", "fr", "fl", |
| 261 |
"dy", "dw", "dr", |
| 262 |
"by", "bw", "br", "bl", |
| 263 |
NULL |
| 264 |
}; |
| 265 |
|
| 266 |
static int cmulex_onset_bigram(const cst_val *rest) |
| 267 |
{ |
| 268 |
char x[10]; |
| 269 |
int i; |
| 270 |
|
| 271 |
cst_sprintf(x,"%s%s",val_string(val_car(rest)), |
| 272 |
val_string(val_car(val_cdr(rest)))); |
| 273 |
for (i=0; cmulex_onset_bigrams[i]; i++) |
| 274 |
if (cst_streq(x,cmulex_onset_bigrams[i])) |
| 275 |
return TRUE; |
| 276 |
return FALSE; |
| 277 |
} |
| 278 |
|
| 279 |
static int cmulex_onset_trigram(const cst_val *rest) |
| 280 |
{ |
| 281 |
char x[15]; |
| 282 |
int i; |
| 283 |
|
| 284 |
cst_sprintf(x,"%s%s%s",val_string(val_car(rest)), |
| 285 |
val_string(val_car(val_cdr(rest))), |
| 286 |
val_string(val_car(val_cdr(val_cdr(rest))))); |
| 287 |
for (i=0; cmulex_onset_trigrams[i]; i++) |
| 288 |
if (cst_streq(x,cmulex_onset_trigrams[i])) |
| 289 |
return TRUE; |
| 290 |
return FALSE; |
| 291 |
} |
| 292 |
|
| 293 |
int cmu_syl_boundary_mo(const cst_item *i,const cst_val *rest) |
| 294 |
{ |
| 295 |
/* syl boundary maximal onset */ |
| 296 |
int d2v; |
| 297 |
|
| 298 |
if (rest == NULL) |
| 299 |
return TRUE; |
| 300 |
else if (cmu_is_silence(val_string(val_car(rest)))) |
| 301 |
return TRUE; |
| 302 |
else if (!cmu_has_vowel_in_list(rest)) |
| 303 |
/* no more vowels so rest *all* coda */ |
| 304 |
return FALSE; |
| 305 |
else if (!cmu_has_vowel_in_syl(i)) /* need a vowel */ |
| 306 |
/* no vowel yet in syl so keep copying */ |
| 307 |
return FALSE; |
| 308 |
else if (cmu_is_vowel(val_string(val_car(rest)))) |
| 309 |
/* next is a vowel, syl has vowel, so this is a break */ |
| 310 |
return TRUE; |
| 311 |
else if (cst_streq("ng",val_string(val_car(rest)))) |
| 312 |
/* next is "ng" which can't start a word internal syl */ |
| 313 |
return FALSE; |
| 314 |
else |
| 315 |
{ |
| 316 |
/* want to know if from rest to the next vowel is a valid onset */ |
| 317 |
d2v = cmulex_dist_to_vowel(rest); |
| 318 |
if (d2v < 2) |
| 319 |
return TRUE; |
| 320 |
else if (d2v > 3) |
| 321 |
return FALSE; |
| 322 |
else if (d2v == 2) |
| 323 |
return cmulex_onset_bigram(rest); |
| 324 |
else /* if (d2v == 3) */ |
| 325 |
return cmulex_onset_trigram(rest); |
| 326 |
return TRUE; |
| 327 |
} |
| 328 |
|
| 329 |
} |
| 330 |
|
| 331 |
cst_lexicon cmu_lex; |
| 332 |
cst_lts_rules cmu_lts_rules; |
| 333 |
extern const char * const cmu_lts_phone_table[]; |
| 334 |
extern const char * const cmu_lts_letter_table[]; |
| 335 |
extern const cst_lts_addr cmu_lts_letter_index[]; |
| 336 |
extern const cst_lts_model cmu_lts_model[]; |
| 337 |
|
| 338 |
cst_lexicon *cmulex_init() |
| 339 |
{ |
| 340 |
/* We actually need the init function match the directory name */ |
| 341 |
return cmu_lex_init(); |
| 342 |
} |
| 343 |
|
| 344 |
cst_lexicon *cmu_lex_init() |
| 345 |
{ |
| 346 |
/* I'd like to do this as a const but it needs everything in this */ |
| 347 |
/* file and already the bits are too big for some compilers */ |
| 348 |
|
| 349 |
if (cmu_lts_rules.name) |
| 350 |
return &cmu_lex; /* Already initialized */ |
| 351 |
|
| 352 |
cmu_lts_rules.name = "cmu"; |
| 353 |
cmu_lts_rules.letter_index = cmu_lts_letter_index; |
| 354 |
#ifdef CST_NO_STATIC_LTS_MODEL |
| 355 |
/* cmu_lts_rules.models will be set elsewhere */ |
| 356 |
#else |
| 357 |
cmu_lts_rules.models = cmu_lts_model; |
| 358 |
#endif |
| 359 |
cmu_lts_rules.phone_table = cmu_lts_phone_table; |
| 360 |
cmu_lts_rules.context_window_size = 4; |
| 361 |
cmu_lts_rules.context_extra_feats = 1; |
| 362 |
cmu_lts_rules.letter_table = 0 /* cmu_lts_letter_table */; |
| 363 |
|
| 364 |
cmu_lex.name = "cmu"; |
| 365 |
cmu_lex.num_entries = cmu_lex_num_entries; |
| 366 |
#ifdef CST_NO_STATIC_LEX |
| 367 |
/* cmu_lex.data will be set elsewhere */ |
| 368 |
#else |
| 369 |
/* as the data is const, we cast it through void * */ |
| 370 |
cmu_lex.data = (unsigned char *)(void *)cmu_lex_data; |
| 371 |
#endif |
| 372 |
cmu_lex.num_bytes = cmu_lex_num_bytes; |
| 373 |
cmu_lex.phone_table = (char **) cmu_lex_phone_table; |
| 374 |
cmu_lex.syl_boundary = cmu_syl_boundary_mo; |
| 375 |
cmu_lex.addenda = (char ***) addenda; |
| 376 |
cmu_lex.lts_rule_set = (cst_lts_rules *) &cmu_lts_rules; |
| 377 |
|
| 378 |
cmu_lex.phone_hufftable = cmu_lex_phones_huff_table; |
| 379 |
cmu_lex.entry_hufftable = cmu_lex_entries_huff_table; |
| 380 |
|
| 381 |
cmu_lex.postlex = cmu_postlex; |
| 382 |
|
| 383 |
return &cmu_lex; |
| 384 |
|
| 385 |
} |