voxforge.org
VoxForge Dev

root/Trunk/Scripts/AcousticModel_scripts/HTK/AMCreate_scripts/Compile_AcousticModel.sh

Revision 2270, 18.6 kB (checked in by kmaclean, 1 year ago)

Flac audio processing updates & GPL v3 updates

  • Property svn:executable set to *
Line 
1 #!/bin/sh
2 ####################################################################
3 ###
4 ### script name: Compile_AcouticModel.sh
5 ### modified by: Ken MacLean
6 ### email: contact@voxforge.org
7 ### Date: 2006.06.16
8 ### Command: ./Compile_AcousticModel.sh
9 ### Version: 0.1
10 ###             
11 ### Copyright (C) 2006 Ken MacLean
12 ###
13 ### This program is free software; you can redistribute it and/or
14 ### modify it under the terms of the GNU General Public License
15 ### as published by the Free Software Foundation; either version 3
16 ### of the License, or (at your option) any later version.
17 ###
18 ### This program is distributed in the hope that it will be useful,
19 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ### GNU General Public License for more details.
22 ###
23 ####################################################################
24 ### Input Files
25 ####################################################################
26 # update this files:
27 #    master_prompts file needs directory paths since train.scp is derived from this file!
28
29 ####################################################################
30 ### Subroutines
31 ####################################################################
32 htk_init () {
33         cd ./interim_files
34         #create directories if they do not already exist
35         mkdir hmm0 hmm1 hmm2 hmm3 hmm4 hmm5 hmm6 hmm7 hmm8 hmm9 hmm10 hmm11 hmm12 hmm13 hmm14 hmm15
36         #all these rms were to allow the contents of the interim directory to be committed to svn
37     rm -f hmm0/hmmdefs hmm0/macros hmm0/proto hmm0/vFloors
38     rm -f hmm1/hmmdefs hmm1/macros
39     rm -f hmm2/hmmdefs hmm2/macros
40     rm -f hmm3/hmmdefs hmm3/hmmdefs.tmp2  hmm3/macros
41     rm -f hmm4/hmmdefs hmm4/hmmdefs.tmp2  hmm4/macros
42     rm -f hmm5/hmmdefs hmm5/macros
43     rm -f hmm6/hmmdefs hmm6/macros   
44     rm -f hmm7/hmmdefs hmm7/macros
45     rm -f hmm8/hmmdefs hmm8/macros
46     rm -f hmm9/hmmdefs hmm9/macros
47     rm -f hmm10/hmmdefs hmm10/macros
48     rm -f hmm11/hmmdefs hmm11/macros
49     rm -f hmm12/hmmdefs hmm12/macros 
50     rm -f hmm13/hmmdefs hmm13/macros
51     rm -f hmm14/hmmdefs hmm14/macros
52     rm -f hmm15/hmmdefs hmm15/macros   
53         rm -f ./aligned.mlf
54         rm -f ./dict
55         rm -f ./dict1
56         rm -f ./dict-tri
57         rm -f ./fulllist
58         rm -f ./fulllist-original
59 #       rm -f ./master_prompts don't delete - created by fix_master_prompts.pl
60         rm -f ./mktri.hed
61         rm -f ./monophones0
62         rm -f ./monophones1
63         rm -f ./phones0.mlf
64         rm -f ./phones1.mlf
65         rm -f ./stats
66         rm -f ./tiedlist
67         rm -f ./train.scp
68         rm -f ./tree.hed
69         rm -f ./trees
70         rm -f ./triphones1
71         rm -f ./wintri.mlf
72         rm -f ./wlist
73         rm -f ./words.mlf
74     cd ..
75     rm -f ../acoustic_model_files/hmmdefs
76     rm -f ../acoustic_model_files/tiedlist
77     rm -f ../acoustic_model_files/macros
78     cd logs
79  
80     rm -f ./Step2_HDMan1_log
81     rm -f ./Step2_HDMan2_log
82     rm -f ./Step4_HLEd_phones0_log
83     rm -f ./Step4_HLEd_phones1_log
84     rm -f ./Step6_HCompV_hmm0_log
85     rm -f ./Step6_HERest_hmm1_log
86     rm -f ./Step6_HERest_hmm2_log
87     rm -f ./Step6_HERest_hmm3_log
88     rm -f ./Step7_HERest_hmm6_log
89     rm -f ./Step7_HERest_hmm7_log
90     rm -f ./Step7_HHEd_hmm5_log
91     rm -f ./Step8_HERest_hmm8_log
92     rm -f ./Step8_HERest_hmm9_log
93     rm -f ./Step8_HVite_log
94     rm -f ./Step9_HERest_hmm10_log
95     rm -f ./Step9_HERest_hmm11_log
96     rm -f ./Step9_HLed_log
97     rm -f ./Step9_hmm10_HHEd_log
98     rm -f ./Step10_HDMan_flog
99     rm -f ./Step10_HDMan_log
100     rm -f ./Step10_HHed_hmm13_log
101     rm -f ./Step10_HERest_hmm14_log
102     rm -f ./Step10_HERest_hmm15_log
103    
104     cd ..
105         return 0       
106 }
107
108 make_wlist_label_file () {
109 perl $HTK/prompts2wlist ./interim_files/master_prompts ./interim_files/wlist
110
111     echo 'SENT-END' >> ./interim_files/wlist
112         echo 'SENT-START' >> ./interim_files/wlist
113         perl ./perlsort.pl  ./interim_files/wlist ./interim_files/wlist1
114         uniq ./interim_files/wlist1 ./interim_files/wlist
115     rm ./interim_files/wlist1
116         return 0
117 }
118
119 make_monophones0 () {
120         for STR in `cat ./interim_files/monophones1`; # monophones1 = monophones0 less "sp" phone
121         do
122                 if [ "${STR}" != "sp" ]; then
123                         echo ${STR} >> ./interim_files/monophones0;
124                 fi;
125         done;
126         return 0
127 }
128
129 make_wordsmlf () {
130         perl $HTK/prompts2mlf ./interim_files/words.mlf ./interim_files/master_prompts
131
132
133         return 0
134 }
135
136 make_hmmdefs () {
137         for WORD in `cat ./interim_files/monophones0`
138         do
139                 tail -n 28  ./interim_files/hmm0/proto | sed s/~h\ \"proto\"/~h\ \"$WORD\"/g >> ./interim_files/hmm0/hmmdefs
140         done                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
141         return 0
142 }
143
144 make_macros () {
145         head -n 3 ./interim_files/hmm0/proto > ./interim_files/hmm0/macros
146         cat ./interim_files/hmm0/vFloors >> ./interim_files/hmm0/macros
147         return 0
148 }
149
150 make_hmm4 () {
151     LINE="start"
152     NUM=1
153
154         rm -rf ./interim_files/hmm4/hmmdefs.tmp1
155         rm -rf ./interim_files/hmm4/hmmdefs.tmp2
156         
157     while [ `echo ${LINE} | awk '{ print $1 }'` != "" ];
158     do
159                 LINE=`cat -n ./interim_files/hmm4/hmmdefs | grep ^[[:space:]]*${NUM}[[:space:]] | sed s/^[[:space:]]*[[:digit:]]*//g`
160                 if [ `echo ${LINE} | awk '{ print $2 }'` = "\"sil\"" ]; then
161             while [ `echo ${LINE} | awk '{ print $1 }'` != "<ENDHMM>" ];
162             do
163                 echo ${LINE} >> ./interim_files/hmm4/hmmdefs.tmp1
164                 echo ${LINE} >> ./interim_files/hmm4/hmmdefs.tmp2
165                                 print_process ${NUM}
166                                 let "NUM += 1"
167                                 LINE=`cat -n ./interim_files/hmm4/hmmdefs | grep ^[[:space:]]*${NUM}[[:space:]] | sed s/^[[:space:]]*[[:digit:]]*//g`
168                         done
169                        
170                         echo ${LINE} >> ./interim_files/hmm4/hmmdefs.tmp1
171
172                         NUM2=1
173                         while [ ${NUM2} != "28" ];
174                         do
175                                 LINE2=`cat -n ./interim_files/hmm4/hmmdefs.tmp2 | grep ^[[:space:]]*${NUM2}[[:space:]] \
176                                 | sed s/^[[:space:]]*[[:digit:]]*//g`
177
178                            case ${NUM2} in
179                                         1 )
180                                                 echo ${LINE2} | sed s/~h\ \"sil\"/~h\ \"sp\"/g >> ./interim_files/hmm4/hmmdefs.tmp1
181                                                 ;;
182                                         2 )
183                                                 echo ${LINE2} >> ./interim_files/hmm4/hmmdefs.tmp1
184                                                 ;;
185                                         3 )
186                                                 echo ${LINE2} | sed s/5/3/g >> ./interim_files/hmm4/hmmdefs.tmp1
187                                                 ;;
188                                         10 )
189                                                 echo ${LINE2} | sed s/3/2/g >> ./interim_files/hmm4/hmmdefs.tmp1
190                                                 ;;
191                                         11 | 12 | 13 | 14 | 15)
192                                                 echo ${LINE2} >> ./interim_files/hmm4/hmmdefs.tmp1
193                                                 ;;
194                                         22 )
195                                                 echo ${LINE2} | sed s/5/3/g >> ./interim_files/hmm4/hmmdefs.tmp1
196                                                 ;;
197                                         24 )
198                                                 echo "0.000000e+000 1.000000e+000 0.000000e+000" >> ./interim_files/hmm4/hmmdefs.tmp1
199                                                 ;;
200                                         25 )
201                                                 echo "0.000000e+000 0.900000e+000 0.100000e+000" >> ./interim_files/hmm4/hmmdefs.tmp1
202                                                 ;;
203                                         26 )
204                                                 echo "0.000000e+000 0.000000e+000 0.000000e+000" >> ./interim_files/hmm4/hmmdefs.tmp1
205                                                 ;;
206                                 esac
207                                 let "NUM2 += 1"
208                         done
209         fi
210                 echo ${LINE} >> ./interim_files/hmm4/hmmdefs.tmp1
211                 print_process ${NUM}
212                 let "NUM += 1"
213         done
214         mv -f ./interim_files/hmm4/hmmdefs.tmp1 ./interim_files/hmm4/hmmdefs
215         return 0
216 }
217
218 make_dict1 () {
219         cat ./interim_files/dict > ./interim_files/dict1
220         echo "silence  []  sil" >> ./interim_files/dict1
221         return 0
222 }
223
224 make_mktrihed () {
225         if [ -f "$HTK/maketrihed" ]; then
226                 perl $HTK/maketrihed ./interim_files/monophones1 ./interim_files/triphones1
227                 mv mktri.hed ./interim_files/
228         else
229                 echo "Error!! $HTK/maketrihed not found!"
230                 return 1
231         fi
232         return 0
233 }
234
235 make_treehed () {
236         cat ./input_files/tree1.hed > ./interim_files/tree.hed
237     perl $HTK/mkclscript.prl TB 350 ./interim_files/monophones0 >> ./interim_files/tree.hed
238     echo ' ' >> ./interim_files/tree.hed             
239     echo 'TR 1' >> ./interim_files/tree.hed
240     echo ' ' >> ./interim_files/tree.hed
241     echo 'AU "./interim_files/fulllist" ' >> ./interim_files/tree.hed
242     echo 'CO "./interim_files/tiedlist" ' >> ./interim_files/tree.hed
243     echo ' ' >> ./interim_files/tree.hed
244     echo 'ST "./interim_files/trees" ' >> ./interim_files/tree.hed
245         return 0
246 }
247
248 make_fulllist () {
249         cat ./interim_files/fulllist > ./interim_files/fulllist-original
250         cat ./interim_files/triphones1 >> ./interim_files/fulllist
251         perl fixfulllist.pl ./interim_files/fulllist ./interim_files/fulllist1
252         cat ./interim_files/fulllist1 > ./interim_files/fulllist
253         rm ./interim_files/fulllist1
254         return 0
255 }
256
257 print_heading () {
258         if [ $? = "0" ]; then
259                 echo
260                 echo -e "\t$1"
261                 NUM=1
262                 while [ ${NUM} -lt 32 ];
263                 do
264                         echo -n "=="
265                         let "NUM += 1"
266                 done
267                 echo
268         else
269                 exit 1
270         fi
271         return 0
272 }
273
274 ########################################################################
275 #       Main
276 ########################################################################
277 print_heading "init"
278         HTK=$1
279         LexiconDirectory=$2     
280         Debug=$3
281         htk_init
282         export PATH=$PATH:$HTK  # to access HTK executables
283         
284 print_heading "Step 1 - Task Grammar"
285
286         echo -e 'already completed manually\n'
287
288 print_heading "Step 2 - Pronunciation Dictionnary"
289         make_wlist_label_file
290     HDMan -A -D -T 1 -m -w ./interim_files/wlist -e ./input_files -n ./interim_files/monophones1 -i -l logs/Step2_HDMan1_log ./interim_files/dict $LexiconDirectory/VoxForge/VoxForgeDict > logs/Step2_HDMan2_log
291     make_monophones0
292         echo -e '***Please review the following HDMan output***:\n'
293         cat logs/Step2_HDMan1_log
294         
295 print_heading "Step 3 - Recording the Data"
296         echo -e 'already completed manually\n'
297
298 print_heading "Step 4 - Creating Transcription Files"
299         make_wordsmlf
300 #       HLEd -A -D -T 1 -l '*' -d ./interim_files/dict -i ./interim_files/phones0.mlf ./input_files/mkphones0.led ./interim_files/words.mlf > logs/Step4_HLEd_phones0_log
301 #       HLEd -A -D -T 1 -l '*' -d ./interim_files/dict -i ./interim_files/phones1.mlf ./input_files/mkphones1.led ./interim_files/words.mlf > logs/Step4_HLEd_phones1_log
302         HLEd -A -D -T 1        -d ./interim_files/dict -i ./interim_files/phones0.mlf ./input_files/mkphones0.led ./interim_files/words.mlf > logs/Step4_HLEd_phones0_log
303         HLEd -A -D -T 1        -d ./interim_files/dict -i ./interim_files/phones1.mlf ./input_files/mkphones1.led ./interim_files/words.mlf > logs/Step4_HLEd_phones1_log
304
305 print_heading "Step 5 - Coding the (Audio) Data"       
306 #       HCopy -A -D -T 1 -C ./input_files/wav_config -S master_codetrain_8kHz:16bit.scp > logs/Step5_HCopy_log
307         echo -e 'already completed manually\n'
308                 
309 print_heading "Step 6 - Creating Monophones"
310         perl ./prompts2trainscp.pl ./interim_files/master_prompts ./interim_files/train.scp
311
312     echo -e 'making hmm0\n'
313         HCompV -A -D -T 1 -C ./input_files/config -f 0.01 -m -S ./interim_files/train.scp -M ./interim_files/hmm0 input_files/proto > logs/Step6_HCompV_hmm0_log
314         make_hmmdefs
315         make_macros
316         echo -e 'making hmm1\n'
317         HERest -A -D -T 1 -C ./input_files/config -I ./interim_files/phones0.mlf -t 250.0 150.0 1000.0 -S ./interim_files/train.scp -H ./interim_files/hmm0/macros -H ./interim_files/hmm0/hmmdefs -M ./interim_files/hmm1 ./interim_files/monophones0 > logs/Step6_HERest_hmm1_log
318         echo -e 'making hmm2\n'
319         HERest -A -D -T 1 -C ./input_files/config -I ./interim_files/phones0.mlf -t 250.0 150.0 1000.0 -S ./interim_files/train.scp -H ./interim_files/hmm1/macros -H ./interim_files/hmm1/hmmdefs -M ./interim_files/hmm2 ./interim_files/monophones0 > logs/Step6_HERest_hmm2_log
320         echo -e 'making hmm3\n'
321         HERest -A -D -T 1 -C ./input_files/config -I ./interim_files/phones0.mlf -t 250.0 150.0 1000.0 -S ./interim_files/train.scp -H ./interim_files/hmm2/macros -H ./interim_files/hmm2/hmmdefs -M ./interim_files/hmm3 ./interim_files/monophones0 > logs/Step6_HERest_hmm3_log
322
323 print_heading "Step 7 - Fixing the Silence Model"
324 # using "cp ./interim_files/hmm3/. ./interim_files/hmm4 -R"
325 # causes these errors:
326 #cp: cannot create regular file `./interim_files/hmm4/./.svn/entries': Permission denied
327 #cp: cannot create regular file `./interim_files/hmm4/./.svn/text-base/macros.svn-base': Permission denied
328 #cp: cannot create regular file `./interim_files/hmm4/./.svn/text-base/hmmdefs.svn-base': Permission denied
329 cp ./interim_files/hmm3/hmmdefs ./interim_files/hmm4/hmmdefs
330 cp ./interim_files/hmm3/macros ./interim_files/hmm4/macros
331 # !!!!!!
332         echo -e 'making hmm4\n'
333         make_hmm4 2> /dev/null
334         echo -e 'making hmm5\n'
335         HHEd -A -D -T 1 -H ./interim_files/hmm4/macros -H ./interim_files/hmm4/hmmdefs -M ./interim_files/hmm5 ./input_files/sil.hed ./interim_files/monophones1 > logs/Step7_HHEd_hmm5_log
336         echo -e 'making hmm6\n'
337         HERest -A -D -T 1 -C ./input_files/config  -I ./interim_files/phones1.mlf -t 250.0 150.0 3000.0 -S ./interim_files/train.scp -H ./interim_files/hmm5/macros -H ./interim_files/hmm5/hmmdefs -M ./interim_files/hmm6 ./interim_files/monophones1 > logs/Step7_HERest_hmm6_log
338         echo -e 'making hmm7\n'
339         HERest -A -D -T 1 -C ./input_files/config  -I ./interim_files/phones1.mlf -t 250.0 150.0 3000.0 -S ./interim_files/train.scp -H ./interim_files/hmm6/macros -H ./interim_files/hmm6/hmmdefs -M ./interim_files/hmm7 ./interim_files/monophones1 > logs/Step7_HERest_hmm7_log
340
341 print_heading "Step 8 - Realigning the Training Data"
342         make_dict1
343         echo -e 'realign hmm7\n'
344         HVite -A -D -T 1 -l '*' -o SWT -b silence -C ./input_files/config -H ./interim_files/hmm7/macros -H ./interim_files/hmm7/hmmdefs -i ./interim_files/aligned.mlf -m -t 250.0 150.0 1000.0 -y lab -a -I ./interim_files/words.mlf -S ./interim_files/train.scp ./interim_files/dict1 ./interim_files/monophones1 > logs/Step8_HVite_log
345         echo -e '***Please review the HVite output log file: 'logs/Step8_HVite_log' ***:\n'
346         echo -e 'if you find warning messages stating: "No tokens survived to final node of network at beam xxx.x"\n'
347         echo -e 'listen to the wav audio file and ensure that it is properly transcribed in the corresponding label file\n'
348 #       cat logs/Step8_HVite_log
349         echo -e 'making hmm8\n'
350         HERest -A -D -T 1 -C ./input_files/config -I ./interim_files/aligned.mlf -t 250.0 150.0 3000.0 -S ./interim_files/train.scp -H ./interim_files/hmm7/macros -H ./interim_files/hmm7/hmmdefs -M ./interim_files/hmm8 ./interim_files/monophones1 > logs/Step8_HERest_hmm8_log
351         echo -e 'making hmm9\n'
352         HERest -A -D -T 1 -C ./input_files/config -I ./interim_files/aligned.mlf -t 250.0 150.0 3000.0 -S ./interim_files/train.scp -H ./interim_files/hmm8/macros -H ./interim_files/hmm8/hmmdefs -M ./interim_files/hmm9 ./interim_files/monophones1 > logs/Step8_HERest_hmm9_log
353
354 print_heading "Step 9 - Making Triphones from Monophones"
355         echo -e 'making triphones\n'   
356         HLEd -A -D -T 1 -n ./interim_files/triphones1 -l '*' -i ./interim_files/wintri.mlf ./input_files/mktri.led ./interim_files/aligned.mlf > logs/Step9_HLed_log
357         make_mktrihed
358         echo -e 'making hmm10\n'
359         HHEd -A -D -T 1 -H ./interim_files/hmm9/macros -H ./interim_files/hmm9/hmmdefs -M ./interim_files/hmm10 ./interim_files/mktri.hed ./interim_files/monophones1 > logs/Step9_HHEd_hmm10_log
360         echo -e 'making hmm11\n'
361         HERest  -A -D -T 1 -C ./input_files/config -I ./interim_files/wintri.mlf -t 250.0 150.0 3000.0 -S ./interim_files/train.scp -H ./interim_files/hmm10/macros -H ./interim_files/hmm10/hmmdefs -M ./interim_files/hmm11 ./interim_files/triphones1 > logs/Step9_HERest_hmm11_log
362         echo -e 'making hmm12\n'
363         HERest  -A -D -T 1 -C ./input_files/config -I ./interim_files/wintri.mlf -t 250.0 150.0 3000.0 -s ./interim_files/stats -S ./interim_files/train.scp -H ./interim_files/hmm11/macros -H ./interim_files/hmm11/hmmdefs -M ./interim_files/hmm12 ./interim_files/triphones1 > logs/Step9_HERest_hmm12_log
364
365 print_heading "Step 10 - Making Tied-State Triphones"
366         HDMan -A -D -T 1 -b sp -n ./interim_files/fulllist -g ./input_files/global.ded -l logs/Step10_HDMan_flog ./interim_files/dict-tri $LexiconDirectory/VoxForge/VoxForgeDict > logs/Step10_HDMan_log
367         make_fulllist 
368         make_treehed
369         echo -e 'making hmm13\n'
370         HHEd -A -D -T 1 -H ./interim_files/hmm12/macros -H ./interim_files/hmm12/hmmdefs -M ./interim_files/hmm13 ./interim_files/tree.hed ./interim_files/triphones1 > logs/Step10_HHed_hmm13_log
371         echo -e 'making hmm14\n'
372         HERest -A -D -T 1 -T 1 -C ./input_files/config -I ./interim_files/wintri.mlf -t 250.0 150.0 3000.0 -s ./interim_files/stats -S ./interim_files/train.scp -H ./interim_files/hmm13/macros -H ./interim_files/hmm13/hmmdefs -M ./interim_files/hmm14 ./interim_files/tiedlist > logs/Step10_HERest_hmm14_log
373         echo -e 'making hmm15\n'
374         HERest -A -D -T 1 -T 1 -C ./input_files/config -I ./interim_files/wintri.mlf -t 250.0 150.0 3000.0 -s ./interim_files/stats -S ./interim_files/train.scp -H ./interim_files/hmm14/macros -H ./interim_files/hmm14/hmmdefs -M ./interim_files/hmm15 ./interim_files/tiedlist > logs/Step10_HERest_hmm15_log
375
376         cp ./interim_files/hmm15/hmmdefs ../acoustic_model_files
377         cp ./interim_files/hmm15/macros ../acoustic_model_files
378         cp ./interim_files/tiedlist ../acoustic_model_files
379         
380 print_heading "***completed***"
381
Note: See TracBrowser for help on using the browser.