tomwalters@301: #!/bin/bash tomwalters@301: # using getopts tomwalters@301: # tomwalters@301: # Train and test an HTK monophone model using AIM tomwalters@301: # features and the CNBH syllable databse tomwalters@301: # tomwalters@301: # Copyright 2009-2010 University of Cambridge tomwalters@301: # Author: Thomas Walters tomwalters@301: # Based on the MATLAB scripts by Jess Monaghan and tomwalters@301: # modelled on HTKTimit.sh from Cantab Research tomwalters@301: tomwalters@301: skip_features= tomwalters@301: skip_init= tomwalters@301: matlab_plot= tomwalters@301: while getopts 'fim' OPTION tomwalters@301: do tomwalters@301: case $OPTION in tomwalters@301: f) skip_features=1 tomwalters@301: ;; tomwalters@301: i) skip_init=1 tomwalters@301: ;; tomwalters@301: m) matlab_plot=1 tomwalters@301: ;; tomwalters@301: # b) bflag=1 tomwalters@301: # bval="$OPTARG" tomwalters@301: # ;; tomwalters@301: ?) printf "Usage: %s: [-f] [-i] [-m] args\n" $(basename $0) >&2 tomwalters@301: exit 2 tomwalters@301: ;; tomwalters@301: esac tomwalters@301: done tomwalters@301: shift $(($OPTIND - 1)) tomwalters@301: tomwalters@301: # Machine list tomwalters@301: USE_MULTIPLE_MACHINES= tomwalters@301: MACHINE_LIST="db-xserve2 db-xserve3 db-xserve5 db-xserve6 db-xserve7 db-xserve8" tomwalters@301: MACHINE_COUNT=`echo $MACHINE_LIST | wc -w | sed 's/ *//'` tomwalters@301: # Cores per machine tomwalters@301: MACHINE_CORES=4 tomwalters@301: tomwalters@301: # Set to true / 1 to enable MFCC features rather than AIM features tomwalters@301: # (leave blank for AIM features) tomwalters@301: MFCC_FEATURES= tomwalters@301: tomwalters@301: # Source directory for all the sound files tomwalters@304: SOUND_SOURCE="/media/sounds-database/cnbh-sounds" tomwalters@301: tomwalters@301: # Location of the AIMCopy binary if not in the path tomwalters@303: AIMCOPY_PREFIX="../aimc-read-only/build/posix-release/" tomwalters@301: tomwalters@301: # Location of HTK binaries if not in the path tomwalters@303: HTK_PREFIX="" tomwalters@301: tomwalters@301: # Names of various internal files and directories. tomwalters@301: # Rename here if you don't like them for some reason. tomwalters@301: SYLLIST=syls tomwalters@301: SYLLIST_COMPLETE=syllist tomwalters@301: GRAM=gram tomwalters@301: DICT=dict tomwalters@301: WDNET=wdnet tomwalters@301: TRAIN_SPEAKERS=train_speakers tomwalters@301: TEST_SPEAKERS=test_speakers tomwalters@301: WORK_PREFIX=work tomwalters@301: TRAIN_LIST=train.list tomwalters@301: TEST_LIST=test.list tomwalters@301: COMBINED_LIST=combined.list tomwalters@301: TRAIN_MLF=train.mlf tomwalters@301: TEST_MLF=test.mlf tomwalters@301: TRAIN_SCRIPT=train.scp tomwalters@301: TEST_SCRIPT=test.scp tomwalters@301: FEATURES_DIR=features tomwalters@301: AIMCOPY_CONFIG=aimcopy.cfg tomwalters@301: AIMCOPY_LOG_TRAIN=aimcopy_train.log tomwalters@301: AIMCOPY_LOG_TEST=aimcopy_test.log tomwalters@301: HCOPY_CONFIG=hcopy.cfg tomwalters@301: HMMCONFIG=hmmconfig tomwalters@301: HMMPROTO=proto tomwalters@301: RECOUT=recout.mlf tomwalters@301: RESULTS_FILE=results.txt tomwalters@301: MISCLASSIFIED=misclassified.txt tomwalters@301: HHED_SCRIPT=cmdscript tomwalters@301: tomwalters@301: # The vowels and consonants that make up the CNBH database tomwalters@301: VOWELS="a e i o u" tomwalters@301: CONSONANTS="b d f g h k l m n p r s t v w x y z" tomwalters@301: SILENCE="sil" tomwalters@301: tomwalters@301: WORK=${WORK_PREFIX}`echo $1 | tr -d ' '` tomwalters@301: mkdir -p $WORK tomwalters@301: tomwalters@301: # Make a copy of this script in the experimental directory tomwalters@301: cp -p $0 $WORK tomwalters@301: tomwalters@301: if [ "$skip_init" ] tomwalters@301: then tomwalters@301: echo "Skipping initialisation" tomwalters@301: else tomwalters@301: # Make the sets of VC, CV, and vowel only labels, plus silence and use them to tomwalters@301: # generate the grammar, dictionary and list of syllables tomwalters@301: echo "Generating grammar, dictionary and syllable list..." tomwalters@301: echo -n '$word = ' > $WORK/$GRAM tomwalters@301: FIRST=true; tomwalters@301: for v in $VOWELS; do tomwalters@301: echo $v$v >> $WORK/$SYLLIST.tmp tomwalters@301: echo "$v$v [$v$v] $v$v" >> $WORK/$DICT.tmp tomwalters@301: if $FIRST; then tomwalters@301: echo -n "$v$v" >> $WORK/$GRAM tomwalters@301: FIRST=false tomwalters@301: else tomwalters@301: echo -n " | $v$v" >> $WORK/$GRAM tomwalters@301: fi tomwalters@301: for c in $CONSONANTS; do tomwalters@301: echo $v$c >> $WORK/$SYLLIST.tmp tomwalters@301: echo "$v$c [$v$c] $v$c" >> $WORK/$DICT.tmp tomwalters@301: echo -n " | $v$c" >> $WORK/$GRAM tomwalters@301: echo $c$v >> $WORK/$SYLLIST.tmp tomwalters@301: echo "$c$v [$c$v] $c$v" >> $WORK/$DICT.tmp tomwalters@301: echo -n " | $c$v" >> $WORK/$GRAM tomwalters@301: done tomwalters@301: done tomwalters@301: echo ';' >> $WORK/$GRAM tomwalters@301: tomwalters@301: # Sort the syllable list and the dictionary and delete the tomwalters@301: # temporary, unsorted version tomwalters@301: sort $WORK/$SYLLIST.tmp > $WORK/$SYLLIST tomwalters@301: rm $WORK/$SYLLIST.tmp tomwalters@301: sort $WORK/$DICT.tmp > $WORK/$DICT tomwalters@301: rm $WORK/$DICT.tmp tomwalters@301: tomwalters@301: # Add silence to the end of the various files just generated tomwalters@301: cp $WORK/$SYLLIST $WORK/$SYLLIST_COMPLETE tomwalters@301: echo $SILENCE >> $WORK/$SYLLIST_COMPLETE tomwalters@301: echo "end_$SILENCE [$SILENCE] $SILENCE" >> $WORK/$DICT tomwalters@301: echo "start_$SILENCE [$SILENCE] $SILENCE" >> $WORK/$DICT tomwalters@301: echo "( start_$SILENCE \$word end_$SILENCE )" >> $WORK/$GRAM tomwalters@301: tomwalters@301: # Use HParse to parse the grammar into a wordnet tomwalters@301: echo "Generating wordnet from grammar..." tomwalters@301: ${HTK_PREFIX}HParse $WORK/$GRAM $WORK/$WDNET tomwalters@301: tomwalters@301: # Generate a list of filenames from the spoke pattern tomwalters@301: cat <<"EOF" > $WORK/$TRAIN_SPEAKERS tomwalters@301: 170.9p112.2s100.0t+000itd tomwalters@301: 171.0p112.8s100.0t+000itd tomwalters@301: 171.3p111.7s100.0t+000itd tomwalters@301: 171.5p113.1s100.0t+000itd tomwalters@301: 171.9p111.5s100.0t+000itd tomwalters@301: 172.1p113.0s100.0t+000itd tomwalters@301: 172.4p111.9s100.0t+000itd tomwalters@301: 172.5p112.5s100.0t+000itd tomwalters@301: EOF tomwalters@301: tomwalters@301: cat <<"EOF" > $WORK/$TEST_SPEAKERS tomwalters@301: 137.0p104.3s100.0t+000itd tomwalters@301: 141.3p135.4s100.0t+000itd tomwalters@301: 145.5p106.3s100.0t+000itd tomwalters@301: 148.8p128.8s100.0t+000itd tomwalters@301: 151.6p83.9s100.0t+000itd tomwalters@301: 153.0p108.1s100.0t+000itd tomwalters@301: 155.5p123.5s100.0t+000itd tomwalters@301: 156.7p90.6s100.0t+000itd tomwalters@301: 159.5p109.6s100.0t+000itd tomwalters@301: 161.1p119.4s100.0t+000itd tomwalters@301: 161.1p96.8s100.0t+000itd tomwalters@301: 163.4p157.6s100.0t+000itd tomwalters@301: 164.7p110.8s100.0t+000itd tomwalters@301: 164.9p102.1s100.0t+000itd tomwalters@301: 165.6p144.0s100.0t+000itd tomwalters@301: 165.7p116.2s100.0t+000itd tomwalters@301: 167.4p133.5s100.0t+000itd tomwalters@301: 167.8p106.5s100.0t+000itd tomwalters@301: 168.6p111.6s100.0t+000itd tomwalters@301: 168.9p125.4s100.0t+000itd tomwalters@301: 169.0p114.0s100.0t+000itd tomwalters@301: 170.0p109.7s100.0t+000itd tomwalters@301: 170.1p119.5s100.0t+000itd tomwalters@301: 171.0p115.5s100.0t+000itd tomwalters@301: 171.7p112.3s100.0t+000itd tomwalters@301: 172.4p109.3s100.0t+000itd tomwalters@301: 173.3p105.6s100.0t+000itd tomwalters@301: 173.5p115.0s100.0t+000itd tomwalters@301: 174.5p100.6s100.0t+000itd tomwalters@301: 174.5p110.6s100.0t+000itd tomwalters@301: 174.9p113.0s100.0t+000itd tomwalters@301: 175.7p118.5s100.0t+000itd tomwalters@301: 176.1p94.5s100.0t+000itd tomwalters@301: 178.0p108.5s100.0t+000itd tomwalters@301: 178.1p87.6s100.0t+000itd tomwalters@301: 178.8p123.6s100.0t+000itd tomwalters@301: 179.0p113.9s100.0t+000itd tomwalters@301: 180.4p80.1s100.0t+000itd tomwalters@301: 183.0p105.7s100.0t+000itd tomwalters@301: 183.0p130.4s100.0t+000itd tomwalters@301: 184.8p115.1s100.0t+000itd tomwalters@301: 188.1p139.2s100.0t+000itd tomwalters@301: 189.6p102.1s100.0t+000itd tomwalters@301: 192.7p116.7s100.0t+000itd tomwalters@301: 194.5p150.4s100.0t+000itd tomwalters@301: 198.1p97.9s100.0t+000itd tomwalters@301: 202.7p118.6s100.0t+000itd tomwalters@301: 208.6p93.2s100.0t+000itd tomwalters@301: 215.2p121.0s100.0t+000itd tomwalters@301: EOF tomwalters@301: tomwalters@301: # Construct the conversion scripts for AIMCopy (or HCopy) and tomwalters@301: # the master label files for the train and test sets tomwalters@301: tomwalters@301: echo "Generating train and test scripts and master label files..." tomwalters@301: exec 4> $WORK/$TRAIN_MLF tomwalters@301: exec 6> $WORK/$TEST_MLF tomwalters@301: echo '#!MLF!#' >&4 tomwalters@301: echo '#!MLF!#' >&6 tomwalters@301: if [ -a $WORK/$TRAIN_LIST ] tomwalters@301: then tomwalters@301: rm $WORK/$TRAIN_LIST tomwalters@301: fi tomwalters@301: if [ -a $WORK/$TEST_LIST ] tomwalters@301: then tomwalters@301: rm $WORK/$TEST_LIST tomwalters@301: fi tomwalters@301: if [ -a $WORK/$TRAIN_SCRIPT ] tomwalters@301: then tomwalters@301: rm $WORK/$TRAIN_SCRIPT tomwalters@301: fi tomwalters@301: if [ -a $WORK/$TEST_SCRIPT ] tomwalters@301: then tomwalters@301: rm $WORK/$TEST_SCRIPT tomwalters@301: fi tomwalters@301: exec 3> $WORK/$TRAIN_LIST tomwalters@301: exec 5> $WORK/$TEST_LIST tomwalters@301: exec 7> $WORK/$TRAIN_SCRIPT tomwalters@301: exec 8> $WORK/$TEST_SCRIPT tomwalters@301: for syllable in $(cat $WORK/$SYLLIST); do tomwalters@301: for speaker in $(cat $WORK/$TRAIN_SPEAKERS); do tomwalters@301: SOURCE_FILENAME=$SOUND_SOURCE/$syllable/${syllable}${speaker}.wav tomwalters@301: DEST_FILENAME=$WORK/$FEATURES_DIR/$syllable/${syllable}${speaker} tomwalters@301: echo "$SOURCE_FILENAME ${DEST_FILENAME}.htk" >&3 tomwalters@301: echo "'${DEST_FILENAME}.htk'" >&7 tomwalters@301: echo "'\"${DEST_FILENAME}.lab\"'" >&4 tomwalters@301: echo "$SILENCE" >&4 tomwalters@301: echo $syllable >&4 tomwalters@301: echo "$SILENCE" >&4 tomwalters@301: echo "." >&4 tomwalters@301: done tomwalters@301: for speaker in $(cat $WORK/$TEST_SPEAKERS); do tomwalters@301: SOURCE_FILENAME=$SOUND_SOURCE/$syllable/${syllable}${speaker}.wav tomwalters@301: DEST_FILENAME=$WORK/$FEATURES_DIR/$syllable/${syllable}${speaker} tomwalters@301: echo "$SOURCE_FILENAME ${DEST_FILENAME}.htk" >&5 tomwalters@301: echo "'${DEST_FILENAME}.htk'" >&8 tomwalters@301: echo "'\"${DEST_FILENAME}.lab\"'" >&6 tomwalters@301: echo "$SILENCE" >&6 tomwalters@301: echo $syllable >&6 tomwalters@301: echo "$SILENCE" >&6 tomwalters@301: echo "." >&6 tomwalters@301: done tomwalters@301: done tomwalters@301: exec 3>&- tomwalters@301: exec 4>&- tomwalters@301: exec 5>&- tomwalters@301: exec 6>&- tomwalters@301: exec 7>&- tomwalters@301: exec 8>&- tomwalters@301: fi tomwalters@301: tomwalters@301: if [ "$skip_features" ] tomwalters@301: then tomwalters@301: echo "Skipping feature generation" tomwalters@301: else tomwalters@301: # Make the necessary directories for the computed features tomwalters@301: echo "Making directory structure..." tomwalters@301: mkdir $WORK/$FEATURES_DIR tomwalters@301: for syllable in $(cat $WORK/$SYLLIST); do tomwalters@301: mkdir $WORK/$FEATURES_DIR/$syllable tomwalters@301: done tomwalters@301: tomwalters@301: if [ "$MFCC_FEATURES" ] tomwalters@301: then tomwalters@301: # Write the HCopy config file tomwalters@301: echo "Creating HCopy config file..." tomwalters@301: cat <<"EOF" > $WORK/$HCOPY_CONFIG tomwalters@301: # Coding parameters tomwalters@301: SOURCEFORMAT= WAV tomwalters@301: TARGETKIND = MFCC_0_D_A tomwalters@301: TARGETRATE = 100000.0 tomwalters@301: SAVECOMPRESSED = T tomwalters@301: SAVEWITHCRC = T tomwalters@301: WINDOWSIZE = 250000.0 tomwalters@301: USEHAMMING = T tomwalters@301: PREEMCOEF = 0.97 tomwalters@301: NUMCHANS = 200 tomwalters@301: CEPLIFTER = 22 tomwalters@301: NUMCEPS = 12 tomwalters@301: ENORMALISE = F tomwalters@301: EOF tomwalters@301: echo "Generating features for training..." tomwalters@301: ${HTK_PREFIX}HCopy -T 1 -C $WORK/$HCOPY_CONFIG -S $WORK/${TRAIN_LIST} tomwalters@301: tomwalters@301: echo "Generating features for testing..." tomwalters@301: ${HTK_PREFIX}HCopy -T 1 -C $WORK/$HCOPY_CONFIG -S $WORK/${TEST_LIST} tomwalters@301: else tomwalters@301: # Write the AIMCopy config file tomwalters@301: echo "Creating AIMCopy config file..." tomwalters@301: cat <<"EOF" > $WORK/$AIMCOPY_CONFIG tomwalters@301: input.buffersize=480 tomwalters@301: gtfb.channel_count=200 tomwalters@301: gtfb.min_frequency=86.0 tomwalters@301: gtfb.max_frequency=16000.0 tomwalters@301: nap.do_lowpass=true tomwalters@301: nap.lowpass_cutoff=100.0 tomwalters@301: slice.temporal=false tomwalters@301: slice.all=true tomwalters@301: slice.normalize=true tomwalters@301: EOF tomwalters@301: if [ "$USE_MULTIPLE_MACHINES" ] tomwalters@301: then tomwalters@301: echo "Splitting data files..." tomwalters@301: cat $WORK/${TRAIN_LIST} $WORK/${TEST_LIST} > $WORK/${COMBINED_LIST} tomwalters@301: total_cores=$(($MACHINE_COUNT*$MACHINE_CORES)) tomwalters@301: echo -n $total_cores tomwalters@301: echo " cores available" tomwalters@301: total_files=`cat $WORK/${COMBINED_LIST} | wc -l | sed 's/ *//'` tomwalters@301: echo -n $total_files tomwalters@301: echo " files to process" tomwalters@301: files_per_core=$(($total_files/$total_cores+1)) tomwalters@301: echo -n $files_per_core tomwalters@301: echo " files per core" tomwalters@301: split -l $files_per_core $WORK/${COMBINED_LIST} $WORK/split_list tomwalters@301: splits=( $(ls $WORK/split_list*)) tomwalters@301: element=0 tomwalters@301: echo "Spawning tasks..." tomwalters@301: for m in $MACHINE_LIST; do tomwalters@301: for ((c=1;c<=$MACHINE_CORES;c+=1)); do tomwalters@301: s=${splits[$element]} tomwalters@301: echo "ssh $m \"cd HTK-AIM;${AIMCOPY_PREFIX}AIMCopy -C $WORK/$AIMCOPY_CONFIG -S $s\" &" tomwalters@301: #ssh $m "cd HTK-AIM;${AIMCOPY_PREFIX}AIMCopy -C $WORK/$AIMCOPY_CONFIG -S $s" & tomwalters@301: let element=element+1 tomwalters@301: done tomwalters@301: done tomwalters@301: echo "Waiting for tasks to complete..." tomwalters@301: wait tomwalters@301: else tomwalters@301: echo "Generating features for training..." tomwalters@301: ${AIMCOPY_PREFIX}AIMCopy -C $WORK/$AIMCOPY_CONFIG -S $WORK/${TRAIN_LIST} -D $WORK/$AIMCOPY_LOG_TRAIN tomwalters@301: tomwalters@301: echo "Generating features for testing..." tomwalters@301: ${AIMCOPY_PREFIX}AIMCopy -C $WORK/$AIMCOPY_CONFIG -S $WORK/${TEST_LIST} -D $WORK/$AIMCOPY_LOG_TEST tomwalters@301: fi tomwalters@301: fi tomwalters@301: fi tomwalters@301: tomwalters@301: if [ "$MFCC_FEATURES" ] tomwalters@301: then tomwalters@301: cat <<"EOF" > $WORK/$HMMCONFIG tomwalters@301: # Coding parameters tomwalters@301: SOURCEFORMAT= HTK tomwalters@301: EOF tomwalters@301: else tomwalters@301: cat <<"EOF" > $WORK/$HMMCONFIG tomwalters@301: # Coding parameters tomwalters@301: SOURCEFORMAT= HTK tomwalters@301: SOURCEKIND= USER_E tomwalters@301: TARGETKIND = USER_E_D_A tomwalters@301: EOF tomwalters@301: fi tomwalters@301: tomwalters@301: echo "Creating HMM structure..." tomwalters@301: if [ "$MFCC_FEATURES" ] tomwalters@301: then tomwalters@301: cat <<"EOF" > $WORK/$HMMPROTO tomwalters@301: ~o 39 tomwalters@301: ~h "proto" tomwalters@301: tomwalters@301: 6 tomwalters@301: 2 tomwalters@301: 39 tomwalters@301: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 tomwalters@301: 39 tomwalters@301: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 tomwalters@301: 3 tomwalters@301: 39 tomwalters@301: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 tomwalters@301: 39 tomwalters@301: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 tomwalters@301: 4 tomwalters@301: 39 tomwalters@301: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 tomwalters@301: 39 tomwalters@301: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 tomwalters@301: 5 tomwalters@301: 39 tomwalters@301: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 tomwalters@301: 39 tomwalters@301: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 tomwalters@301: tomwalters@301: 6 tomwalters@301: 0.0 1.0 0.0 0.0 0.0 0.0 tomwalters@301: 0.0 0.6 0.4 0.0 0.0 0.0 tomwalters@301: 0.0 0.0 0.6 0.4 0.0 0.0 tomwalters@301: 0.0 0.0 0.0 0.6 0.4 0.0 tomwalters@301: 0.0 0.0 0.0 0.0 0.6 0.4 tomwalters@301: 0.0 0.0 0.0 0.0 0.0 0.0 tomwalters@301: tomwalters@301: EOF tomwalters@301: else tomwalters@301: cat <<"EOF" > $WORK/$HMMPROTO tomwalters@301: ~o 12 tomwalters@301: ~h "proto" tomwalters@301: tomwalters@301: 4 tomwalters@301: 2 tomwalters@301: 12 tomwalters@301: 0 0 0 0 0 0 0 0 0 0 0 0 tomwalters@301: 12 tomwalters@301: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 tomwalters@301: 3 tomwalters@301: 12 tomwalters@301: 0 0 0 0 0 0 0 0 0 0 0 0 tomwalters@301: 12 tomwalters@301: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 tomwalters@301: 4 tomwalters@301: 0.0 1.0 0.0 0.0 tomwalters@301: 0.0 0.6 0.4 0.0 tomwalters@301: 0.0 0.0 0.6 0.4 tomwalters@301: 0.0 0.0 0.0 0.0 tomwalters@301: tomwalters@301: EOF tomwalters@301: fi tomwalters@301: tomwalters@301: tomwalters@301: echo "Training HMM..." tomwalters@301: echo "Setting up prototype HMM..." tomwalters@301: mkdir $WORK/hmm0 tomwalters@301: ${HTK_PREFIX}HCompV -C $WORK/$HMMCONFIG -f 0.01 -m -S $WORK/$TRAIN_SCRIPT -M $WORK/hmm0 $WORK/$HMMPROTO tomwalters@301: tomwalters@301: echo "Generating HMM definitions..." tomwalters@301: # Now take the prototype file from hmm0, and create the other HMM definitions from it tomwalters@301: grep -A 9999 "" $WORK/hmm0/$HMMPROTO > $WORK/hmm0/hmms tomwalters@301: for syllable in $(cat $WORK/$SYLLIST_COMPLETE); do tomwalters@301: echo "~h $syllable" >> $WORK/hmm0/hmmdefs tomwalters@301: cat $WORK/hmm0/hmms >> $WORK/hmm0/hmmdefs tomwalters@301: done tomwalters@301: if [ "$MFCC_FEATURES" ] tomwalters@301: then tomwalters@301: echo -n "~o 1 39 39" > $WORK/hmm0/macros tomwalters@301: else tomwalters@301: echo -n "~o 1 12 12" > $WORK/hmm0/macros tomwalters@301: fi tomwalters@301: cat $WORK/hmm0/vFloors >> $WORK/hmm0/macros tomwalters@301: tomwalters@301: echo "Adding output mixture components..." tomwalters@301: cat <<"EOF" > $WORK/$HHED_SCRIPT tomwalters@301: MU 4 {*.state[2].mix} MU 4 {*.state[3].mix} MU 4 {*.state[4].mix} MU 4 {*.state[5].mix} tomwalters@301: EOF tomwalters@301: tomwalters@301: ${HTK_PREFIX}HHEd -H $WORK/hmm0/macros -H $WORK/hmm0/hmmdefs $WORK/$HHED_SCRIPT $WORK/$SYLLIST_COMPLETE tomwalters@301: tomwalters@301: for iter in 0 1 2 3 4 5 6 7 8 9; do tomwalters@301: echo "Training iteration ${iter}..." tomwalters@301: let "nextiter=$iter+1" tomwalters@301: mkdir $WORK/hmm$nextiter tomwalters@301: ${HTK_PREFIX}HERest -C $WORK/$HMMCONFIG -I $WORK/$TRAIN_MLF \ tomwalters@301: -t 250.0 150.0 1000.0 -S $WORK/$TRAIN_SCRIPT \ tomwalters@301: -H $WORK/hmm$iter/macros -H $WORK/hmm$iter/hmmdefs \ tomwalters@301: -M $WORK/hmm$nextiter $WORK/$SYLLIST_COMPLETE tomwalters@301: done tomwalters@301: tomwalters@301: echo "Testing..." tomwalters@301: for iter in 9; do tomwalters@301: ${HTK_PREFIX}HVite -H $WORK/hmm$iter/macros -H $WORK/hmm$iter/hmmdefs \ tomwalters@301: -C $WORK/$HMMCONFIG -S $WORK/$TEST_SCRIPT -i $WORK/$RECOUT \ tomwalters@301: -w $WORK/$WDNET -p 0.0 -s 5.0 $WORK/$DICT $WORK/$SYLLIST_COMPLETE tomwalters@301: echo "Results from testing on iteration ${iter}..." tomwalters@301: ${HTK_PREFIX}HResults -e "???" ${SILENCE} -I $WORK/$TEST_MLF $WORK/$SYLLIST_COMPLETE $WORK/$RECOUT tomwalters@301: done tomwalters@301: tomwalters@301: ${HTK_PREFIX}HResults -p -t -e "???" ${SILENCE} \ tomwalters@301: -I $WORK/$TEST_MLF $WORK/$SYLLIST_COMPLETE $WORK/$RECOUT > $WORK/$RESULTS_FILE tomwalters@301: tomwalters@301: grep Aligned $WORK/$RESULTS_FILE | sed -E "s/.*\/..\/([a-z]{2})([0-9]{2,3}\.[0-9])p([0-9]{2,3}\.[0-9])s.*/\2 \3/" | sort | uniq -c > $WORK/$MISCLASSIFIED tomwalters@301: tomwalters@301: echo "Final results, errors, and confusion matrix in file $WORK/$RESULTS_FILE" tomwalters@301: echo "Statstics on misclassification in file $WORK/$MISCLASSIFIED" tomwalters@301: echo "`wc -l $WORK/$SYLLIST` sounds in total" tomwalters@301: tomwalters@301: if [ "$matlab_plot" ] tomwalters@301: then tomwalters@301: echo "Plotting results figure in MATLAB..." tomwalters@301: cd matlab tomwalters@301: /Applications/MATLAB_R2007b/bin/matlab -nojvm -nosplash -r "plot_results('../${WORK}/'); exit" tomwalters@301: cd .. tomwalters@301: fi