File: build_flite

package info (click to toggle)
flite 1.4-release-12
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 82,784 kB
  • ctags: 146,840
  • sloc: ansic: 636,986; sh: 3,685; lisp: 2,496; makefile: 900; cpp: 804; xml: 52
file content (365 lines) | stat: -rwxr-xr-x 12,296 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#!/bin/sh
###########################################################################
##                                                                       ##
##                  Language Technologies Institute                      ##
##                     Carnegie Mellon University                        ##
##                      Copyright (c) 2002-2009                          ##
##                        All Rights Reserved.                           ##
##                                                                       ##
##  Permission is hereby granted, free of charge, to use and distribute  ##
##  this software and its documentation without restriction, including   ##
##  without limitation the rights to use, copy, modify, merge, publish,  ##
##  distribute, sublicense, and/or sell copies of this work, and to      ##
##  permit persons to whom this work is furnished to do so, subject to   ##
##  the following conditions:                                            ##
##   1. The code must retain the above copyright notice, this list of    ##
##      conditions and the following disclaimer.                         ##
##   2. Any modifications must be clearly marked as such.                ##
##   3. Original authors' names are not deleted.                         ##
##   4. The authors' names are not used to endorse or promote products   ##
##      derived from this software without specific prior written        ##
##      permission.                                                      ##
##                                                                       ##
##  CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK         ##
##  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING      ##
##  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   ##
##  SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE      ##
##  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    ##
##  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   ##
##  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          ##
##  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       ##
##  THIS SOFTWARE.                                                       ##
##                                                                       ##
###########################################################################
##                                                                       ##
##  Build a flite voice from a festvox voice                             ##
##                                                                       ##
##  C files are built into flite/                                        ##
##                                                                       ##
###########################################################################

FIND_STS=$FLITEDIR/bin/find_sts
FESTIVAL=$ESTDIR/../festival/bin/festival

if [ "$PROMPTFILE" = "" ]
then
   if [ $# = 2 ]
   then
      export PROMPTFILE=$2
   else
      export PROMPTFILE=etc/txt.done.data
   fi
fi

HEAPSIZE=20000000

. ./etc/voice.defs

if [ $# = 0 ]
then
   if [ "$FV_TYPE" = "clunits" ]
   then
      $0 lpc
      $0 sts
      $0 mcep
      $0 clunits
   elif [ "$FV_TYPE" = "ldom" ]
   then
      $0 lpc
      $0 sts
      $0 mcep
      $0 clunits
   elif [ "$FV_TYPE" = "diphone" ]
   then
      $0 lpc
      $0 sts
      $0 diphone
   elif [ "$FV_TYPE" = "cg" ]
   then
      $0 cg
   else
      echo $0 unsupported voicetype $FV_TYPE
   fi   
   exit 0
fi

# Build lpc coefficients
if [ "$1" = "lpc" ]
then
   echo "Finding LPC coefficients"

   ./bin/make_lpc $PROMPTFILE

   echo "Finding LPC min, max and range"
   # make lpc.params file
   cat $PROMPTFILE |
   awk '{print $2}' |
   while read i
   do
      $ESTDIR/bin/ch_track -otype est_ascii lpc/$i.lpc | 
      sed '1,/EST_Header_End/d'
   done |
   awk 'BEGIN {min=0; max=0;}
        {for (i=4; i<=NF; i++)
        {
            if ($i < min) min = $i;
            if ($i > max) max = $i;
        }
     } 
     END {printf("LPC_MIN=%f\n",min);
          printf("LPC_MAX=%f\n",max);
          printf("LPC_RANGE=%f\n",max-min);
         }' >lpc/lpc.params

   exit 0
fi

# build sts files
if [ "$1" = "sts" ]
then
   echo "Finding STS files"
   if [ ! -d sts ]
   then
      mkdir sts
   fi
   . ./lpc/lpc.params

   cat $PROMPTFILE |
   awk '{print $2}' |
   while read i
   do
      fname=$i
      echo $fname STS
      $FIND_STS $LPC_MIN $LPC_RANGE lpc/$fname.lpc wav/$fname.wav sts/$fname.sts
   done

   exit 0
fi

# build mcep (params)
if [ "$1" = "mcep" ]
then
   echo "Finding MCEP min max and range"
   cat $PROMPTFILE |
   awk '{print $2}' |
   while read i
   do
      $ESTDIR/bin/ch_track -otype est_ascii mcep/$i.mcep |
      sed '1,/EST_Header_End/d'
   done |
   awk 'BEGIN {min=0; max=0;}
        {for (i=4; i<=NF; i++)
        {
            if ($i < min) min = $i;
            if ($i > max) max = $i;
        }
     } 
     END {printf("(set! mcep_min %f)\n",min);
          printf("(set! mcep_max %f)\n",max);
          printf("(set! mcep_range %f)\n",max-min);
         }' >mcep/mcep.params.scm
   exit 0
fi

if [ "$1" = "cg" ]  # clustergen
then
   # For smaller (and quicker) voices you can build with a reduced order
   # this seems to be ok for values down to 13 
   RORDER=0  
   if [ $# = 2 ]
   then
      RORDER=$2
   fi
   echo cg_convert: finding parameter ranges
   $ESTDIR/bin/ch_track -otype est_ascii festival/trees/${FV_VOICENAME}_mcep*.params |
   sed '1,/EST_Header_End/d' |
   awk 'BEGIN {nc=0;}
        {if (nc == 0) nc = NF;
        if (NF == nc )
        {
           for (i=3; i<=NF; i++)
           {
               if ((NR == 1) || ($i < min[i])) min[i] = $i;
               if ((NR == 1) || ($i > max[i])) max[i] = $i;
           }
           nc = NF;
        }
     } 
     END {for (i=3; i<=nc; i++)
          {
             printf("( %f %f )\n",min[i],max[i]-min[i]);
          }
         }' >festival/trees/${FV_VOICENAME}_min_range.scm
   cat etc/f0.params |
   sed 's/=/ /' |
   head -2 |
   awk '{printf("(set! %s %s)\n",$1,$2)}' >flite/f0_params.scm

   $FESTIVAL --heap $HEAPSIZE -b \
         '(set! cg_reduced_order '$RORDER')' \
          flite/f0_params.scm \
          $FLITEDIR/tools/make_cg.scm \
          $FLITEDIR/tools/make_cart.scm \
          $FLITEDIR/tools/make_vallist.scm \
         '(cg_convert 
                   "'$FV_VOICENAME'"
                   "."
                   "flite/")'

   echo "flite_build cg complete.  You can compile the generated voice by"
   echo "   cd flite; make"

   exit 0
fi

if [ "$1" = "clunits" ]  # clunits or ldom 
then
   echo "Building clunits/ldom index"
   sed '1,/EST_Header_End/d' festival/clunits/$FV_VOICENAME.catalogue |
   awk 'BEGIN {p="CLUNIT_NONE";}
        {if ((NR > 1) && (t != "0_0"))
        {
            n = split(t,bits,"_");
            unit_type = substr(t,1,length(t)-(length(bits[n])+1));
            unit_occur = bits[n];
            if ((t == "0_0") || (f != $2) || ($1 == "0_0"))
               printf("%s-%05d -- ( %s %s %s )\n",unit_type,unit_occur,line,p,"CLUNIT_NONE");
            else
               printf("%s-%05d -- ( %s %s unit_%s )\n",unit_type,unit_occur, line,p,$1);
         }
         line = $0;
         if ((t == "0_0") || (f != $2))
            p = "CLUNIT_NONE";
         else
             p=sprintf("unit_%s",t);
         t=$1;
         f=$2;
        } 
        END { if (t != "0_0")
              {
                n = split(t,bits,"_");
                unit_type = substr(t,1,length(t)-(length(bits[n])+1));
                unit_occur = bits[n];
                printf("%s-%05d -- ( %s %s %s )\n", unit_type,unit_occur,line,p,"CLUNIT_NONE");
              } }' |
        cat >festival/clunits/$FV_VOICENAME.scm
        cat festival/clunits/$FV_VOICENAME.scm |
        $FLITEDIR/bin/flite_sort |
        sed 's/^.* -- //'  >festival/clunits/$FV_VOICENAME.unitordered.scm
        cat festival/clunits/$FV_VOICENAME.scm |
        sed 's/^.* -- //'  >festival/clunits/$FV_VOICENAME.fileordered.scm

   rm -f flite/$FV_VOICENAME"_lpc"*
   rm -f flite/$FV_VOICENAME"_mcep"*
   $FESTIVAL --heap $HEAPSIZE -b $FLITEDIR/tools/make_clunits.scm \
          $FLITEDIR/tools/make_cart.scm \
          $FLITEDIR/tools/make_vallist.scm \
          mcep/mcep.params.scm \
         '(clunits_convert "'$FV_VOICENAME'"
                   "festival/clunits/'$FV_VOICENAME'.fileordered.scm"
                   "festival/clunits/'$FV_VOICENAME'.unitordered.scm"
                   "festival/trees/'$FV_VOICENAME'.tree"
                   "."
                   "flite/")'

   echo "flite_build complete.  You can compile the generated voice by"
   echo "   cd flite; make"
   exit 0
fi

if [ "$1" = "diphone" ]
then
   echo "Building diphone index"
   # Not a good way to do this, to take the most recent
   idxfile=`ls -t dic/*.est | head -1`
   echo "Using "$idxfile
   sed '1,/EST_Header_End/d' $idxfile |
   awk '{printf("%s ( %s )\n",$1,$0)}' |
   $FLITEDIR/bin/flite_sort |
   sed 's/^.* (/(/' >dic/diphidx.scm
   $FESTIVAL --heap $HEAPSIZE -b $FLITEDIR/tools/make_didb2.scm \
     '(diphtoC "dic/diphidx.scm" "'$FV_VOICENAME'" "sts" "flite")'

   echo "flite_build complete.  You can compile the generated voice by"
   echo "   cd flite; make"
   exit 0
fi

# build index file
if [ "$1" = "idx" ]
then
   HEAPSIZE=10000000
   if [ "$FV_TYPE" != "diphone" ]  # clunits or ldom 
   then
      echo "Building clunits/ldom index"
      sed '1,/EST_Header_End/d' festival/clunits/$FV_VOICENAME.catalogue |
      awk 'BEGIN {p="CLUNIT_NONE";}
           {if ((NR > 1) && (t != "0_0"))
           {
               n = split(t,bits,"_");
               unit_type = substr(t,1,length(t)-(length(bits[n])+1));
               unit_occur = bits[n];
               if ((t == "0_0") || (f != $2) || ($1 == "0_0"))
                  printf("%s_%05d -- ( %s %s %s )\n",unit_type,unit_occur,line,p,"CLUNIT_NONE");
               else
                  printf("%s_%05d -- ( %s %s unit_%s )\n",unit_type,unit_occur, line,p,$1);
            }
            line = $0;
   	    if ((t == "0_0") || (f != $2))
                p = "CLUNIT_NONE";
            else
                p=sprintf("unit_%s",t);
            t=$1;
            f=$2;
           } 
           END { if (t != "0_0")
                 {
                   n = split(t,bits,"_");
                   unit_type = substr(t,1,length(t)-(length(bits[n])+1));
                   unit_occur = bits[n];
                   printf("%s_%05d -- ( %s %s %s )\n", unit_type,unit_occur,line,p,"CLUNIT_NONE");
                 } }' |
           cat >festival/clunits/$FV_VOICENAME.scm
           cat festival/clunits/$FV_VOICENAME.scm |
	   $FLITEDIR/bin/flite_sort |
           sed 's/^.* -- //'  >festival/clunits/$FV_VOICENAME.unitordered.scm
           cat festival/clunits/$FV_VOICENAME.scm |
           sed 's/^.* -- //'  >festival/clunits/$FV_VOICENAME.fileordered.scm

      rm -f flite/$FV_VOICENAME"_lpc"*
      rm -f flite/$FV_VOICENAME"_mcep"*
      $FESTIVAL --heap $HEAPSIZE -b $FLITEDIR/tools/make_clunits.scm \
             $FLITEDIR/tools/make_cart.scm \
             $FLITEDIR/tools/make_vallist.scm \
             mcep/mcep.params.scm \
            '(clunits_convert "'$FV_VOICENAME'"
                      "festival/clunits/'$FV_VOICENAME'.fileordered.scm"
                      "festival/clunits/'$FV_VOICENAME'.unitordered.scm"
                      "festival/trees/'$FV_VOICENAME'.tree"
                      "."
                      "flite/")'
   fi
   if [ "$FV_TYPE" = "diphone" ]
   then
      echo "Building diphone index"
      # Not a good way to do this, to take the most recent
      idxfile=`ls -t dic/*.est | head -1`
      echo "Using "$idxfile
      sed '1,/EST_Header_End/d' $idxfile |
      awk '{printf("%s ( %s )\n",$1,$0)}' |
      $FLITEDIR/bin/flite_sort |
      sed 's/^.* (/(/' >dic/diphidx.scm

      $FESTIVAL --heap $HEAPSIZE -b $FLITEDIR/tools/make_didb.scm \
      '(diphtoC "dic/diphidx.scm" "'$FV_VOICENAME'" "sts" "flite")'

   fi

   echo "flite_build complete.  You can compile the generated voice by"
   echo "   cd flite; make"
   exit 0
fi

echo build_flite unknown arguments $*
exit 1