| 1 |
/* |
| 2 |
* Copyright (C) 2005 to 2010 by Jonathan Duddington |
| 3 |
* email: [email protected] |
| 4 |
* Copyright (C) 2015-2017 Reece H. Dunn |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 3 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, see: <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#ifndef ESPEAK_NG_PHONEME_H |
| 21 |
#define ESPEAK_NG_PHONEME_H |
| 22 |
|
| 23 |
#include "espeak_ng.h" |
| 24 |
|
| 25 |
#ifdef __cplusplus |
| 26 |
extern "C" |
| 27 |
{ |
| 28 |
#endif |
| 29 |
|
| 30 |
// See docs/phonemes.md for the list of supported features. |
| 31 |
typedef enum { |
| 32 |
# define FEATURE_T(a, b, c) ((a << 16) | (b << 8) | (c)) |
| 33 |
// invalid phoneme feature name |
| 34 |
inv = 0, |
| 35 |
// manner of articulation |
| 36 |
nas = FEATURE_T('n', 'a', 's'), |
| 37 |
stp = FEATURE_T('s', 't', 'p'), |
| 38 |
afr = FEATURE_T('a', 'f', 'r'), |
| 39 |
frc = FEATURE_T('f', 'r', 'c'), |
| 40 |
flp = FEATURE_T('f', 'l', 'p'), |
| 41 |
trl = FEATURE_T('t', 'r', 'l'), |
| 42 |
apr = FEATURE_T('a', 'p', 'r'), |
| 43 |
clk = FEATURE_T('c', 'l', 'k'), |
| 44 |
ejc = FEATURE_T('e', 'j', 'c'), |
| 45 |
imp = FEATURE_T('i', 'm', 'p'), |
| 46 |
vwl = FEATURE_T('v', 'w', 'l'), |
| 47 |
lat = FEATURE_T('l', 'a', 't'), |
| 48 |
sib = FEATURE_T('s', 'i', 'b'), |
| 49 |
// place of articulation |
| 50 |
blb = FEATURE_T('b', 'l', 'b'), |
| 51 |
lbd = FEATURE_T('l', 'b', 'd'), |
| 52 |
bld = FEATURE_T('b', 'l', 'd'), |
| 53 |
dnt = FEATURE_T('d', 'n', 't'), |
| 54 |
alv = FEATURE_T('a', 'l', 'v'), |
| 55 |
pla = FEATURE_T('p', 'l', 'a'), |
| 56 |
rfx = FEATURE_T('r', 'f', 'x'), |
| 57 |
alp = FEATURE_T('a', 'l', 'p'), |
| 58 |
pal = FEATURE_T('p', 'a', 'l'), |
| 59 |
vel = FEATURE_T('v', 'e', 'l'), |
| 60 |
lbv = FEATURE_T('l', 'b', 'v'), |
| 61 |
uvl = FEATURE_T('u', 'v', 'l'), |
| 62 |
phr = FEATURE_T('p', 'h', 'r'), |
| 63 |
glt = FEATURE_T('g', 'l', 't'), |
| 64 |
// voice |
| 65 |
vcd = FEATURE_T('v', 'c', 'd'), |
| 66 |
vls = FEATURE_T('v', 'l', 's'), |
| 67 |
// vowel height |
| 68 |
hgh = FEATURE_T('h', 'g', 'h'), |
| 69 |
smh = FEATURE_T('s', 'm', 'h'), |
| 70 |
umd = FEATURE_T('u', 'm', 'd'), |
| 71 |
mid = FEATURE_T('m', 'i', 'd'), |
| 72 |
lmd = FEATURE_T('l', 'm', 'd'), |
| 73 |
sml = FEATURE_T('s', 'm', 'l'), |
| 74 |
low = FEATURE_T('l', 'o', 'w'), |
| 75 |
// vowel backness |
| 76 |
fnt = FEATURE_T('f', 'n', 't'), |
| 77 |
cnt = FEATURE_T('c', 'n', 't'), |
| 78 |
bck = FEATURE_T('b', 'c', 'k'), |
| 79 |
// rounding |
| 80 |
unr = FEATURE_T('u', 'n', 'r'), |
| 81 |
rnd = FEATURE_T('r', 'n', 'd'), |
| 82 |
// articulation |
| 83 |
lgl = FEATURE_T('l', 'g', 'l'), |
| 84 |
idt = FEATURE_T('i', 'd', 't'), |
| 85 |
apc = FEATURE_T('a', 'p', 'c'), |
| 86 |
lmn = FEATURE_T('l', 'm', 'n'), |
| 87 |
// air flow |
| 88 |
egs = FEATURE_T('e', 'g', 's'), |
| 89 |
igs = FEATURE_T('i', 'g', 's'), |
| 90 |
// phonation |
| 91 |
brv = FEATURE_T('b', 'r', 'v'), |
| 92 |
slv = FEATURE_T('s', 'l', 'v'), |
| 93 |
stv = FEATURE_T('s', 't', 'v'), |
| 94 |
crv = FEATURE_T('c', 'r', 'v'), |
| 95 |
glc = FEATURE_T('g', 'l', 'c'), |
| 96 |
// rounding and labialization |
| 97 |
ptr = FEATURE_T('p', 't', 'r'), |
| 98 |
cmp = FEATURE_T('c', 'm', 'p'), |
| 99 |
mrd = FEATURE_T('m', 'r', 'd'), |
| 100 |
lrd = FEATURE_T('l', 'r', 'd'), |
| 101 |
// syllabicity |
| 102 |
syl = FEATURE_T('s', 'y', 'l'), |
| 103 |
nsy = FEATURE_T('n', 's', 'y'), |
| 104 |
// consonant release |
| 105 |
asp = FEATURE_T('a', 's', 'p'), |
| 106 |
nrs = FEATURE_T('n', 'r', 's'), |
| 107 |
lrs = FEATURE_T('l', 'r', 's'), |
| 108 |
unx = FEATURE_T('u', 'n', 'x'), |
| 109 |
// coarticulation |
| 110 |
pzd = FEATURE_T('p', 'z', 'd'), |
| 111 |
vzd = FEATURE_T('v', 'z', 'd'), |
| 112 |
fzd = FEATURE_T('f', 'z', 'd'), |
| 113 |
nzd = FEATURE_T('n', 'z', 'd'), |
| 114 |
rzd = FEATURE_T('r', 'z', 'd'), |
| 115 |
// tongue root |
| 116 |
atr = FEATURE_T('a', 't', 'r'), |
| 117 |
rtr = FEATURE_T('r', 't', 'r'), |
| 118 |
// fortis and lenis |
| 119 |
fts = FEATURE_T('f', 't', 's'), |
| 120 |
lns = FEATURE_T('l', 'n', 's'), |
| 121 |
// length |
| 122 |
est = FEATURE_T('e', 's', 't'), |
| 123 |
hlg = FEATURE_T('h', 'l', 'g'), |
| 124 |
lng = FEATURE_T('l', 'n', 'g'), |
| 125 |
elg = FEATURE_T('e', 'l', 'g'), |
| 126 |
# undef FEATURE_T |
| 127 |
} phoneme_feature_t; |
| 128 |
|
| 129 |
phoneme_feature_t phoneme_feature_from_string(const char *feature); |
| 130 |
|
| 131 |
// phoneme types |
| 132 |
#define phPAUSE 0 |
| 133 |
#define phSTRESS 1 |
| 134 |
#define phVOWEL 2 |
| 135 |
#define phLIQUID 3 |
| 136 |
#define phSTOP 4 |
| 137 |
#define phVSTOP 5 |
| 138 |
#define phFRICATIVE 6 |
| 139 |
#define phVFRICATIVE 7 |
| 140 |
#define phNASAL 8 |
| 141 |
#define phVIRTUAL 9 |
| 142 |
#define phDELETED 14 |
| 143 |
#define phINVALID 15 |
| 144 |
|
| 145 |
// places of articulation (phARTICULATION) |
| 146 |
#define phPLACE_BILABIAL 1 |
| 147 |
#define phPLACE_LABIODENTAL 2 |
| 148 |
#define phPLACE_DENTAL 3 |
| 149 |
#define phPLACE_ALVEOLAR 4 |
| 150 |
#define phPLACE_RETROFLEX 5 |
| 151 |
#define phPLACE_PALATO_ALVEOLAR 6 |
| 152 |
#define phPLACE_PALATAL 7 |
| 153 |
#define phPLACE_VELAR 8 |
| 154 |
#define phPLACE_LABIO_VELAR 9 |
| 155 |
#define phPLACE_UVULAR 10 |
| 156 |
#define phPLACE_PHARYNGEAL 11 |
| 157 |
#define phPLACE_GLOTTAL 12 |
| 158 |
|
| 159 |
// phflags |
| 160 |
#define phFLAGBIT_UNSTRESSED 1 |
| 161 |
#define phFLAGBIT_VOICELESS 3 |
| 162 |
#define phFLAGBIT_VOICED 4 |
| 163 |
#define phFLAGBIT_SIBILANT 5 |
| 164 |
#define phFLAGBIT_NOLINK 6 |
| 165 |
#define phFLAGBIT_TRILL 7 |
| 166 |
#define phFLAGBIT_PALATAL 9 |
| 167 |
#define phFLAGBIT_BRKAFTER 14 // [*] add a post-pause |
| 168 |
#define phARTICULATION 0xf0000 // bits 16-19 |
| 169 |
#define phFLAGBIT_NONSYLLABIC 20 // don't count this vowel as a syllable when finding the stress position |
| 170 |
#define phFLAGBIT_LONG 21 |
| 171 |
#define phFLAGBIT_LENGTHENSTOP 22 // make the pre-pause slightly longer |
| 172 |
#define phFLAGBIT_RHOTIC 23 |
| 173 |
#define phFLAGBIT_NOPAUSE 24 |
| 174 |
#define phFLAGBIT_PREVOICE 25 // for voiced stops |
| 175 |
#define phFLAGBIT_FLAG1 28 |
| 176 |
#define phFLAGBIT_FLAG2 29 |
| 177 |
#define phFLAGBIT_LOCAL 31 // used during compilation |
| 178 |
|
| 179 |
// phoneme properties |
| 180 |
#define phUNSTRESSED (1U << phFLAGBIT_UNSTRESSED) |
| 181 |
#define phVOICELESS (1U << phFLAGBIT_VOICELESS) |
| 182 |
#define phVOICED (1U << phFLAGBIT_VOICED) |
| 183 |
#define phSIBILANT (1U << phFLAGBIT_SIBILANT) |
| 184 |
#define phNOLINK (1U << phFLAGBIT_NOLINK) |
| 185 |
#define phTRILL (1U << phFLAGBIT_TRILL) |
| 186 |
#define phPALATAL (1U << phFLAGBIT_PALATAL) |
| 187 |
#define phBRKAFTER (1U << phFLAGBIT_BRKAFTER) |
| 188 |
#define phNONSYLLABIC (1U << phFLAGBIT_NONSYLLABIC) |
| 189 |
#define phLONG (1U << phFLAGBIT_LONG) |
| 190 |
#define phLENGTHENSTOP (1U << phFLAGBIT_LENGTHENSTOP) |
| 191 |
#define phRHOTIC (1U << phFLAGBIT_RHOTIC) |
| 192 |
#define phNOPAUSE (1U << phFLAGBIT_NOPAUSE) |
| 193 |
#define phPREVOICE (1U << phFLAGBIT_PREVOICE) |
| 194 |
#define phFLAG1 (1U << phFLAGBIT_FLAG1) |
| 195 |
#define phFLAG2 (1U << phFLAGBIT_FLAG2) |
| 196 |
#define phLOCAL (1U << phFLAGBIT_LOCAL) |
| 197 |
|
| 198 |
// fixed phoneme code numbers, these can be used from the program code |
| 199 |
#define phonCONTROL 1 |
| 200 |
#define phonSTRESS_U 2 |
| 201 |
#define phonSTRESS_D 3 |
| 202 |
#define phonSTRESS_2 4 |
| 203 |
#define phonSTRESS_3 5 |
| 204 |
#define phonSTRESS_P 6 |
| 205 |
#define phonSTRESS_P2 7 // priority stress within a word |
| 206 |
#define phonSTRESS_PREV 8 |
| 207 |
#define phonPAUSE 9 |
| 208 |
#define phonPAUSE_SHORT 10 |
| 209 |
#define phonPAUSE_NOLINK 11 |
| 210 |
#define phonLENGTHEN 12 |
| 211 |
#define phonSCHWA 13 |
| 212 |
#define phonSCHWA_SHORT 14 |
| 213 |
#define phonEND_WORD 15 |
| 214 |
#define phonDEFAULTTONE 17 |
| 215 |
#define phonCAPITAL 18 |
| 216 |
#define phonGLOTTALSTOP 19 |
| 217 |
#define phonSYLLABIC 20 |
| 218 |
#define phonSWITCH 21 |
| 219 |
#define phonX1 22 // a language specific action |
| 220 |
#define phonPAUSE_VSHORT 23 |
| 221 |
#define phonPAUSE_LONG 24 |
| 222 |
#define phonT_REDUCED 25 |
| 223 |
#define phonSTRESS_TONIC 26 |
| 224 |
#define phonPAUSE_CLAUSE 27 |
| 225 |
#define phonVOWELTYPES 28 // 28 to 33 |
| 226 |
|
| 227 |
#define N_PHONEME_TABS 150 // number of phoneme tables |
| 228 |
#define N_PHONEME_TAB 256 // max phonemes in a phoneme table |
| 229 |
#define N_PHONEME_TAB_NAME 32 // must be multiple of 4 |
| 230 |
|
| 231 |
// main table of phonemes, index by phoneme number (1-254) |
| 232 |
|
| 233 |
typedef struct { |
| 234 |
unsigned int mnemonic; // Up to 4 characters. The first char is in the l.s.byte |
| 235 |
unsigned int phflags; // bits 16-19 place of articulation |
| 236 |
unsigned short program; // index into phondata file |
| 237 |
unsigned char code; // the phoneme number |
| 238 |
unsigned char type; // phVOWEL, phPAUSE, phSTOP etc |
| 239 |
unsigned char start_type; |
| 240 |
unsigned char end_type; // vowels: endtype; consonant: voicing switch |
| 241 |
unsigned char std_length; // for vowels, in mS/2; for phSTRESS phonemes, this is the stress/tone type |
| 242 |
unsigned char length_mod; // a length_mod group number, used to access length_mod_tab |
| 243 |
} PHONEME_TAB; |
| 244 |
|
| 245 |
espeak_ng_STATUS |
| 246 |
phoneme_add_feature(PHONEME_TAB *phoneme, |
| 247 |
phoneme_feature_t feature); |
| 248 |
|
| 249 |
// Several phoneme tables may be loaded into memory. phoneme_tab points to |
| 250 |
// one for the current voice |
| 251 |
extern int n_phoneme_tab; |
| 252 |
extern PHONEME_TAB *phoneme_tab[N_PHONEME_TAB]; |
| 253 |
|
| 254 |
typedef struct { |
| 255 |
char name[N_PHONEME_TAB_NAME]; |
| 256 |
PHONEME_TAB *phoneme_tab_ptr; |
| 257 |
int n_phonemes; |
| 258 |
int includes; // also include the phonemes from this other phoneme table |
| 259 |
} PHONEME_TAB_LIST; |
| 260 |
|
| 261 |
// table of phonemes to be replaced with different phonemes, for the current voice |
| 262 |
#define N_REPLACE_PHONEMES 60 |
| 263 |
typedef struct { |
| 264 |
unsigned char old_ph; |
| 265 |
unsigned char new_ph; |
| 266 |
char type; // 0=always replace, 1=only at end of word |
| 267 |
} REPLACE_PHONEMES; |
| 268 |
|
| 269 |
extern int n_replace_phonemes; |
| 270 |
extern REPLACE_PHONEMES replace_phonemes[N_REPLACE_PHONEMES]; |
| 271 |
|
| 272 |
// Table of phoneme programs and lengths. Used by MakeVowelLists |
| 273 |
typedef struct { |
| 274 |
unsigned int addr; |
| 275 |
unsigned int length; |
| 276 |
} PHONEME_PROG_LOG; |
| 277 |
|
| 278 |
#define PhonemeCode2(c1, c2) PhonemeCode((c2<<8)+c1) |
| 279 |
|
| 280 |
extern PHONEME_TAB_LIST phoneme_tab_list[N_PHONEME_TABS]; |
| 281 |
extern int phoneme_tab_number; |
| 282 |
|
| 283 |
#ifdef __cplusplus |
| 284 |
} |
| 285 |
#endif |
| 286 |
|
| 287 |
#endif |