-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo_clustergen
executable file
·1309 lines (1117 loc) · 36.1 KB
/
do_clustergen
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#####################################################-*-mode:shell-script-*-
## ##
## Carnegie Mellon University ##
## Copyright (c) 2005-2006 ##
## 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. ##
## ##
###########################################################################
## ##
## Author: Alan W Black ([email protected]) Nov 2005 ##
## ##
###########################################################################
## ##
## Build a clustergen voice (sort of HMM-generation synthesis). ##
## ##
## With no arguments is does (mostly) the right thing ##
## ##
## Its assumes there is already a labeled voice with a set of ##
## utterances. It naively believes it was labeled with ehmm and the ##
## state names are available from that (and voicing information) ##
## ##
## Does deltas by default (and later mlpg) ##
## ##
###########################################################################
LANG=C; export LANG
if [ ! "$ESTDIR" ]
then
echo "environment variable ESTDIR is unset"
echo "set it to your local speech tools directory e.g."
echo ' bash$ export ESTDIR=/home/awb/projects/speech_tools/'
echo or
echo ' csh% setenv ESTDIR /home/awb/projects/speech_tools/'
exit 1
fi
if [ ! "$FESTVOXDIR" ]
then
echo "environment variable FESTVOXDIR is unset"
echo "set it to your local festvox directory e.g."
echo ' bash$ export FESTVOXDIR=/home/awb/projects/festvox/'
echo or
echo ' csh% setenv FESTVOXDIR /home/awb/projects/festvox/'
exit 1
fi
if [ "$SIODHEAPSIZE" = "" ]
then
SIODHEAPSIZE=20000000
export SIODHEAPSIZE
fi
HEAPSIZE=$SIODHEAPSIZE
if [ "$CLUSTERGENDIR" = "" ]
then
export CLUSTERGENDIR=$FESTVOXDIR/src/clustergen
fi
if [ $# = 0 ]
then
$0 f0
$0 mcep
$0 combine_coeffs_v
$0 generate_statenames
$0 cluster
$0 dur
exit 0
fi
. ./etc/voice.defs
if [ "$1" = "parallel" ]
then
ACTION="$2"
PROMPTFILE="$3"
if [ "$PROMPTFILE" = "" ]
then
PROMPTFILE=etc/txt.done.data
fi
if [ ! -d tmpdir ]
then
# for the split promptfile
mkdir tmpdir
fi
if [ "$ACTION" = "cluster" ]
then
$ESTDIR/../festival/bin/festival --heap $HEAPSIZE -b festvox/clustergen_build.scm festvox/build_clunits.scm festvox/${FV_VOICENAME}_cg.scm '(begin (set! cg:parallel_tree_build t) (build_clustergen "'$PROMPTFILE'"))'
exit 0
fi
# We use xargs to parallelize our work. We split our promptfile in 16
# parts. Then run those in parallel with xargs
num_cpus=$(./bin/find_num_available_cpu)
seq 0 15 | xargs -n 1 -P $num_cpus $0 _parallelworker $ACTION $PROMPTFILE
exit 0
fi
if [ "$1" = "process_utts" ]
then
# Internally called from Festival when doing a parallel cluster build
# but its not a normal prompt file its ( fileid num_frames )\n ...
PROMPTFILE="$2"
$ESTDIR/../festival/bin/festival --heap $HEAPSIZE -b festvox/clustergen_build.scm festvox/build_clunits.scm festvox/${FV_VOICENAME}_cg.scm '(begin (set! cg:parallel_tree_build t) (clustergen::do_process_utts "'$PROMPTFILE'"))'
exit 0
fi
if [ "$1" = "_parallelworker" ]
then
ACTION="$2"
PROMPTFILE="$3"
INDEX="$4"
# Get our partition of PROMPTFILE
SPLITPROMPTFILE=tmpdir/dobuild_parallelworker.$$.$INDEX
cat $PROMPTFILE | awk "NR%16==$INDEX {print \$0}" > $SPLITPROMPTFILE
# Run our task
$0 $ACTION $SPLITPROMPTFILE
rm $SPLITPROMPTFILE
exit 0
fi
if [ "$PROMPTFILE" = "" ]
then
if [ $# = 2 ]
then
PROMPTFILE=$2
else
PROMPTFILE=etc/txt.done.data
fi
fi
if [ $1 = "prune_silence" ]
then
$FESTVOXDIR/src/general/prune_silence $PROMPTFILE
exit 0
fi
if [ $1 = "islice" ]
then
if [ ! -d pre_islice_wav ]
then
mkdir pre_islice_wav
cp -pr wav/*.wav pre_islice_wav
fi
mkdir islice
cp -pr $PROMPTFILE islice/islice.done.data
cd islice
$FESTVOXDIR/src/interslice/scripts/do_islice_v2.sh setup
mv ../wav/*.wav bwav
mkdir txt
cat islice.done.data |
awk '{printf("echo ");
for (i=3; i<NF; i++)
printf("%s ",$i);
printf(">txt/%s.txt\n",$2);}' |
sh -v
awk '{print $2}' islice.done.data |
while read x
do
$FESTVOXDIR/src/interslice/scripts/do_islice_v2.sh islice txt/$x.txt bwav/$x.wav
done
cd ..
awk '{print $2}' islice/islice.done.data |
while read x
do
mv islice/twav/${x}_*.wav wav
cat islice/txt/${x}.data
done >$PROMPTFILE
exit 0
fi
if [ $1 = "f0" ]
then
# $0 f0_esps $PROMPTFILE
$0 f0_pda $PROMPTFILE
exit 0
fi
if [ $1 = "f0_pda" ]
then
if [ ! -f etc/f0.params ]
then
./bin/find_f0_stats $PROMPTFILE
fi
./bin/make_f0_pm $PROMPTFILE
exit 0
fi
if [ $1 = "f0_esps" ]
then
if [ ! -f etc/f0.params ]
then
./bin/find_f0_stats $PROMPTFILE
fi
./bin/make_f0_pm_get_f0 $PROMPTFILE
exit 0
fi
if [ $1 = "f0_v_sptk" ]
then
if [ ! "$SPTKDIR" ]
then
echo "environment variable SPTKDIR is unset"
echo "set it to your local festvox directory e.g."
echo ' bash$ export SPTKDIR=/usr/local/SPTK/'
echo or
echo ' csh% setenv SPTKDIR /usr/local/SPTK/'
exit 1
fi
if [ ! -f etc/f0.params ]
then
./bin/find_f0_stats $PROMPTFILE
fi
./bin/make_f0_v_sptk $PROMPTFILE
exit 0
fi
if [ $1 = "str_sptk" ]
then
if [ ! "$SPTKDIR" ]
then
echo "environment variable SPTKDIR is unset"
echo "set it to your local festvox directory e.g."
echo ' bash$ export SPTKDIR=/usr/local/SPTK/'
echo or
echo ' csh% setenv SPTKDIR /usr/local/SPTK/'
exit 1
fi
if [ ! -f etc/f0.params ]
then
./bin/find_f0_stats $PROMPTFILE
fi
if [ ! -f festvox/mef.track ]
then
echo "Mixed Excitation Filters not Generated"
echo "Please run ./bin/do_clustergen generate_filters"
echo "Before extracting strengths"
fi
./bin/get_str_sptk $PROMPTFILE
exit 0
fi
if [ $1 = "voicing" ]
then
if [ ! -f etc/f0.params ]
then
./bin/find_f0_stats $PROMPTFILE
fi
./bin/make_voicing pda $PROMPTFILE
exit 0
fi
if [ $1 = "mcep" ]
then
# Default is now deltas (and mlpg)
$0 mcep_deltas $PROMPTFILE
exit 0
fi
if [ $1 = "mgc" ]
then
$0 mcep_sptk $PROMPTFILE
exit 0
fi
if [ $1 = "mcep_sptk" ]
then
# Default is now deltas (and mlpg)
if [ ! "$SPTKDIR" ]
then
echo "environment variable SPTKDIR is unset"
echo "set it to your local festvox directory e.g."
echo ' bash$ export SPTKDIR=/usr/local/SPTK/'
echo or
echo ' csh% setenv SPTKDIR /usr/local/SPTK/'
exit 1
fi
$0 mcep_sptk_deltas $PROMPTFILE
exit 0
fi
if [ $1 = "mcep_static" ]
then
ORDER=24
CG_TMP=cg_tmp_$$
if [ ! -d mcep_static ]
then
mkdir mcep_static
fi
cat $PROMPTFILE |
awk '{print $2}' |
while read i
do
fname=$i
echo $fname MCEP static
$FESTVOXDIR/src/vc/src/analysis/analysis -nmsg -mcep -pow -order $ORDER -npowfile $CG_TMP.npow wav/$i.wav $CG_TMP.mcep
cat $CG_TMP.mcep |
perl $CLUSTERGENDIR/d2a.pl |
awk '{printf("%s ",$1); if ((NR%(1+'$ORDER')) == 0) printf("\n")}' |
$ESTDIR/bin/ch_track -itype ascii -otype est_binary -s 0.005 -o mcep_static/$i.mcep
# cat $CG_TMP.npow |
# perl $CLUSTERGENDIR/d2a.pl |
# awk '{printf("%s\n",$1);}' |
# $ESTDIR/bin/ch_track -itype ascii -otype est_binary -s 0.005 -o mcep/$i.npow
rm -f $CG_TMP.*
done
exit 0
fi
if [ $1 = "mcep_deltas" ]
then
ORDER=24
dynwin=$FESTVOXDIR/src/vc/src/win/dyn.win
CG_TMP=cg_tmp_$$
if [ ! -d mcep_deltas ]
then
mkdir mcep_deltas
fi
cat $PROMPTFILE |
awk '{print $2}' |
while read i
do
fname=$i
echo $fname MCEP with deltas
$FESTVOXDIR/src/vc/src/analysis/analysis -nmsg -mcep -pow -order $ORDER -npowfile $CG_TMP.npow wav/$i.wav $CG_TMP.mcep
# get deltas
ORDERP=`echo $ORDER | awk '{printf("%d",$1+1)}'`
$FESTVOXDIR/src/vc/src/mlpg/delta -nmsg -jnt -dynwinf $dynwin -dim $ORDERP $CG_TMP.mcep $CG_TMP.mcepd
cat $CG_TMP.mcepd |
perl $CLUSTERGENDIR/d2a.pl |
awk '{printf("%s ",$1); if ((NR%(2*('$ORDER'+1))) == 0) printf("\n")}' |
cat >$CG_TMP.ascii.mcepd
cat $CG_TMP.ascii.mcepd |
$ESTDIR/bin/ch_track -itype ascii -otype est_binary -s 0.005 -o mcep_deltas/$i.mcep
# cat cg_tmp.npow |
# perl $CLUSTERGENDIR/d2a.pl |
# awk '{printf("%s\n",$1);}' |
# $ESTDIR/bin/ch_track -itype ascii -otype est_binary -s 0.005 -o mcep/$i.npow
rm -f $CG_TMP.*
done
exit 0
fi
if [ $1 = "mcep_sptk_deltas" ]
then
# Extract MCEP using SPTK, but save them into mcep_deltas directory
# so other parts of this script continue to work
MCEPORDER=24
WINDOWTYPE=1
NORMALIZE=1
FFTLEN=2048
LNGAIN=1
X2X=$SPTKDIR/bin/x2x
MCEP=$SPTKDIR/bin/mcep
LPC2LSP=$SPTKDIR/bin/lpc2lsp
MERGE=$SPTKDIR/bin/merge
SOPR=$SPTKDIR/bin/sopr
NAN=$SPTKDIR/bin/nan
MINMAX=$SPTKDIR/bin/minmax
PITCH=$SPTKDIR/bin/pitch
FRAME=$SPTKDIR/bin/frame
WINDOW=$SPTKDIR/bin/window
if [ ! -d mcep_sptk ]
then
mkdir mcep_sptk
fi
if [ ! -d mcep_deltas ]
then
mkdir mcep_deltas
fi
cat $PROMPTFILE |
awk '{print $2}' |
while read i
do
fname=$i
if [ "$SAMPFREQ" = "" ]
then
# Use the first wav file to determine sampling frequency
SAMPFREQ=$($ESTDIR/bin/ch_wave -info wav/$fname.wav | grep 'Sample rate' | cut -d ' ' -f 3)
FRAMELEN=$(echo | awk "{print int(0.025*$SAMPFREQ)}")
FRAMESHIFT=$(echo | awk "{print int(0.005*$SAMPFREQ)}")
FWARP[8000]=0.312
FWARP[11025]=0.357
FWARP[16000]=0.42
FWARP[22050]=0.455
FWARP[32000]=0.504
FWARP[44100]=0.544
FWARP[48000]=0.554
FREQWARP=${FWARP[$SAMPFREQ]}
if [ "$FREQWARP" = "" ]
then
echo "mcep_sptk_deltas: Cannot handle sampling frequency $SAMPFREQ"
exit 1
fi
fi
echo "$fname MCEP with deltas (SPTK) $SAMPFREQ"
TMP=mcep_sptk_tmp.$$
# Save raw wave out
$ESTDIR/bin/ch_wave -otype raw < wav/$fname.wav > $TMP.raw
$X2X +sf $TMP.raw > $TMP.sf
cat $TMP.sf | $MINMAX | $X2X +fa > $TMP.minmax
min=$(head -n 1 $TMP.minmax)
max=$(tail -n 1 $TMP.minmax)
if [ -s $TMP.raw -a $min -gt -32768 -a $max -lt 32767 ]
then
$FRAME -l $FRAMELEN -p $FRAMESHIFT $TMP.sf | \
$WINDOW -l $FRAMELEN -L $FFTLEN -w $WINDOWTYPE -n $NORMALIZE | \
$MCEP -a $FREQWARP -m $MCEPORDER -l $FFTLEN -e 1.0E-08 > mcep_sptk/$fname.mcep
if [ -n "`$NAN mcep_sptk/$fname.mcep`" ]
then
echo "Failed to process $fname"
else
$SPTKDIR/bin/delta -m $MCEPORDER -d -0.5 0.0 0.5 < mcep_sptk/$fname.mcep | \
$SPTKDIR/bin/x2x +fa$(expr 2 \* \( $MCEPORDER + 1 \)) | \
$ESTDIR/bin/ch_track -itype ascii -otype est_binary -s 0.005 -o mcep_deltas/$fname.mcep
fi
else
echo "Failed to process $fname"
fi
rm -rf $TMP.*
done
exit 0
fi
if [ $1 = "combine_coeffs" ]
then
if [ ! -d ccoefs ]
then
mkdir ccoefs
fi
CG_TMP=cg_tmp_$$
cat $PROMPTFILE |
awk '{print $2}' |
while read i
do
fname=$i
echo $fname "COMBINE_COEFFS (f0,mcep_static,v)"
$ESTDIR/bin/ch_track -otype ascii f0/$fname.f0 |
awk '{if (NR == 1) { print $1; print $1} print $1}' >$CG_TMP.f0
# cp -p tempo/$fname.f0 $CG_TMP.f0
# if [ -f ehmm/feat/$fname.vp ]
# then
# sed 1d ehmm/feat/$fname.vp >$CG_TMP.vu
# fi
# $ESTDIR/bin/ch_track -otype ascii get_f0/$fname.f0 |
# awk '{if (NR == 1) { print $2; } print $2}' >$CG_TMP.vu
$ESTDIR/bin/ch_track -otype ascii mcep_static/$fname.mcep |
awk '{if (NR == 1) { print $0; } print $0}' >$CG_TMP.mcep
# $ESTDIR/bin/ch_track -otype ascii formant/$fname.fb |
# awk '{if (NR == 1) { print $0; } print $0}' >$CG_TMP.formant
# $ESTDIR/bin/ch_track -otype ascii lsp/$fname.lsp > $CG_TMP.mcep
# awk '{if (NR == 1) { print $0; } print $0}' >$CG_TMP.mcep
# $ESTDIR/bin/ch_track -otype ascii mcep/$fname.npow >$CG_TMP.npow
# paste $CG_TMP.f0 $CG_TMP.npow $CG_TMP.mcep |
# paste $CG_TMP.f0 $CG_TMP.vu $CG_TMP.mcep |
# paste $CG_TMP.f0 $CG_TMP.formant $CG_TMP.mcep |
if [ -f v/$fname.v ]
then
paste $CG_TMP.f0 $CG_TMP.mcep v/$fname.v
else
paste $CG_TMP.f0 $CG_TMP.mcep
fi |
awk '{if (l==0)
l=NF;
else if (l == NF)
print $0}' |
awk '{if (NR == -1) print $0; print $0}' |
$ESTDIR/bin/ch_track -itype ascii -otype est_binary -s 0.005 -o ccoefs/$fname.mcep
rm -f $CG_TMP.*
done
exit 0
fi
if [ $1 = "combine_coeffs_v" ]
then
if [ ! -d ccoefs ]
then
mkdir ccoefs
fi
CG_TMP=cg_tmp_$$
cat $PROMPTFILE |
awk '{print $2}' |
while read i
do
fname=$i
echo $fname "COMBINE_COEFFS (f0,mcep_deltas,v)"
if [ -f festival/utts/$fname.utt ]
then
enddur=`$ESTDIR/../festival/examples/dumpfeats -relation Segment -feats '(end)' festival/utts/$fname.utt | tail -1 | awk '{printf("%0.3f",$1+0.0005)}'`
else
enddur=`$ESTDIR/bin/ch_track -otype est_ascii mcep_deltas/$fname.mcep | awk '{time=$1} END {printf("%0.3f",time)}'`
fi
$ESTDIR/bin/ch_track -otype ascii f0/$fname.f0 |
awk '{if (NR == 1) { print $1;} print $1}' >$CG_TMP.f0
$ESTDIR/bin/ch_track -otype ascii mcep_deltas/$fname.mcep |
sed '1d' |
awk '{if (NR == -1) { print $0; } print $0}' >$CG_TMP.mcep
cat v/$fname.v | awk '{print 10*$1}' |
awk '{if (NR == 1) { print $1;} print $1}' >$CG_TMP.v
paste $CG_TMP.f0 $CG_TMP.mcep $CG_TMP.v |
awk '{if (l==0)
l=NF;
if (l == NF)
print $0}' |
$ESTDIR/bin/ch_track -itype ascii -otype est_binary -s 0.005 -end $enddur -o ccoefs/$fname.mcep
rm -f $CG_TMP.*
done
exit 0
fi
if [ $1 = "combine_coeffs_me" ]
then
if [ ! -d ccoefs ]
then
mkdir ccoefs
fi
CG_TMP=cg_tmp_$$
cat $PROMPTFILE |
awk '{print $2}' |
while read i
do
fname=$i
echo $fname "COMBINE_COEFFS (f0,mcep_deltas,str,v)"
if [ -f festival/utts/$fname.utt ]
then
enddur=`$ESTDIR/../festival/examples/dumpfeats -relation Segment -feats '(end)' festival/utts/$fname.utt | tail -1 | awk '{printf("%0.3f",$1+0.0005)}'`
else
enddur=`$ESTDIR/bin/ch_track -otype est_ascii mcep_deltas/$fname.mcep | awk '{time=$1} END {printf("%0.3f",time)}'`
fi
$ESTDIR/bin/ch_track -otype ascii f0/$fname.f0 |
awk '{if (NR == 1) { print $1} print $1}' >$CG_TMP.f0
$ESTDIR/bin/ch_track -otype ascii mcep_deltas/$fname.mcep |
sed '1d' |
awk '{if (NR == 1) { print $0; } print $0}' >$CG_TMP.mcep
cat v/$fname.v | awk '{print 10*$1}' |
awk '{if (NR == 1) { print $1} print $1}' >$CG_TMP.v
cat str/$fname.str |
sed '1,2d' |
awk '{if (NR == -1) { print $0} print $0}' >$CG_TMP.str
paste $CG_TMP.f0 $CG_TMP.mcep $CG_TMP.str $CG_TMP.v |
awk '{if (l==0)
l=NF;
if (l == NF)
print $0}' |
$ESTDIR/bin/ch_track -itype ascii -otype est_binary -s 0.005 -end $enddur -o ccoefs/$fname.mcep
rm -f $CG_TMP.*
done
exit 0
fi
if [ $1 = "combine_coeffs_psync" ]
then
if [ ! -d ccoefs ]
then
mkdir ccoefs
fi
CG_TMP=cg_tmp_$$
cat $PROMPTFILE |
awk '{print $2}' |
while read i
do
fname=$i
echo $fname COMBINE_COEFFS_PSYNC
$ESTDIR/bin/ch_track -otype ascii f0/$fname.f0 |
awk '{if (NR == 1) { print $1; print $1;} print $1}' >$CG_TMP.f0
$ESTDIR/bin/ch_track -otype ascii mcep/$fname.mcep |
awk '{if (NR == 1) { print $0; } print $0}' >$CG_TMP.mcep
sed 's/)/ )/g' sts/$i.sts |
awk '{if (NR == 1)
{
lpcmin = $5;
lpcrange = $6;
}
else
{
printf("%f ",$2);
printf("%d ",$21); # put frame size first
for (i=4; i<=19; i++)
printf("%f ",$i);
for (i=23; i<=256+23; i++)
if (i > NF)
printf("%d ",0);
else
printf("%d ",$i);
printf("\n")
}}' >$CG_TMP.lpc
# need to get time in there and smooth F0 at each pitch mark
$ESTDIR/bin/ch_track -otype ascii f0/$fname.f0 |
awk '{if (NR == 1) { print $1; print $1;} print $1}' |
awk 'BEGIN {printf("{\n");}
{printf("f0[%d]=%f;\n",NR,$1);}
END {printf("}\n")}' >$CG_TMP.awk.f0
echo '{ printf("%f 1 %f\n",$1,f0[int($1/0.005)]); }' >>$CG_TMP.awk.f0
awk -f $CG_TMP.awk.f0 $CG_TMP.lpc >$CG_TMP.time
# paste $CG_TMP.time $CG_TMP.mcep $CG_TMP.lpc |
paste $CG_TMP.time $CG_TMP.lpc |
awk '{if (l==0)
l=NF;
else if (l == NF)
print $0}' >$CG_TMP.all
echo EST_File Track >$CG_TMP.est
echo DataType ascii >>$CG_TMP.est
echo NumFrames `cat $CG_TMP.all | wc -l` >>$CG_TMP.est
echo NumChannels `head -1 $CG_TMP.all | awk '{print NF-2}'` >>$CG_TMP.est
echo NumAuxChannels 0 >>$CG_TMP.est
echo EqualSpace 0 >>$CG_TMP.est
echo BreaksPresent true >>$CG_TMP.est
head -1 $CG_TMP.all |
awk '{for (i=1; i<=NF-2; i++)
printf("Channel_%d track_%d\n",i-1,i-1)}' >>$CG_TMP.est
echo ByteOrder 01 >>$CG_TMP.est
echo "CommentChar ;" >>$CG_TMP.est
echo file_type 13 >>$CG_TMP.est
echo name $fname.ccoeffs >>$CG_TMP.est
echo EST_Header_End >>$CG_TMP.est
cat $CG_TMP.all >>$CG_TMP.est
$ESTDIR/bin/ch_track -otype est_binary $CG_TMP.est -o ccoefs/$fname.mcep
rm -f $CG_TMP.*
done
exit 0
fi
if [ $1 = "do_coeffs" ]
then
$0 f0
$0 mcep
$0 combine_coeffs
exit 0
fi
if [ "$1" = "remove_all_short_silences" ]
then
if [ ! -d lab_ok ]
then
cp -pr lab lab_ok
fi
$ESTDIR/../festival/bin/festival -b festvox/clustergen_build.scm '(ClusterGen_ml_delete_short_pauses "'$PROMPTFILE'" "lab_ok/" "lab/")'
exit 0
fi
if [ "$1" = "build_utts" ]
then
$ESTDIR/../festival/bin/festival --heap $HEAPSIZE -b festvox/build_clunits.scm '(set! split_long_silences nil)' '(build_utts "'$PROMPTFILE'")'
exit 0
fi
if [ "$1" = "add_word_feats" ]
then
$ESTDIR/../festival/bin/festival --heap $HEAPSIZE -b festvox/build_clunits.scm festvox/addfeats.scm '(add_word_feats "'$PROMPTFILE'")'
exit 0
fi
if [ "$1" = "add_syl_feats" ]
then
$ESTDIR/../festival/bin/festival --heap $HEAPSIZE -b festvox/build_clunits.scm festvox/addfeats.scm '(add_syl_feats "'$PROMPTFILE'")'
exit 0
fi
if [ "$1" = "add_phone_feats" ]
then
$ESTDIR/../festival/bin/festival --heap $HEAPSIZE -b festvox/build_clunits.scm festvox/addfeats.scm '(add_phone_feats "'$PROMPTFILE'")'
exit 0
fi
if [ "$1" = "generate_filters" ]
then
MEF_ORDER=47
LPF_ORDER=31
FRVGEN=$CLUSTERGENDIR/freq_response_vector_gen
# Find sampling rate from first wavefile
fname=$(head -1 $PROMPTFILE | awk '{print $2}')
SAMP_RATE=$($ESTDIR/bin/ch_wave -info wav/$fname.wav | grep 'Sample rate' | cut -d ' ' -f 3)
if [ ! -d filters ]
then
mkdir filters
fi
TMP=fil_$$
# Generate MEF
$FRVGEN LPF $SAMP_RATE 500 > $TMP.h1.freq
$FRVGEN BPF $SAMP_RATE 900 1500 > $TMP.h2.freq
$FRVGEN BPF $SAMP_RATE 2000 3750 > $TMP.h3.freq
$FRVGEN BPF $SAMP_RATE 4000 6000 > $TMP.h4.freq
$FRVGEN BPF $SAMP_RATE 6250 7500 > $TMP.h5.freq
for i in $(seq 1 5)
do
$ESTDIR/bin/design_filter $TMP.h$i.freq -forder $MEF_ORDER -o $TMP.tmp
sed '1,/End/ d' $TMP.tmp | sed 's/ /\n/g' > filters/h$i.txt
sed '1,/End/ d' $TMP.tmp > $TMP.h$i
done
cat $TMP.h1 $TMP.h2 $TMP.h3 $TMP.h4 $TMP.h5 | $ESTDIR/bin/ch_track -itype ascii -s 0.005 -otype est_binary -o festvox/mef.track
# Generate LPF
$FRVGEN LPF $SAMP_RATE 6000 > $TMP.lpf.freq
$ESTDIR/bin/design_filter $TMP.lpf.freq -forder $LPF_ORDER -o $TMP.tmp
sed '1,/End/ d' $TMP.tmp | $ESTDIR/bin/ch_track -itype ascii -s 0.005 -otype est_binary -o festvox/lpf.track
rm -rf $TMP.*
exit 0
fi
if [ $1 = "generate_statenames" ]
then
if [ ! -f etc/silence ]
then
$ESTDIR/../festival/bin/festival -b festvox/build_clunits.scm "(find_silence_name)"
fi
SILENCE=`awk '{print $1}' etc/silence`
if [ ! -f etc/statenames ]
then
# Its possible for statenames come from Janus or Sphinx labeling
# but default is to assume it comes from ehmm
# This should be generated by the ehmm process already
cat ehmm/etc/ph_list.int_log |
awk '{if ($1 == "ssil")
printf("ssil pau_5\n");
else if (NF > 1)
{
printf("%s ",$1);
for (i=4; i<(4+$2-2); i++)
printf("%s_%s ",$1,$i);
printf("\n");
}}' |
sed 's/ ssil/ '$SILENCE'/g' >etc/statenames
fi
# Lisp level names for mapping phones to statenames
echo ";; Autogenerated file from EHMM state labels" >festvox/$FV_VOICENAME"_statenames.scm"
echo "(set! "$FV_VOICENAME"::phone_to_states '(" >>festvox/$FV_VOICENAME"_statenames.scm"
cat etc/statenames |
awk '{printf(" ( %s )\n",$0)}' >>festvox/$FV_VOICENAME"_statenames.scm"
echo "))" >>festvox/$FV_VOICENAME"_statenames.scm"
echo "(provide '"$FV_VOICENAME"_statenames)" >>festvox/$FV_VOICENAME"_statenames.scm"
# Wagon .desc file
cat etc/statenames |
awk '{for (i=2; i<=NF; i++)
{
if (done[$i] != 1)
printf("%s___",$i);
done[$i] = 1;
}
}' >festival/clunits/statenames
cat etc/statenames |
awk '{ printf("%s___",$1);
}' >festival/clunits/phonenames
if grep -q "state names" festival/clunits/mcep.desc
then
mv festival/clunits/mcep.desc festival/clunits/mcep.desc-old
fi
if grep -q "state names" festival/clunits/mcep.desc-old
then
true
else
cp -p $FESTVOXDIR/src/clustergen/mcep.desc festival/clunits/mcep.desc-old
fi
cat festival/clunits/mcep.desc-old |
sed 's/state names/'`cat festival/clunits/statenames`'/' |
sed 's/phone names/'`cat festival/clunits/phonenames`'/' |
sed 's/___/ /g' >festival/clunits/mcep.desc
if [ -f festival/clunits/mceptraj.desc ]
then
mv festival/clunits/mceptraj.desc festival/clunits/mceptraj.desc-old
cat festival/clunits/mceptraj.desc-old |
sed 's/state names/'`cat festival/clunits/statenames`'/' |
sed 's/phone names/'`cat festival/clunits/phonenames`'/' |
sed 's/___/ /g' >festival/clunits/mceptraj.desc
fi
exit 0
fi
if [ $1 = "cluster" ]
then
$ESTDIR/../festival/bin/festival --heap $HEAPSIZE -b festvox/clustergen_build.scm festvox/build_clunits.scm festvox/${FV_VOICENAME}_cg.scm '(build_clustergen "'$PROMPTFILE'")'
exit 0
fi
if [ $1 = "trajectory" ]
then
$ESTDIR/../festival/bin/festival --heap $HEAPSIZE -b festvox/clustergen_build.scm '(set! cluster_feature_filename "mceptraj.desc")' festvox/build_clunits.scm festvox/${FV_VOICENAME}_cg.scm '(build_clustergen_traj "'$PROMPTFILE'")'
exit 0
fi
if [ $1 = "trajectory_ola" ]
then
$ESTDIR/../festival/bin/festival --heap $HEAPSIZE -b \
festvox/clustergen_build.scm \
'(set! cluster_feature_filename "mceptraj.desc")' \
'(set! cg::trajectory_ola t)' \
festvox/build_clunits.scm festvox/${FV_VOICENAME}_cg.scm \
'(build_clustergen_traj "'$PROMPTFILE'")'
exit 0
fi
if [ $1 = "dur" ]
then
./bin/make_dur_model_mcep $PROMPTFILE
cp -p festvox/$FV_VOICENAME"_dur.scm" festvox/$FV_VOICENAME"_durdata_cg.scm"
exit 0
fi
#######################################################################
## Prune Frames: remove frames from a build whose predicted value are
## mode that X away from their actual.
##
## Doesn't improve MCD (even with multiple passes and playing with the
## stop value. Might be worthwhile for flite models
## Getting rid of 5% of the frames makes no different to the MCD, F0 or
## how it sounds.
##
## Note you need to build an initial model before you can run this
#######################################################################
if [ $1 = "prune_frames" ]
then
PRUNE_THRESHOLD=50
$ESTDIR/../festival/bin/festival --heap $HEAPSIZE -b \
festvox/clustergen_build.scm \
festvox/build_clunits.scm festvox/${FV_VOICENAME}_cg.scm \
'(voice_'${FV_VOICENAME}'_cg)' \
'(set! cg:prune_frame_threshold 1.7)' \
'(build_clustergen "'$PROMPTFILE'")'
exit 0
fi
#######################################################################
## CG Viterbi function *very* experimental
#######################################################################
if [ $1 = "cgv_label" ]
then
if [ ! -d cgv ]
then
mkdir cgv
fi
if [ ! -d cgv/lab ]
then
mkdir cgv/lab
fi
$ESTDIR/../festival/bin/festival --heap $HEAPSIZE -b festvox/clustergen_build.scm festvox/build_clunits.scm festvox/${FV_VOICENAME}_cg.scm '(begin (voice_'${FV_VOICENAME}'_cg) (cgv_label_clustergen "'$PROMPTFILE'" "cgv/lab") ) '
exit 0
fi
if [ $1 = "cgv_combine_coeffs" ]
then
CG_TMP=cg_tmp_$$
cat $PROMPTFILE |
awk '{print $2}' |
while read i
do
fname=$i
echo $fname CGV_COMBINE_COEFFS
$ESTDIR/bin/ch_track -otype ascii f0/$fname.f0 |
awk '{if (NR == 1) { print $1; print $1} print $1}' >$CG_TMP.f0
$ESTDIR/bin/ch_track -otype ascii cgv/lab/$fname.cseq |
awk '{if (NR == 1) { print $0; } print $0}' >$CG_TMP.cseq
paste $CG_TMP.f0 $CG_TMP.cseq |
awk '{if (l==0)
l=NF;
else if (l == NF)
print $0}' |
awk '{if (NR == -1) print $0; print $0}' |
$ESTDIR/bin/ch_track -itype ascii -otype est_binary -s 0.005 -o ccoefs/$fname.mcep
rm -f $CG_TMP.*
done
exit 0
fi
if [ $1 = "cgv_cluster" ]
then
$ESTDIR/../festival/bin/festival --heap $HEAPSIZE -b festvox/clustergen_build.scm festvox/build_clunits.scm festvox/${FV_VOICENAME}_cg.scm '(build_cgv_clustergen "'$PROMPTFILE'")'
exit 0
fi
if [ $1 = "cgv_lm_ngram" ]
then
NGRAM_BUILD=$ESTDIR/bin/ngram_build
ORDER=3;
cat $PROMPTFILE |
awk '{print $2}' |