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 /* */
34 /* Author: Paul Taylor */
35 /* Date: February 1998 */
36 /* --------------------------------------------------------------------- */
37 /* Waveform Generation Scheme Interface File */
38 /* */
39 /*************************************************************************/
40
41 #include "EST.h"
42 #include "us_diphone.h"
43 #include "festival.h"
44
45 extern USDiphIndex *diph_index;
46 LISP us_dbs = NIL;
47 LISP us_make_group_file(LISP lname, LISP params);
48
49 int read_diphone_index(const EST_String &filename,
50 USDiphIndex &di);
51 void us_check_db();
52
53
54 void us_add_diphonedb(USDiphIndex *db);
55
FT_us_get_diphones(LISP lutt)56 LISP FT_us_get_diphones(LISP lutt)
57 {
58 EST_Utterance *utt = get_c_utt(lutt);
59
60 us_get_diphones(*utt);
61
62 return lutt;
63 }
64
us_select_db(LISP name)65 LISP us_select_db(LISP name)
66 {
67 // Select diphone set
68 LISP lpair;
69
70 lpair = siod_assoc_str(get_c_string(name),us_dbs);
71
72 if (lpair == NIL)
73 EST_error("US DB: no diphone database named \"%s\" defined\n",
74 (const char *) get_c_string(name));
75 else
76 diph_index = us_db(car(cdr(lpair)));
77
78 return name;
79 }
80
us_list_dbs(void)81 LISP us_list_dbs(void)
82 {
83 // List names of currently loaded dbs
84 LISP names,n;
85
86 for (names=NIL,n=us_dbs; n != NIL; n=cdr(n))
87 names = cons(car(car(n)),names);
88 return reverse(names);
89 }
90
us_db_params(void)91 LISP us_db_params(void)
92 {
93 // Return parameters of current db
94
95 us_check_db();
96 return diph_index->params;
97 }
98
us_diphone_init(LISP args)99 LISP us_diphone_init(LISP args)
100 {
101 EST_String x;
102 USDiphIndex *d_index = new USDiphIndex;
103 d_index->grouped = false;
104 d_index->params = args;
105 d_index->name = get_param_str("name",args,"name");
106 d_index->index_file = get_param_str("index_file",args,"");
107
108 read_diphone_index(d_index->index_file, *d_index);
109
110 // This is needed because there is no get_param_EST_String function
111 x = get_param_str("grouped",args,"");
112 if (x == "true")
113 {
114 d_index->grouped = true;
115 if (d_index->ts.open(d_index->index_file) != 0)
116 {
117 cerr << "US DB: can't open grouped diphone file "
118 << d_index->index_file << endl;
119 festival_error();
120 }
121 // set up the character constant values for this stream
122 d_index->ts.set_SingleCharSymbols(";");
123 }
124 else
125 {
126 *cdebug << ":" << get_param_str("grouped",args,"") << ":" << endl
127 << "index grouped:" << d_index->grouped << endl
128 << "true:" << true << endl
129 << "false:" << false << endl;
130
131 d_index->coef_dir = get_param_str("coef_dir",args,"");
132 d_index->sig_dir = get_param_str("sig_dir",args,"");
133
134 d_index->coef_ext = get_param_str("coef_ext",args,"");
135 d_index->sig_ext = get_param_str("sig_ext",args,"");
136 }
137
138 us_add_diphonedb(d_index);
139
140 return rintern(d_index->name);
141 }
142
FT_us_full_cut(LISP lutt,LISP lrname)143 LISP FT_us_full_cut(LISP lutt, LISP lrname)
144 {
145 EST_Utterance *utt = get_c_utt(lutt);
146 EST_String rname = get_c_string(lrname);
147
148 us_full_cut(*utt->relation(rname));
149
150 // parse_diphone_times(*(utt->relation(rname)),
151 // *(utt->relation("SourceSegments")));
152
153 return lutt;
154 }
155
festival_UniSyn_diphone_init(void)156 void festival_UniSyn_diphone_init(void)
157 {
158 proclaim_module("UniSyn_diphone");
159
160 init_subr_0("us_list_dbs", us_list_dbs,
161 "(us_list_dbs)\n\
162 List names of UniSyn databases currently loaded.");
163
164 init_subr_0("us_db_params", us_db_params,
165 "(us_db_params)\n\
166 Return parameters of current UniSyn database.");
167
168 init_subr_1("us_db_select", us_select_db,
169 "(us_db_select NAME)\n\
170 Select named UniSyn database.");
171
172 init_subr_1("us_get_diphones", FT_us_get_diphones,
173 "(us_get_synthesis UTT)\n\
174 Construct a unit stream in UTT comprising suitable diphones. The unit \n\
175 stream produced is suitable for immediate use in us_ps_synthesis.");
176
177 init_subr_2("us_make_group_file", us_make_group_file,
178 "(us_make_group_file FILENAME PARAMS)\n\
179 Make a group file from the currently specified diphone set. PARAMS \n\
180 is an optional assoc list and allows specification of the \n\
181 track_file_format (default est_binary), sig_file_format (default \n\
182 snd) and sig_sample_format (default mulaw). This is recommended \n\
183 for LPC databases. For PSOLA based databases the sig_sample_format \n\
184 should probably be set to short.");
185
186 init_subr_2("us_full_cut", FT_us_full_cut,
187 "(us_ps_synthesis UTT SIGPR)\n\
188 Synthesize utterance UTT using signal processing technique SIGPR \n\
189 for the UniSyn pitch-synchronous synthesizer.");
190
191 init_subr_1("us_diphone_init", us_diphone_init,
192 "(us_diphone_init DIPHONE_NAME)\n\
193 Initialise UniSyn diphone synthesizer with database DIPHONE_NAME.");
194
195 init_subr_1("diphone_present", us_check_diphone_presence,
196 "(diphone_present? STR)\n\
197 Checks whether the given STRing corresponds to any diphone in the\n\
198 current database.");
199
200 }
201