Debian Codegraph @

sapi/FliteTTSEngineObj/flite_sapi_usenglish.c

raw
1 /*************************************************************************/
2 /* */
3 /* Cepstral, LLC */
4 /* Copyright (c) 2001 */
5 /* All Rights Reserved. */
6 /* */
7 /* Permission is hereby granted, free of charge, to use and distribute */
8 /* this software and its documentation without restriction, including */
9 /* without limitation the rights to use, copy, modify, merge, publish, */
10 /* distribute, sublicense, and/or sell copies of this work, and to */
11 /* permit persons to whom this work is furnished to do so, subject to */
12 /* the following conditions: */
13 /* 1. The code must retain the above copyright notice, this list of */
14 /* conditions and the following disclaimer. */
15 /* 2. Any modifications must be clearly marked as such. */
16 /* 3. Original authors' names are not deleted. */
17 /* 4. The authors' names are not used to endorse or promote products */
18 /* derived from this software without specific prior written */
19 /* permission. */
20 /* */
21 /* CEPSTRAL, LLC AND THE CONTRIBUTORS TO THIS WORK DISCLAIM ALL */
22 /* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED */
23 /* WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL */
24 /* CEPSTRAL, LLC NOR THE CONTRIBUTORS BE LIABLE FOR ANY SPECIAL, */
25 /* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER */
26 /* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION */
27 /* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR */
28 /* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
29 /* */
30 /*************************************************************************/
31 /* Author: David Huggins-Daines ([email protected]) */
32 /* Date: December 2001 */
33 /*************************************************************************/
34 /* */
35 /* flite_sapi_usenglish.c: US English specific functions for Flite/SAPI */
36 /* */
37 /*************************************************************************/
38
39 #include "flite_sapi_usenglish.h"
40 #include "cst_string.h"
41
42 static const char *sapi_usenglish_phones[] = {
43 NULL, NULL, NULL, NULL, NULL, NULL, NULL, "pau", "1",
44 "2", "aa", "ae", "ah", "ao", "aw", "ax", "ay", "b",
45 "ch", "d", "dh", "eh", "er", "ey", "f", "g", "hh", "ih",
46 "iy", "jh", "k", "l", "m", "n", "ng", "ow", "oy", "p",
47 "r", "s", "sh", "t", "th", "uh", "uw", "v", "w", "y",
48 "z", "zh"
49 };
50 static const int sapi_usenglish_nphones = (sizeof(sapi_usenglish_phones)
51 / sizeof(sapi_usenglish_phones[0]));
52
53 static const char *vis0[] = {"pau", NULL};
54 static const char *vis1[] = {"ae", "ax", "ah", NULL};
55 static const char *vis2[] = {"aa", NULL};
56 static const char *vis3[] = {"ao", NULL};
57 static const char *vis4[] = {"ey", "eh", "uh", NULL};
58 static const char *vis5[] = {"er", NULL};
59 static const char *vis6[] = {"y", "iy", "ih", NULL};
60 static const char *vis7[] = {"w", "uw", NULL};
61 static const char *vis8[] = {"ow", NULL};
62 static const char *vis9[] = {"aw", NULL};
63 static const char *vis10[] = {"oy", NULL};
64 static const char *vis11[] = {"ay", NULL};
65 static const char *vis12[] = {"hh", NULL};
66 static const char *vis13[] = {"r", NULL};
67 static const char *vis14[] = {"l", NULL};
68 static const char *vis15[] = {"s", "z", NULL};
69 static const char *vis16[] = {"sh", "ch", "jh", "zh", NULL};
70 static const char *vis17[] = {"th", "dh", NULL};
71 static const char *vis18[] = {"f", "v", NULL};
72 static const char *vis19[] = {"d", "t", "n", NULL};
73 static const char *vis20[] = {"k", "g", "ng", NULL};
74 static const char *vis21[] = {"p", "b", "m", NULL};
75
76 static const struct {
77 int vis;
78 const char *const *phones;
79 } sapi_usenglish_visemes[] = {
80 { SP_VISEME_0, vis0 },
81 { SP_VISEME_1, vis1 },
82 { SP_VISEME_2, vis2 },
83 { SP_VISEME_3, vis3 },
84 { SP_VISEME_4, vis4 },
85 { SP_VISEME_5, vis5 },
86 { SP_VISEME_6, vis6 },
87 { SP_VISEME_7, vis7 },
88 { SP_VISEME_8, vis8 },
89 { SP_VISEME_9, vis9 },
90 { SP_VISEME_10, vis10 },
91 { SP_VISEME_11, vis11 },
92 { SP_VISEME_12, vis12 },
93 { SP_VISEME_13, vis13 },
94 { SP_VISEME_14, vis14 },
95 { SP_VISEME_15, vis15 },
96 { SP_VISEME_16, vis16 },
97 { SP_VISEME_17, vis17 },
98 { SP_VISEME_18, vis18 },
99 { SP_VISEME_19, vis19 },
100 { SP_VISEME_20, vis20 },
101 { SP_VISEME_21, vis21 },
102 { -1, NULL }
103 };
104
105 int
106 flite_sapi_usenglish_phoneme(cst_item *s)
107 {
108 const char *name;
109 int i;
110
111 if (s == NULL)
112 return 0;
113
114 name = item_name(s);
115 for (i = 0; i < sapi_usenglish_nphones; ++i)
116 if (sapi_usenglish_phones[i]
117 && cst_streq(sapi_usenglish_phones[i], name))
118 break;
119 if (i == sapi_usenglish_nphones)
120 return 0;
121 return i;
122 }
123
124 int
125 flite_sapi_usenglish_viseme(cst_item *s)
126 {
127 const char *name;
128 int i;
129
130 /* FIXME: Is 0 a valid viseme or not? */
131 if (s == NULL)
132 return -1;
133
134 name = item_name(s);
135 for (i = 0; sapi_usenglish_visemes[i].phones; ++i)
136 if (cst_member_string(name, sapi_usenglish_visemes[i].phones))
137 break;
138 return sapi_usenglish_visemes[i].vis;
139 }
140
141 int
142 flite_sapi_usenglish_feature(cst_item *s)
143 {
144 int feat = 0;
145
146 if (s == NULL)
147 return 0;
148
149 if (ffeature_int(s, "R:SylStructure.parent.stress"))
150 feat |= SPVFEATURE_STRESSED;
151 if (ffeature_int(s, "R:SylStructure.parent.accented"))
152 feat |= SPVFEATURE_EMPHASIS;
153
154 return feat;
155 }
156
157 cst_val *
158 flite_sapi_usenglish_pronounce(SPPHONEID *pids)
159 {
160 SPPHONEID *p;
161 cst_val *phones = NULL;
162
163 for (p = pids; *p; ++p) {
164 const char *pname;
165
166 if (*p >= sapi_usenglish_nphones)
167 continue;
168 pname = sapi_usenglish_phones[*p];
169 if (pname == NULL)
170 continue;
171 if (isdigit(pname[0])) {
172 /* stress numbers */
173 if (phones) {
174 char *psname;
175 cst_val *car, *cdr;
176
177 car = (cst_val *) val_car(phones);
178 cdr = (cst_val *) val_cdr(phones);
179 psname = cst_alloc(char,
180 strlen(val_string(car))
181 + strlen(pname) + 1);
182 sprintf(psname, "%s%s", val_string(car), pname);
183 phones = cons_val(string_val(psname), cdr);
184 cst_free(psname);
185 delete_val(car);
186 }
187 } else
188 phones = cons_val(string_val(pname), phones);
189 }
190 return val_reverse(phones);
191 }