upstream version 1.2.2
[debian/freetts] / tools / ArcticToFreeTTS / ArcticToFreeTTS.sh
1 #!/bin/bash
2 # Portions Copyright 2004 Sun Microsystems, Inc.
3 # Portions Copyright 1999-2003 Language Technologies Institute,
4 # Carnegie Mellon University.
5 # All Rights Reserved.  Use is subject to license terms.
6 #
7 # See the file "license.terms" for information on usage and
8 # redistribution of this file, and for a DISCLAIMER OF ALL
9 # WARRANTIES.
10
11 # Shell script to do a lot of the work to import a cluster
12 # unit selection voice into FreeTTS.  This is still a work
13 # in progress.
14
15 # You should override these environment variables to match
16 # your environment.
17 #
18 export JAVA_HOME=/usr
19 export ESTDIR=/Users/wwalker/work/festival/speech_tools
20 export FESTIVALDIR=/Users/wwalker/work/festival/festival
21 export FESTVOXDIR=/Users/wwalker/work/festival/festvox
22 export FREETTSDIR=/Users/wwalker/work/SourceForge/FreeTTS/FreeTTS
23
24 export HELPERDIR=$FREETTSDIR/tools/ArcticToFreeTTS
25
26 export JAVAHEAP=-mx512m
27
28
29
30
31 # Compile the helping Java classes
32 #
33 (cd $HELPERDIR; mkdir -p classes; cd src; javac -d ../classes *.java)
34
35
36
37
38 # Get FV_VOICENAME and FV_FULLVOICENAME
39 #
40 . ./etc/voice.defs
41
42 echo Importing $FV_VOICENAME
43
44 export VOICEDIR=$FREETTSDIR/com/sun/speech/freetts/en/us/$FV_VOICENAME
45
46 mkdir -p FreeTTS
47 mkdir -p $VOICEDIR
48
49
50
51
52 # Import F0_MEAN (for setPitch) and F0_RANGE (for setPitchRange)
53 #
54 # [[[WDW FIXME: Currently unused.]]]
55 #
56 $FESTIVALDIR/bin/festival -b \
57     festvox/$FV_FULLVOICENAME.scm \
58     $HELPERDIR/scheme/dump_f0_terms.scm \
59     "(begin (voice_${FV_FULLVOICENAME}) (dump_f0_terms))" > \
60     /tmp/foo.sh
61 chmod +x /tmp/foo.sh
62 . /tmp/foo.sh
63
64
65
66
67 ########################################################################
68 #                                                                      #
69 # Create voice-specific files that are not part of the big database.   #
70 #                                                                      #
71 # [[[WDW FIXME: Currently copies some files from FreeTTS instead of    #
72 #    generating them directly from the voice data itself.]]]           #
73 #                                                                      #
74 ########################################################################
75
76 echo Creating $VOICEDIR/dur_stat.txt
77 $FESTIVALDIR/bin/festival -b \
78     festvox/$FV_FULLVOICENAME.scm \
79     $HELPERDIR/scheme/dump_dur_stat.scm \
80     "(begin (voice_${FV_FULLVOICENAME}) (dump_dur_stat))" > \
81     $VOICEDIR/dur_stat.txt
82
83
84
85
86 echo Creating $VOICEDIR/durz_cart.txt
87 $FESTIVALDIR/bin/festival -b \
88     festvox/$FV_FULLVOICENAME.scm \
89     $HELPERDIR/scheme/dump_durz_cart.scm \
90     "(begin (voice_${FV_FULLVOICENAME}) (dump_durz_cart))" > \
91     $VOICEDIR/durz_cart.txt
92
93
94
95
96 echo Creating $VOICEDIR/f0_lr_terms.txt
97 cp $FREETTSDIR/com/sun/speech/freetts/en/us/f0_lr_terms.txt $VOICEDIR
98
99
100
101
102 echo Creating $VOICEDIR/int_accent_cart.txt
103 cp $FREETTSDIR/com/sun/speech/freetts/en/us/int_accent_cart.txt $VOICEDIR
104
105
106
107
108 echo Creating $VOICEDIR/int_tone_cart.txt
109 cp $FREETTSDIR/com/sun/speech/freetts/en/us/int_tone_cart.txt $VOICEDIR
110
111
112
113
114 echo Creating $VOICEDIR/nums_cart.txt
115 cp $FREETTSDIR/com/sun/speech/freetts/en/us/nums_cart.txt $VOICEDIR
116
117
118
119
120 echo Creating $VOICEDIR/part_of_speech.txt
121 $FESTIVALDIR/bin/festival -b \
122     festvox/$FV_FULLVOICENAME.scm \
123     $HELPERDIR/scheme/dump_pos.scm \
124     "(begin (voice_${FV_FULLVOICENAME}) (dump_pos))" > \
125     $VOICEDIR/part_of_speech.txt
126
127
128
129
130 echo Creating $VOICEDIR/phoneset.txt
131 $FESTIVALDIR/bin/festival -b \
132     festvox/$FV_FULLVOICENAME.scm \
133     $HELPERDIR/scheme/dump_phoneset.scm \
134     "(begin (voice_${FV_FULLVOICENAME}) (dump_phoneset))" > \
135     $VOICEDIR/phoneset.txt
136
137
138
139
140 echo Creating $VOICEDIR/phrasing_cart.txt
141 cp $FREETTSDIR/com/sun/speech/freetts/en/us/phrasing_cart.txt $VOICEDIR
142
143
144
145
146 echo Creating $VOICEDIR/prefix_fsm.txt
147 cp $FREETTSDIR/com/sun/speech/freetts/en/us/prefix_fsm.txt $VOICEDIR
148
149
150
151
152 echo Creating $VOICEDIR/suffix_fsm.txt
153 cp $FREETTSDIR/com/sun/speech/freetts/en/us/suffix_fsm.txt $VOICEDIR
154
155
156
157
158 ########################################################################
159 #                                                                      #
160 # Create voice-specific files that are part of the big database.       #
161 # These will ultimately be concatenated together to make the big txt   #
162 # file for the voice data.                                             #
163 #                                                                      #
164 ########################################################################
165
166 echo Creating lpc files
167 mkdir -p lpc
168 bin/make_lpc wav/*.wav
169
170
171
172
173 echo Creating lpc/lpc.params
174 for file in lpc/*.lpc; do
175     $ESTDIR/bin/ch_track -otype est_ascii $file
176 done | sed '1,/EST_Header_End/d' |
177 awk 'BEGIN {min=0; max=0;} {
178          for (i=4; i<=NF; i++) {
179              if ($i < min) min = $i;
180              if ($i > max) max = $i;
181          }
182      } END {
183          printf("LPC_MIN=%f\n",min);
184          printf("LPC_MAX=%f\n",max);
185          printf("LPC_RANGE=%f\n",max-min);
186      }' > lpc/lpc.params
187
188
189
190
191 echo Creating mcep/mcep.params and converting mcep files to text
192 for file in mcep/*.mcep; do
193     echo $file MCEP
194     $ESTDIR/bin/ch_track -otype est_ascii $file > $file.txt
195     cat $file.txt
196 done | sed '1,/EST_Header_End/d' |
197 awk 'BEGIN {min=0; max=0;} {
198          for (i=4; i<=NF; i++) {
199              if ($i < min) min = $i;
200              if ($i > max) max = $i;
201          }
202      } END {
203          printf("MCEP_MIN=%f\n",min);
204          printf("MCEP_MAX=%f\n",max);
205          printf("MCEP_RANGE=%f\n",max-min);
206      }' > mcep/mcep.params
207
208
209
210
211 echo "Creating short term signal (STS) files in sts/*.sts"
212 mkdir -p sts
213 java -cp $HELPERDIR/classes FindSTS \
214     `find wav -type f | cut -f2 -d/ | cut -f1 -d.`
215
216
217
218
219 echo Creating FreeTTS/misc.txt
220 $FESTIVALDIR/bin/festival -b \
221     festvox/$FV_FULLVOICENAME.scm \
222     $HELPERDIR/scheme/dump_misc.scm \
223     "(begin (voice_${FV_FULLVOICENAME}) (dump_misc))" > \
224     FreeTTS/misc.txt
225
226
227
228
229 # UnitDatabase outputs its own info...
230
231 java $JAVAHEAP -cp $HELPERDIR/classes UnitDatabase \
232     festival/clunits/${FV_VOICENAME}.catalogue \
233     `find wav -type f | cut -f2 -d/ | cut -f1 -d.`
234
235
236
237
238 echo Creating FreeTTS/trees.txt
239 $FESTIVALDIR/bin/festival -b \
240     festvox/$FV_FULLVOICENAME.scm \
241     $HELPERDIR/scheme/dump_trees.scm \
242     "(begin (voice_${FV_FULLVOICENAME}) (dump_trees))" > \
243     FreeTTS/trees.txt
244
245
246
247
248 echo Creating FreeTTS/weights.txt
249 $FESTIVALDIR/bin/festival -b \
250     festvox/$FV_FULLVOICENAME.scm \
251     $HELPERDIR/scheme/dump_join_weights.scm \
252     "(begin (voice_${FV_FULLVOICENAME}) (dump_join_weights))" > \
253     FreeTTS/weights.txt
254
255
256
257
258 ########################################################################
259 #                                                                      #
260 # Now create the big database file and also set up the *.java files    #
261 # for this voice.                                                      #
262 #                                                                      #
263 ########################################################################
264
265 echo Creating $VOICEDIR/$FV_VOICENAME.txt
266 (cd FreeTTS; cat misc.txt unit_catalog.txt trees.txt unit_index.txt sts.txt mcep.txt weights.txt > $VOICEDIR/$FV_VOICENAME.txt)
267
268
269
270
271 echo Creating $VOICEDIR/ArcticVoiceDirectory.java
272 cat $HELPERDIR/ArcticVoiceDirectory.java.template | \
273     sed "s/%FV_VOICENAME%/$FV_VOICENAME/g" | \
274     sed "s/%FV_NAME%/$FV_NAME/g" | \
275     sed "s/%FV_INST%/$FV_INST/g" > \
276     $VOICEDIR/ArcticVoiceDirectory.java
277
278
279
280
281 echo Creating $VOICEDIR/ArcticVoice.java
282 cat $HELPERDIR/ArcticVoice.java.template | \
283     sed "s/%FV_VOICENAME%/$FV_VOICENAME/g" | \
284     sed "s/%FV_NAME%/$FV_NAME/g" | \
285     sed "s/%FV_INST%/$FV_INST/g" > \
286     $VOICEDIR/ArcticVoice.java
287
288
289
290
291 echo Creating $VOICEDIR/voice.Manifest
292 cat $HELPERDIR/voice.Manifest.template | \
293     sed "s/%FV_VOICENAME%/$FV_VOICENAME/g" | \
294     sed "s/%FV_NAME%/$FV_NAME/g" | \
295     sed "s/%FV_INST%/$FV_INST/g" > \
296     $VOICEDIR/voice.Manifest
297
298
299
300
301 echo Compiling $FV_VOICENAME
302 (cd $FREETTSDIR; ant -Darctic_voice=$FV_VOICENAME)
303
304
305
306
307 echo Done.