[egs] Fixed some issues in the multilingual BABEL example scripts (#1850)
[processor-sdk/kaldi.git] / egs / babel_multilang / s5 / local / nnet3 / run_common_langs.sh
1 #!/bin/bash
3 # Copyright 2016 Pegah Ghahremani
5 # This script used to generate MFCC+pitch features for input language lang.
7 . ./cmd.sh
8 set -e
9 stage=1
10 train_stage=-10
11 generate_alignments=true # If true, it regenerates alignments.
12 speed_perturb=true
13 use_pitch=true      # If true, it generates pitch features and combine it with 40dim MFCC.
14 pitch_conf=conf/pitch.conf # Configuration used for pitch extraction.
15 feat_suffix=_hires  # feature suffix for training data
17 [ ! -f ./conf/common_vars.sh ] && echo 'the file conf/common_vars.sh does not exist!' && exit 1
19 . conf/common_vars.sh || exit 1;
21 [ -f local.conf ] && . ./local.conf
23 . ./utils/parse_options.sh
25 lang=$1
27 # perturbed data preparation
28 train_set=train
30 if [ $# -ne 1 ]; then
31   echo "Usage:$0 [options] <language-id>"
32   echo "e.g. $0 102-assamese"
33   exit 1;
34 fi
36 if [ "$speed_perturb" == "true" ]; then
37   if [ $stage -le 1 ]; then
38     #Although the nnet model will be trained by high resolution data, we still have to perturbe the normal data to get the alignment
39     # _sp stands for speed-perturbed
40     for datadir in train; do
41       if [ ! -d data/$lang/${datadir}_sp ]; then
42         ./utils/data/perturb_data_dir_speed_3way.sh data/$lang/${datadir} data/$lang/${datadir}_sp
44         # Extract Plp+pitch feature for perturbed data.
45         featdir=plp_perturbed/$lang
46         if $use_pitch; then
47           steps/make_plp_pitch.sh --cmd "$train_cmd" --nj 70  data/$lang/${datadir}_sp exp/$lang/make_plp_pitch/${datadir}_sp $featdir
48         else
49           steps/make_plp.sh --cmd "$train_cmd" --nj 70 data/$lang/${datadir}_sp exp/$lang/make_plp/${datadir}_sp $featdir
50         fi
51         steps/compute_cmvn_stats.sh data/$lang/${datadir}_sp exp/$lang/make_plp/${datadir}_sp $featdir || exit 1;
52         utils/fix_data_dir.sh data/$lang/${datadir}_sp
53       fi
54     done
55   fi
57   train_set=train_sp
58   if [ $stage -le 2 ] && [ "$generate_alignments" == "true" ] && [ ! -f exp/$lang/tri5_ali_sp/.done ]; then
59     #obtain the alignment of the perturbed data
60     steps/align_fmllr.sh \
61       --nj 70 --cmd "$train_cmd" \
62       --boost-silence $boost_sil \
63       data/$lang/$train_set data/$lang/lang exp/$lang/tri5 exp/$lang/tri5_ali_sp || exit 1
64     touch exp/$lang/tri5_ali_sp/.done
65   fi
66 fi
68 hires_config="--mfcc-config conf/mfcc_hires.conf"
69 mfccdir=mfcc_hires/$lang
70 mfcc_affix=""
71 if $use_pitch; then
72   hires_config="$hires_config --online-pitch-config $pitch_conf"
73   mfccdir=mfcc_hires_pitch/$lang
74   mfcc_affix=_pitch_online
75 fi
77 if [ $stage -le 3 ] && [ ! -f data/$lang/${train_set}${feat_suffix}/.done ]; then
78   if [[ $(hostname -f) == *.clsp.jhu.edu ]] && [ ! -d $mfccdir/storage ]; then
79     date=$(date +'%m_%d_%H_%M')
80     utils/create_split_dir.pl /export/b0{1,2,3,4}/$USER/kaldi-data/egs/$lang-$date/s5c/$mfccdir/storage $mfccdir/storage
81   fi
84   for dataset in $train_set ; do
85     data_dir=data/$lang/${dataset}${feat_suffix}
86     log_dir=exp/$lang/make${feat_suffix}/$dataset
88     utils/copy_data_dir.sh data/$lang/$dataset ${data_dir} || exit 1;
90     # scale the waveforms, this is useful as we don't use CMVN
91     utils/data/perturb_data_dir_volume.sh $data_dir || exit 1;
93     steps/make_mfcc${mfcc_affix}.sh --nj 70 $hires_config \
94       --cmd "$train_cmd" ${data_dir} $log_dir $mfccdir;
96     steps/compute_cmvn_stats.sh ${data_dir} $log_dir $mfccdir;
98     # Remove the small number of utterances that couldn't be extracted for some
99     # reason (e.g. too short; no such file).
100     utils/fix_data_dir.sh ${data_dir};
101   done
102   touch ${data_dir}/.done
103 fi
104 exit 0;