|
| 1 | +#!/bin/bash |
| 2 | +. ./path.sh |
| 3 | + |
| 4 | +final_sil_prob=0.5 |
| 5 | + |
| 6 | +echo "$0 $@" # Print the command line for logging |
| 7 | + |
| 8 | +. utils/parse_options.sh |
| 9 | + |
| 10 | +if [ $# -ne 1 ]; then |
| 11 | + echo "Usage: $0 <lang>" |
| 12 | + echo " Add final optional silence to lexicon FSTs (L.fst and L_disambig.fst) in " |
| 13 | + echo " lang/ directory <lang>." |
| 14 | + echo " This can be useful in systems with byte-pair encoded (BPE) lexicons, in which" |
| 15 | + echo " the word-initial silence is part of the lexicon, so we turn off the standard" |
| 16 | + echo " optional silence in the lexicon" |
| 17 | + echo "options:" |
| 18 | + echo " --final-sil-prob <final silence probability> # default 0.5" |
| 19 | + exit 1; |
| 20 | +fi |
| 21 | + |
| 22 | +lang=$1 |
| 23 | + |
| 24 | +if [ $lang/phones/final_sil_prob -nt $lang/phones/nonsilence.txt ]; then |
| 25 | + echo "$0 $lang/phones/final_sil_prob exists. Exiting..." |
| 26 | + exit 1; |
| 27 | +fi |
| 28 | + |
| 29 | +sil_eq_zero=$(echo $(perl -e "if ( $final_sil_prob == 0.0) {print 'true';} else {print 'false';}")) |
| 30 | +sil_eq_one=$(echo $(perl -e "if ( $final_sil_prob == 1.0) {print 'true';} else {print 'false';}")) |
| 31 | +sil_lt_zero=$(echo $(perl -e "if ( $final_sil_prob < 0.0) {print 'true';} else {print 'false';}")) |
| 32 | +sil_gt_one=$(echo $(perl -e "if ( $final_sil_prob > 1.0) {print 'true';} else {print 'false';}")) |
| 33 | + |
| 34 | +if $sil_lt_zero || $sil_gt_one; then |
| 35 | + echo "$0 final-sil-prob should be between 0.0 and 1.0. Final silence was not added." |
| 36 | + exit 1; |
| 37 | +else |
| 38 | + if $sil_eq_zero; then |
| 39 | + echo "$0 final-sil-prob = 0 => Final silence was not added." |
| 40 | + exit 0; |
| 41 | + elif $sil_eq_one; then |
| 42 | + echo -e "0\t1\t1\t0\n1" | fstcompile > $lang/final_sil.fst |
| 43 | + else |
| 44 | + log_silprob=$(echo $(perl -e "print log $final_sil_prob")) |
| 45 | + echo -e "0\t1\t1\t0\t$log_silprob\n0\t$log_silprob\n1\t0.0" | fstcompile > $lang/final_sil.fst |
| 46 | + fi |
| 47 | + mv $lang/L.fst $lang/L.fst.orig |
| 48 | + mv $lang/L_disambig.fst $lang/L_disambig.fst.orig |
| 49 | + fstconcat $lang/L.fst.orig $lang/final_sil.fst | fstarcsort --sort_type=olabel > $lang/L.fst |
| 50 | + fstconcat $lang/L_disambig.fst.orig $lang/final_sil.fst | fstarcsort --sort_type=olabel > $lang/L_disambig.fst |
| 51 | + echo "$final_sil_prob" > $lang/phones/final_sil_prob |
| 52 | +fi |
| 53 | + |
0 commit comments