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