Commit 935cb540e45de06a2676e5d04a925a20c5075b74
1 parent
143ba2a4be
Exists in
master
check if avconv is installed
Showing 1 changed file with 21 additions and 15 deletions Inline Diff
main_tools/FirstPass.sh
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | ##################################################### | 3 | ##################################################### |
4 | # File : FirstPass.sh # | 4 | # File : FirstPass.sh # |
5 | # Brief : ASR first pass and speaker diarization # | 5 | # Brief : ASR first pass and speaker diarization # |
6 | # Author : Jean-François Rey # | 6 | # Author : Jean-François Rey # |
7 | # (base on Emmanuel Ferreira # | 7 | # (base on Emmanuel Ferreira # |
8 | # and Hugo Mauchrétien works) # | 8 | # and Hugo Mauchrétien works) # |
9 | # Version : 1.1 # | 9 | # Version : 1.1 # |
10 | # Date : 18/06/13 # | 10 | # Date : 18/06/13 # |
11 | ##################################################### | 11 | ##################################################### |
12 | 12 | ||
13 | echo "### FirstPass.sh ###" | 13 | echo "### FirstPass.sh ###" |
14 | 14 | ||
15 | # Check OTMEDIA_HOME env var | 15 | # Check OTMEDIA_HOME env var |
16 | if [ -z ${OTMEDIA_HOME} ] | 16 | if [ -z ${OTMEDIA_HOME} ] |
17 | then | 17 | then |
18 | OTMEDIA_HOME=$(dirname $(dirname $(readlink -e $0))) | 18 | OTMEDIA_HOME=$(dirname $(dirname $(readlink -e $0))) |
19 | export OTMEDIA_HOME=$OTMEDIA_HOME | 19 | export OTMEDIA_HOME=$OTMEDIA_HOME |
20 | fi | 20 | fi |
21 | 21 | ||
22 | # where is FirstPass.sh | 22 | # where is FirstPass.sh |
23 | MAIN_SCRIPT_PATH=$(dirname $(readlink -e $0)) | 23 | MAIN_SCRIPT_PATH=$(dirname $(readlink -e $0)) |
24 | 24 | ||
25 | # scripts path | 25 | # scripts path |
26 | SCRIPT_PATH=$OTMEDIA_HOME/tools/scripts | 26 | SCRIPT_PATH=$OTMEDIA_HOME/tools/scripts |
27 | 27 | ||
28 | # Include scripts | 28 | # Include scripts |
29 | . $SCRIPT_PATH"/Tools.sh" | 29 | . $SCRIPT_PATH"/Tools.sh" |
30 | . $SCRIPT_PATH"/CheckFirstPass.sh" | 30 | . $SCRIPT_PATH"/CheckFirstPass.sh" |
31 | 31 | ||
32 | # where is FirstPass.cfg | 32 | # where is FirstPass.cfg |
33 | FIRSTPASS_CONFIG_FILE=$OTMEDIA_HOME"/cfg/FirstPass.cfg" | 33 | FIRSTPASS_CONFIG_FILE=$OTMEDIA_HOME"/cfg/FirstPass.cfg" |
34 | if [ -e $FIRSTPASS_CONFIG_FILE ] | 34 | if [ -e $FIRSTPASS_CONFIG_FILE ] |
35 | then | 35 | then |
36 | . $FIRSTPASS_CONFIG_FILE | 36 | . $FIRSTPASS_CONFIG_FILE |
37 | else | 37 | else |
38 | echo "ERROR : Can't find configuration file $FIRSTPASS_CONFIG_FILE" >&2 | 38 | echo "ERROR : Can't find configuration file $FIRSTPASS_CONFIG_FILE" >&2 |
39 | echo "exit" >&2 | 39 | echo "exit" >&2 |
40 | exit 1 | 40 | exit 1 |
41 | fi | 41 | fi |
42 | 42 | ||
43 | #---------------# | 43 | #---------------# |
44 | # Parse Options # | 44 | # Parse Options # |
45 | #---------------# | 45 | #---------------# |
46 | while getopts ":hDv:cf:r" opt | 46 | while getopts ":hDv:cf:r" opt |
47 | do | 47 | do |
48 | case $opt in | 48 | case $opt in |
49 | h) | 49 | h) |
50 | echo -e "$0 [OPTIONS] <WAV_FILE> <OUTPUT_DIRECTORY>\n" | 50 | echo -e "$0 [OPTIONS] <WAV_FILE> <OUTPUT_DIRECTORY>\n" |
51 | echo -e "\t Options:" | 51 | echo -e "\t Options:" |
52 | echo -e "\t\t-h :\tprint this message" | 52 | echo -e "\t\t-h :\tprint this message" |
53 | echo -e "\t\t-D :\tDEBUG mode on" | 53 | echo -e "\t\t-D :\tDEBUG mode on" |
54 | echo -e "\t\t-v l :\tVerbose mode, l=(1|2|3) level mode" | 54 | echo -e "\t\t-v l :\tVerbose mode, l=(1|2|3) level mode" |
55 | echo -e "\t\t-c :\tCheck process, and log it into files, can stop if error detected" | 55 | echo -e "\t\t-c :\tCheck process, and log it into files, can stop if error detected" |
56 | echo -e "\t\t-f n :\tspecify a speeral forks number (default 1)" | 56 | echo -e "\t\t-f n :\tspecify a speeral forks number (default 1)" |
57 | echo -e "\t\t-r :\tforce rerun the wav file" | 57 | echo -e "\t\t-r :\tforce rerun the wav file" |
58 | exit 1 | 58 | exit 1 |
59 | ;; | 59 | ;; |
60 | D) | 60 | D) |
61 | DEBUG=1 | 61 | DEBUG=1 |
62 | ;; | 62 | ;; |
63 | v) | 63 | v) |
64 | VERBOSE=$OPTARG | 64 | VERBOSE=$OPTARG |
65 | ;; | 65 | ;; |
66 | c) | 66 | c) |
67 | CHECK=1 | 67 | CHECK=1 |
68 | ;; | 68 | ;; |
69 | f) | 69 | f) |
70 | FORKS="--forks $OPTARG" | 70 | FORKS="--forks $OPTARG" |
71 | ;; | 71 | ;; |
72 | r) | 72 | r) |
73 | RERUN=1 | 73 | RERUN=1 |
74 | ;; | 74 | ;; |
75 | :) | 75 | :) |
76 | echo "Option -$OPTARG requires an argument." >&2 | 76 | echo "Option -$OPTARG requires an argument." >&2 |
77 | exit 1 | 77 | exit 1 |
78 | ;; | 78 | ;; |
79 | \?) | 79 | \?) |
80 | echo "BAD USAGE : unknow opton -$OPTARG" | 80 | echo "BAD USAGE : unknow opton -$OPTARG" |
81 | exit 1 | 81 | exit 1 |
82 | ;; | 82 | ;; |
83 | esac | 83 | esac |
84 | done | 84 | done |
85 | 85 | ||
86 | # mode debug enable | 86 | # mode debug enable |
87 | if [ $DEBUG -eq 1 ] | 87 | if [ $DEBUG -eq 1 ] |
88 | then | 88 | then |
89 | set -x | 89 | set -x |
90 | echo -e "## Mode DEBUG ON ##" | 90 | echo -e "## Mode DEBUG ON ##" |
91 | fi | 91 | fi |
92 | 92 | ||
93 | # mode verbose enable | 93 | # mode verbose enable |
94 | if [ $VERBOSE -gt 0 ]; then echo -e "## Verbose level : $VERBOSE ##" ;fi | 94 | if [ $VERBOSE -gt 0 ]; then echo -e "## Verbose level : $VERBOSE ##" ;fi |
95 | 95 | ||
96 | # Check USAGE by arguments number | 96 | # Check USAGE by arguments number |
97 | if [ $(($#-($OPTIND-1))) -ne 2 ] | 97 | if [ $(($#-($OPTIND-1))) -ne 2 ] |
98 | then | 98 | then |
99 | echo "BAD USAGE : FirstPass.sh [OPTIONS] <WAV_FILE> <OUTPUT_DIR>" | 99 | echo "BAD USAGE : FirstPass.sh [OPTIONS] <WAV_FILE> <OUTPUT_DIR>" |
100 | echo "$0 -h for more info" | 100 | echo "$0 -h for more info" |
101 | exit 1 | 101 | exit 1 |
102 | fi | 102 | fi |
103 | 103 | ||
104 | shift $((OPTIND-1)) | 104 | shift $((OPTIND-1)) |
105 | # check audio file - First argument | 105 | # check audio file - First argument |
106 | if [ -e $1 ] && [ -s $1 ] | 106 | if [ -e $1 ] && [ -s $1 ] |
107 | then | 107 | then |
108 | # absolute path to wav file | 108 | # absolute path to wav file |
109 | WAV_FILE=$(readlink -e $1) | 109 | WAV_FILE=$(readlink -e $1) |
110 | # wav filename | 110 | # wav filename |
111 | FILENAME=$(basename $WAV_FILE) | 111 | FILENAME=$(basename $WAV_FILE) |
112 | # wav filename without extension | 112 | # wav filename without extension |
113 | BASENAME=${FILENAME%.*} | 113 | BASENAME=${FILENAME%.*} |
114 | 114 | ||
115 | print_info "[${BASENAME}] => P1 start | $(date +'%d/%m/%y %H:%M:%S')" 1 | 115 | print_info "[${BASENAME}] => P1 start | $(date +'%d/%m/%y %H:%M:%S')" 1 |
116 | print_info "[${BASENAME}] $WAV_FILE OK" 2 | 116 | print_info "[${BASENAME}] $WAV_FILE OK" 2 |
117 | else | 117 | else |
118 | print_error " Can't find $1 OR file is empty" | 118 | print_error " Can't find $1 OR file is empty" |
119 | exit 1 | 119 | exit 1 |
120 | fi | 120 | fi |
121 | 121 | ||
122 | # check output directory - Second argument | 122 | # check output directory - Second argument |
123 | if [ ! -e $2 ] | 123 | if [ ! -e $2 ] |
124 | then | 124 | then |
125 | mkdir -p $2 | 125 | mkdir -p $2 |
126 | print_info "[${BASENAME}] Make directory $2" 2 | 126 | print_info "[${BASENAME}] Make directory $2" 2 |
127 | fi | 127 | fi |
128 | 128 | ||
129 | 129 | ||
130 | #-------------# | 130 | #-------------# |
131 | # GLOBAL VARS # | 131 | # GLOBAL VARS # |
132 | #-------------# | 132 | #-------------# |
133 | OUTPUT_DIR=$(readlink -e $2) # Output directory absolute path | 133 | OUTPUT_DIR=$(readlink -e $2) # Output directory absolute path |
134 | OUTPUT_DIR_BASENAME="$OUTPUT_DIR/$BASENAME/" # New OUTPUT_DIR with BASENAME | 134 | OUTPUT_DIR_BASENAME="$OUTPUT_DIR/$BASENAME/" # New OUTPUT_DIR with BASENAME |
135 | PLP_FILE="$OUTPUT_DIR_BASENAME/$BASENAME.plp" # Global PLP file | 135 | PLP_FILE="$OUTPUT_DIR_BASENAME/$BASENAME.plp" # Global PLP file |
136 | PLP_DIR="$OUTPUT_DIR_BASENAME/PLP/" # Segmented PLP files directory | 136 | PLP_DIR="$OUTPUT_DIR_BASENAME/PLP/" # Segmented PLP files directory |
137 | PLP_LIST="$OUTPUT_DIR_BASENAME/plp.lst" # list of plp files | 137 | PLP_LIST="$OUTPUT_DIR_BASENAME/plp.lst" # list of plp files |
138 | SEG_FILE="$OUTPUT_DIR_BASENAME/$BASENAME.seg" # Global Seg file | 138 | SEG_FILE="$OUTPUT_DIR_BASENAME/$BASENAME.seg" # Global Seg file |
139 | LBL_FILE="$OUTPUT_DIR_BASENAME/$BASENAME.lbl" # Global LBL file | 139 | LBL_FILE="$OUTPUT_DIR_BASENAME/$BASENAME.lbl" # Global LBL file |
140 | RES_DIR=$OUTPUT_DIR_BASENAME"/res_p1" | 140 | RES_DIR=$OUTPUT_DIR_BASENAME"/res_p1" |
141 | LOGFILE="$OUTPUT_DIR_BASENAME/info_p1.log" | 141 | LOGFILE="$OUTPUT_DIR_BASENAME/info_p1.log" |
142 | ERRORFILE="$OUTPUT_DIR_BASENAME/error_p1.log" | 142 | ERRORFILE="$OUTPUT_DIR_BASENAME/error_p1.log" |
143 | 143 | ||
144 | #------------------# | 144 | #------------------# |
145 | # Create WORKSPACE # | 145 | # Create WORKSPACE # |
146 | #------------------# | 146 | #------------------# |
147 | if [ ! -e $OUTPUT_DIR_BASENAME ] | 147 | if [ ! -e $OUTPUT_DIR_BASENAME ] |
148 | then | 148 | then |
149 | mkdir -p $OUTPUT_DIR_BASENAME | 149 | mkdir -p $OUTPUT_DIR_BASENAME |
150 | print_info "[${BASENAME}] Make directory $OUTPUT_DIR_BASENAME" 2 | 150 | print_info "[${BASENAME}] Make directory $OUTPUT_DIR_BASENAME" 2 |
151 | fi | 151 | fi |
152 | 152 | ||
153 | # Lock directory | 153 | # Lock directory |
154 | if [ -e $OUTPUT_DIR_BASENAME/FIRSTPASS.lock ] && [ $RERUN -eq 0 ]; then exit 1; fi | 154 | if [ -e $OUTPUT_DIR_BASENAME/FIRSTPASS.lock ] && [ $RERUN -eq 0 ]; then exit 1; fi |
155 | rm "$OUTPUT_DIR_BASENAME/FIRSTPASS.unlock" > /dev/null 2>&1 | 155 | rm "$OUTPUT_DIR_BASENAME/FIRSTPASS.unlock" > /dev/null 2>&1 |
156 | touch "$OUTPUT_DIR_BASENAME/FIRSTPASS.lock" > /dev/null 2>&1 | 156 | touch "$OUTPUT_DIR_BASENAME/FIRSTPASS.lock" > /dev/null 2>&1 |
157 | 157 | ||
158 | rm -r $PLP_DIR > /dev/null 2>&1; | 158 | rm -r $PLP_DIR > /dev/null 2>&1; |
159 | mkdir -p $PLP_DIR | 159 | mkdir -p $PLP_DIR |
160 | print_info "[${BASENAME}] Make directory $PLP_DIR" 2 | 160 | print_info "[${BASENAME}] Make directory $PLP_DIR" 2 |
161 | if [ $RERUN -eq 0 ]; | 161 | if [ $RERUN -eq 0 ]; |
162 | then | 162 | then |
163 | rm -r $RES_DIR > /dev/null 2>&1; | 163 | rm -r $RES_DIR > /dev/null 2>&1; |
164 | else | 164 | else |
165 | rm $RES_DIR/*.lock > /dev/null 2>&1 | 165 | rm $RES_DIR/*.lock > /dev/null 2>&1 |
166 | fi | 166 | fi |
167 | mkdir -p $RES_DIR > /dev/null 2>&1 | 167 | mkdir -p $RES_DIR > /dev/null 2>&1 |
168 | print_info "[${BASENAME}] Make directory $RES_DIR" 2 | 168 | print_info "[${BASENAME}] Make directory $RES_DIR" 2 |
169 | rm $LOGFILE $ERRORFILE > /dev/null 2>&1 | 169 | rm $LOGFILE $ERRORFILE > /dev/null 2>&1 |
170 | 170 | ||
171 | #--------------------# | 171 | #--------------------# |
172 | # Save configuration # | 172 | # Save configuration # |
173 | #--------------------# | 173 | #--------------------# |
174 | cp $FIRSTPASS_CONFIG_FILE $OUTPUT_DIR_BASENAME/FirstPass.cfg | 174 | cp $FIRSTPASS_CONFIG_FILE $OUTPUT_DIR_BASENAME/FirstPass.cfg |
175 | echo "FIRSTPASS_SCRIPT_PATH=$MAIN_SCRIPT_PATH" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg | 175 | echo "FIRSTPASS_SCRIPT_PATH=$MAIN_SCRIPT_PATH" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg |
176 | echo "WAV_FILE=$WAV_FILE" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg | 176 | echo "WAV_FILE=$WAV_FILE" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg |
177 | echo "BASENAME=$BASENAME" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg | 177 | echo "BASENAME=$BASENAME" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg |
178 | echo "OUTPUT_DIR=$OUTPUT_DIR" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg | 178 | echo "OUTPUT_DIR=$OUTPUT_DIR" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg |
179 | echo "OUTPUT_DIR_BASENAME=$OUTPUT_DIR_BASENAME" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg | 179 | echo "OUTPUT_DIR_BASENAME=$OUTPUT_DIR_BASENAME" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg |
180 | echo "PLP_FILE=$PLP_FILE" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg | 180 | echo "PLP_FILE=$PLP_FILE" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg |
181 | echo "PLP_DIR=$PLP_DIR" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg | 181 | echo "PLP_DIR=$PLP_DIR" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg |
182 | echo "PLP_LIST=$PLP_LIST" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg | 182 | echo "PLP_LIST=$PLP_LIST" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg |
183 | echo "SEG_FILE=$SEG_FILE" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg | 183 | echo "SEG_FILE=$SEG_FILE" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg |
184 | echo "LBL_FILE=$LBL_FILE" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg | 184 | echo "LBL_FILE=$LBL_FILE" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg |
185 | echo "RES_DIR=$RES_DIR" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg | 185 | echo "RES_DIR=$RES_DIR" >> $OUTPUT_DIR_BASENAME/FirstPass.cfg |
186 | print_info "[${BASENAME}] Save config in $OUTPUT_DIR_BASENAME/FirstPass.cfg" 1 | 186 | print_info "[${BASENAME}] Save config in $OUTPUT_DIR_BASENAME/FirstPass.cfg" 1 |
187 | 187 | ||
188 | #-------------------------# | 188 | #-------------------------# |
189 | # Check Audio File Format # | 189 | # Check Audio File Format # |
190 | #-------------------------# | 190 | #-------------------------# |
191 | error=0 | 191 | test=$(whereis avconv) |
192 | temp=$(avconv -i $WAV_FILE 2>&1 | grep "16000 Hz") | 192 | if [ "$test" == "avconv:" ] |
193 | if [ -z "$temp" ]; then error=1; fi | ||
194 | temp=$(avconv -i $WAV_FILE 2>&1 | grep "1 channels") | ||
195 | if [ -z "$temp" ]; then error=1; fi | ||
196 | temp=$(avconv -i $WAV_FILE 2>&1 | grep "s16") | ||
197 | if [ -z "$temp" ]; then error=1; fi | ||
198 | |||
199 | if [ $error -eq 1 ] | ||
200 | then | 193 | then |
201 | print_message $WARNING 2 "[${BASENAME}] $WAV_FILE is not a wav file at 16000 Hz, 1 channel, 16bits\nhave to convert" | 194 | print_message $ERROR 1 "[${BASENAME}] avconv is not installed" |
202 | print_message $INFO 3 "[${BASENAME}] avconv -i $WAV_FILE -threads 4 -vn -f wav -ac 1 -ar 16000 -ab 256000 $OUTPUT_DIR_BASENAME/$BASENAME.wav" | 195 | else |
203 | avconv -i $WAV_FILE -threads 4 -vn -f wav -ac 1 -ar 16000 -ab 256000 $OUTPUT_DIR_BASENAME/$BASENAME.wav | 196 | error=0 |
204 | WAV_FILE=$OUTPUT_DIR_BASENAME/$BASENAME.wav | 197 | temp=$(avconv -i $WAV_FILE 2>&1 | grep "16000 Hz") |
205 | FILENAME=$BASENAME.wav | 198 | if [ -z "$temp" ]; then error=1; fi |
206 | print_message $INFO 1 "[${BASENAME}] new wav file : $WAV_FILE" | 199 | temp=$(avconv -i $WAV_FILE 2>&1 | grep "1 channels") |
200 | if [ -z "$temp" ]; then error=1; fi | ||
201 | temp=$(avconv -i $WAV_FILE 2>&1 | grep "s16") | ||
202 | if [ -z "$temp" ]; then error=1; fi | ||
203 | |||
204 | if [ $error -eq 1 ] | ||
205 | then | ||
206 | print_message $WARNING 2 "[${BASENAME}] $WAV_FILE is not a wav file at 16000 Hz, 1 channel, 16bits\nhave to convert" | ||
207 | print_message $INFO 3 "[${BASENAME}] avconv -i $WAV_FILE -threads 4 -vn -f wav -ac 1 -ar 16000 -ab 256000 $OUTPUT_DIR_BASENAME/$BASENAME.wav" | ||
208 | avconv -i $WAV_FILE -threads 4 -vn -f wav -ac 1 -ar 16000 -ab 256000 $OUTPUT_DIR_BASENAME/$BASENAME.wav | ||
209 | WAV_FILE=$OUTPUT_DIR_BASENAME/$BASENAME.wav | ||
210 | FILENAME=$BASENAME.wav | ||
211 | print_message $INFO 1 "[${BASENAME}] new wav file : $WAV_FILE" | ||
212 | fi | ||
207 | fi | 213 | fi |
208 | 214 | ||
209 | #---------------# | 215 | #---------------# |
210 | # Get SRT file # | 216 | # Get SRT file # |
211 | #---------------# | 217 | #---------------# |
212 | if [ -s $(dirname $WAV_FILE)/$BASENAME.SRT ] | 218 | if [ -s $(dirname $WAV_FILE)/$BASENAME.SRT ] |
213 | then | 219 | then |
214 | cp $(dirname $WAV_FILE)/$BASENAME.SRT $OUTPUT_DIR_BASENAME/$BASENAME.SRT | 220 | cp $(dirname $WAV_FILE)/$BASENAME.SRT $OUTPUT_DIR_BASENAME/$BASENAME.SRT |
215 | print_info "[${BASENAME}] copy $BASENAME.SRT file into $OUTPUT_DIR_BASENAME" 3 | 221 | print_info "[${BASENAME}] copy $BASENAME.SRT file into $OUTPUT_DIR_BASENAME" 3 |
216 | fi | 222 | fi |
217 | 223 | ||
218 | #------------# | 224 | #------------# |
219 | # WAV -> PLP # | 225 | # WAV -> PLP # |
220 | #------------# | 226 | #------------# |
221 | print_info "[${BASENAME}] convert WAV -> PLP" 1 | 227 | print_info "[${BASENAME}] convert WAV -> PLP" 1 |
222 | echo $FILENAME > $OUTPUT_DIR_BASENAME/list.tmp | 228 | echo $FILENAME > $OUTPUT_DIR_BASENAME/list.tmp |
223 | print_info "[${BASENAME}] $BIN_PATH/lia_plp_mt.32 --lst $OUTPUT_DIR_BASENAME/list.tmp --input_dir $(dirname $WAV_FILE) --output_dir $OUTPUT_DIR_BASENAME --input_type WAV --output_type HTK --nb_coef 12 --cms" 3 | 229 | print_info "[${BASENAME}] $BIN_PATH/lia_plp_mt.32 --lst $OUTPUT_DIR_BASENAME/list.tmp --input_dir $(dirname $WAV_FILE) --output_dir $OUTPUT_DIR_BASENAME --input_type WAV --output_type HTK --nb_coef 12 --cms" 3 |
224 | 230 | ||
225 | $BIN_PATH/lia_plp_mt$ARCH --lst $OUTPUT_DIR_BASENAME/list.tmp --input_dir $(dirname $WAV_FILE) --output_dir $OUTPUT_DIR_BASENAME --input_type WAV --output_type HTK --nb_coef 12 --cms | 231 | $BIN_PATH/lia_plp_mt$ARCH --lst $OUTPUT_DIR_BASENAME/list.tmp --input_dir $(dirname $WAV_FILE) --output_dir $OUTPUT_DIR_BASENAME --input_type WAV --output_type HTK --nb_coef 12 --cms |
226 | 232 | ||
227 | if [ $CHECK -eq 1 ] | 233 | if [ $CHECK -eq 1 ] |
228 | then | 234 | then |
229 | check_first_pass_plp "$PLP_FILE" | 235 | check_first_pass_plp "$PLP_FILE" |
230 | if [ $? -eq 1 ] | 236 | if [ $? -eq 1 ] |
231 | then | 237 | then |
232 | print_log_file "$ERROFILE" "ERROR [$(date +'%d/%m/%y %H:%M:%S')] Creating PLP file : $PLP_FILE" | 238 | print_log_file "$ERROFILE" "ERROR [$(date +'%d/%m/%y %H:%M:%S')] Creating PLP file : $PLP_FILE" |
233 | print_error "[${BASENAME}] -> exit, Check $ERRORFILE file" | 239 | print_error "[${BASENAME}] -> exit, Check $ERRORFILE file" |
234 | exit 1 | 240 | exit 1 |
235 | fi | 241 | fi |
236 | fi | 242 | fi |
237 | 243 | ||
238 | rm $OUTPUT_DIR_BASENAME/list.tmp 2> /dev/null | 244 | rm $OUTPUT_DIR_BASENAME/list.tmp 2> /dev/null |
239 | 245 | ||
240 | #------------------------------# | 246 | #------------------------------# |
241 | # S/NS + SPEAKERS SEGMENTATION # | 247 | # S/NS + SPEAKERS SEGMENTATION # |
242 | #------------------------------# | 248 | #------------------------------# |
243 | print_info "[${BASENAME}] Launch speakers diarization" 1 | 249 | print_info "[${BASENAME}] Launch speakers diarization" 1 |
244 | # Calcul seg file | 250 | # Calcul seg file |
245 | print_info "[${BASENAME}] java -Xmx4096m -jar $BIN_PATH/LIUM_SpkDiarization-4.2.jar --fInputMask=${WAV_FILE} --sOutputMask=${SEG_FILE} $BASENAME" 3 | 251 | print_info "[${BASENAME}] java -Xmx4096m -jar $BIN_PATH/LIUM_SpkDiarization-4.2.jar --fInputMask=${WAV_FILE} --sOutputMask=${SEG_FILE} $BASENAME" 3 |
246 | #java -Xmx8000m -Xms2048 -jar $BIN_PATH/LIUM_SpkDiarization-4.2.jar --fInputMask=${WAV_FILE} --sOutputMask=${SEG_FILE} $BASENAME | 252 | #java -Xmx8000m -Xms2048 -jar $BIN_PATH/LIUM_SpkDiarization-4.2.jar --fInputMask=${WAV_FILE} --sOutputMask=${SEG_FILE} $BASENAME |
247 | java -Xmx4096m -jar $BIN_PATH/LIUM_SpkDiarization-4.2.jar --fInputMask=${WAV_FILE} --sOutputMask=${SEG_FILE} $BASENAME #–doCEClustering | 253 | java -Xmx4096m -jar $BIN_PATH/LIUM_SpkDiarization-4.2.jar --fInputMask=${WAV_FILE} --sOutputMask=${SEG_FILE} $BASENAME #–doCEClustering |
248 | 254 | ||
249 | if [ $CHECK -eq 1 ] && ( [ ! -e $SEG_FILE ] || [ -z $SEG_FILE ] ) | 255 | if [ $CHECK -eq 1 ] && ( [ ! -e $SEG_FILE ] || [ -z $SEG_FILE ] ) |
250 | then | 256 | then |
251 | print_log_file "$ERRORFILE" "ERROR [$(date +'%d/%m/%y %H:%M:%S')] Creating SEG file : $SEG_FILE" | 257 | print_log_file "$ERRORFILE" "ERROR [$(date +'%d/%m/%y %H:%M:%S')] Creating SEG file : $SEG_FILE" |
252 | print_error "[${BASENAME}] Check $ERRORFILE file" | 258 | print_error "[${BASENAME}] Check $ERRORFILE file" |
253 | exit 1 | 259 | exit 1 |
254 | fi | 260 | fi |
255 | 261 | ||
256 | 262 | ||
257 | # Create LBL file | 263 | # Create LBL file |
258 | print_info "Extract LBL file from SEG file" 1 | 264 | print_info "Extract LBL file from SEG file" 1 |
259 | 265 | ||
260 | cat $SEG_FILE | grep -v ";;" | cut -f3,4,5,8 -d" " | tr " " "#" | sort -k1 -n | tr "#" " " > $LBL_FILE | 266 | cat $SEG_FILE | grep -v ";;" | cut -f3,4,5,8 -d" " | tr " " "#" | sort -k1 -n | tr "#" " " > $LBL_FILE |
261 | 267 | ||
262 | if [ $CHECK -eq 1 ] && ( [ ! -e $LBL_FILE ] || [ -z $LBL_FILE ] ) | 268 | if [ $CHECK -eq 1 ] && ( [ ! -e $LBL_FILE ] || [ -z $LBL_FILE ] ) |
263 | then | 269 | then |
264 | print_log_file "$ERRORFILE" "ERROR [$(date +'%d/%m/%y %H:%M:%S')] Creating LBL file : $LBL_FILE" | 270 | print_log_file "$ERRORFILE" "ERROR [$(date +'%d/%m/%y %H:%M:%S')] Creating LBL file : $LBL_FILE" |
265 | print_error "[${BASENAME}] Check $ERRORFILE file" | 271 | print_error "[${BASENAME}] Check $ERRORFILE file" |
266 | exit 1 | 272 | exit 1 |
267 | fi | 273 | fi |
268 | 274 | ||
269 | 275 | ||
270 | #----------------------------------------------------# | 276 | #----------------------------------------------------# |
271 | # Cut global PLP file depending to LBL segmentations # | 277 | # Cut global PLP file depending to LBL segmentations # |
272 | #----------------------------------------------------# | 278 | #----------------------------------------------------# |
273 | print_info "[${BASENAME}] Cut PLP file depending to LBL segmentations" 1 | 279 | print_info "[${BASENAME}] Cut PLP file depending to LBL segmentations" 1 |
274 | print_info "[${BASENAME}] $BIN_PATH/gcep $PLP_FILE $LBL_FILE 500 $PLP_DIR -FSEG" 3 | 280 | print_info "[${BASENAME}] $BIN_PATH/gcep $PLP_FILE $LBL_FILE 500 $PLP_DIR -FSEG" 3 |
275 | 281 | ||
276 | $SPEERAL_TOOLS/gcep $PLP_FILE $LBL_FILE 500 $PLP_DIR -FSEG | 282 | $SPEERAL_TOOLS/gcep $PLP_FILE $LBL_FILE 500 $PLP_DIR -FSEG |
277 | 283 | ||
278 | if [ $CHECK -eq 1 ] | 284 | if [ $CHECK -eq 1 ] |
279 | then | 285 | then |
280 | check_first_pass_plps_lbl $PLP_DIR $LBL_FILE | 286 | check_first_pass_plps_lbl $PLP_DIR $LBL_FILE |
281 | if [ $? -eq 1 ] | 287 | if [ $? -eq 1 ] |
282 | then | 288 | then |
283 | print_log_file $ERRORFILE "ERROR [$(date +'%d/%m/%y %H:%M:%S')] $PLP wrong number of .plp files" | 289 | print_log_file $ERRORFILE "ERROR [$(date +'%d/%m/%y %H:%M:%S')] $PLP wrong number of .plp files" |
284 | print_error "[${BASENAME}] Check $ERRORFILE file" | 290 | print_error "[${BASENAME}] Check $ERRORFILE file" |
285 | exit 1 | 291 | exit 1 |
286 | fi | 292 | fi |
287 | fi | 293 | fi |
288 | 294 | ||
289 | # change plp files names | 295 | # change plp files names |
290 | cd $PLP_DIR; | 296 | cd $PLP_DIR; |
291 | rename -f s/_/#/g *plp | 297 | rename -f s/_/#/g *plp |
292 | rename -f s/#/_/ *plp | 298 | rename -f s/#/_/ *plp |
293 | cd $OLDPWD | 299 | cd $OLDPWD |
294 | 300 | ||
295 | #---------------------------------------------# | 301 | #---------------------------------------------# |
296 | # PLP files list depending to acoustic models # | 302 | # PLP files list depending to acoustic models # |
297 | #---------------------------------------------# | 303 | #---------------------------------------------# |
298 | print_info "[${BASENAME}] Create PLP list depending of the model" 1 | 304 | print_info "[${BASENAME}] Create PLP list depending of the model" 1 |
299 | # Create a list of plp files | 305 | # Create a list of plp files |
300 | find $PLP_DIR -type f -exec basename "{}" .plp \; | sort > $PLP_LIST | 306 | find $PLP_DIR -type f -exec basename "{}" .plp \; | sort > $PLP_LIST |
301 | 307 | ||
302 | rm $OUTPUT_DIR_BASENAME/plp_*.lst > /dev/null 2>&1 | 308 | rm $OUTPUT_DIR_BASENAME/plp_*.lst > /dev/null 2>&1 |
303 | for (( i=0; $i<${#MTAG[@]} ; i++ )) | 309 | for (( i=0; $i<${#MTAG[@]} ; i++ )) |
304 | do | 310 | do |
305 | a=`grep -e "${MTAG[$i]}" $OUTPUT_DIR_BASENAME/plp.lst` | 311 | a=`grep -e "${MTAG[$i]}" $OUTPUT_DIR_BASENAME/plp.lst` |
306 | if [ -n "$a" ]; then | 312 | if [ -n "$a" ]; then |
307 | print_info "[${BASENAME}] Creating $OUTPUT_DIR_BASENAME/plp_${MODS[$i]}.lst" 3 | 313 | print_info "[${BASENAME}] Creating $OUTPUT_DIR_BASENAME/plp_${MODS[$i]}.lst" 3 |
308 | grep -e "${MTAG[$i]}" $PLP_LIST | sort > $OUTPUT_DIR_BASENAME/plp_${MODS[$i]}.lst | 314 | grep -e "${MTAG[$i]}" $PLP_LIST | sort > $OUTPUT_DIR_BASENAME/plp_${MODS[$i]}.lst |
309 | fi | 315 | fi |
310 | done | 316 | done |
311 | 317 | ||
312 | #-----------------------# | 318 | #-----------------------# |
313 | # First Pass (DECODING) # | 319 | # First Pass (DECODING) # |
314 | #-----------------------# | 320 | #-----------------------# |
315 | # | 321 | # |
316 | # For all AM do decoding | 322 | # For all AM do decoding |
317 | # if Check error -> iter on undone decoding (max 1 times) | 323 | # if Check error -> iter on undone decoding (max 1 times) |
318 | # | 324 | # |
319 | print_info "[${BASENAME}] Launch decoding" 1 | 325 | print_info "[${BASENAME}] Launch decoding" 1 |
320 | for (( i=0; $i<${#MTAG[@]} ; i++ )) | 326 | for (( i=0; $i<${#MTAG[@]} ; i++ )) |
321 | do | 327 | do |
322 | redo=1; # nb of try if not all segs is decoded | 328 | redo=1; # nb of try if not all segs is decoded |
323 | if [ -e $OUTPUT_DIR_BASENAME/plp_${MODS[$i]}.lst ] | 329 | if [ -e $OUTPUT_DIR_BASENAME/plp_${MODS[$i]}.lst ] |
324 | then | 330 | then |
325 | todo=$OUTPUT_DIR_BASENAME/plp_${MODS[$i]}.lst | 331 | todo=$OUTPUT_DIR_BASENAME/plp_${MODS[$i]}.lst |
326 | while [ $redo -gt 0 ]; do | 332 | while [ $redo -gt 0 ]; do |
327 | rm $RES_DIR/*.lock > /dev/null 2>&1 | 333 | rm $RES_DIR/*.lock > /dev/null 2>&1 |
328 | print_info "[${BASENAME}] $SPEERAL_BIN $todo $RES_DIR ${SPEERAL_CFG[$i]} -r $PLP_DIR -m $SPEERAL_AM/${MODS[$i]}.hmm -c $SPEERAL_AM/${MODS[$i]}.cls $FORKS --lock" 3 | 334 | print_info "[${BASENAME}] $SPEERAL_BIN $todo $RES_DIR ${SPEERAL_CFG[$i]} -r $PLP_DIR -m $SPEERAL_AM/${MODS[$i]}.hmm -c $SPEERAL_AM/${MODS[$i]}.cls $FORKS --lock" 3 |
329 | # Run speeral | 335 | # Run speeral |
330 | $SPEERAL_BIN ${todo} $RES_DIR ${SPEERAL_CFG[$i]} -r $PLP_DIR -m $SPEERAL_AM/${MODS[$i]}.hmm -c $SPEERAL_AM/${MODS[$i]}.cls $FORKS --lock | 336 | $SPEERAL_BIN ${todo} $RES_DIR ${SPEERAL_CFG[$i]} -r $PLP_DIR -m $SPEERAL_AM/${MODS[$i]}.hmm -c $SPEERAL_AM/${MODS[$i]}.cls $FORKS --lock |
331 | 337 | ||
332 | # Check if error | 338 | # Check if error |
333 | if [ $CHECK -eq 1 ] | 339 | if [ $CHECK -eq 1 ] |
334 | then | 340 | then |
335 | check_first_pass_output_speeral "${OUTPUT_DIR_BASENAME}/plp_${MODS[$i]}.lst" "$RES_DIR" | 341 | check_first_pass_output_speeral "${OUTPUT_DIR_BASENAME}/plp_${MODS[$i]}.lst" "$RES_DIR" |
336 | # if error | 342 | # if error |
337 | if [ $? -eq 1 ] | 343 | if [ $? -eq 1 ] |
338 | then | 344 | then |
339 | # rerun | 345 | # rerun |
340 | redo=$(($redo - 1)); | 346 | redo=$(($redo - 1)); |
341 | print_warn "[${BASENAME}] Speeral output error : check $LOGFILE" 2 | 347 | print_warn "[${BASENAME}] Speeral output error : check $LOGFILE" 2 |
342 | print_log_file $LOGFILE "WARN : Speeral number of output ERROR ${OUTPUT_DIR_BASENAME}/plp_${MODS[$i]}.lst" | 348 | print_log_file $LOGFILE "WARN : Speeral number of output ERROR ${OUTPUT_DIR_BASENAME}/plp_${MODS[$i]}.lst" |
343 | # new plp list | 349 | # new plp list |
344 | # list .seg done and compare to list of seg to do | 350 | # list .seg done and compare to list of seg to do |
345 | ls $RES_DIR/*.seg | grep -e "${MTAG[$i]}" | sed -e "s|$RES_DIR\/||g" | sed -e 's/\.seg//' | sort > ${OUTPUT_DIR_BASENAME}/.tmp | 351 | ls $RES_DIR/*.seg | grep -e "${MTAG[$i]}" | sed -e "s|$RES_DIR\/||g" | sed -e 's/\.seg//' | sort > ${OUTPUT_DIR_BASENAME}/.tmp |
346 | diff ${OUTPUT_DIR_BASENAME}/plp_${MODS[$i]}.lst ${OUTPUT_DIR_BASENAME}/.tmp | grep -e "^< " | sed -e "s/< //" > ${OUTPUT_DIR_BASENAME}/todo.lst | 352 | diff ${OUTPUT_DIR_BASENAME}/plp_${MODS[$i]}.lst ${OUTPUT_DIR_BASENAME}/.tmp | grep -e "^< " | sed -e "s/< //" > ${OUTPUT_DIR_BASENAME}/todo.lst |
347 | rm ${OUTPUT_DIR_BASENAME}/.tmp | 353 | rm ${OUTPUT_DIR_BASENAME}/.tmp |
348 | # log seg to do | 354 | # log seg to do |
349 | print_log_file $LOGFILE "Segs not done [" | 355 | print_log_file $LOGFILE "Segs not done [" |
350 | cat ${OUTPUT_DIR_BASENAME}/todo.lst >> $LOGFILE | 356 | cat ${OUTPUT_DIR_BASENAME}/todo.lst >> $LOGFILE |
351 | todo=${OUTPUT_DIR_BASENAME}/todo.lst | 357 | todo=${OUTPUT_DIR_BASENAME}/todo.lst |
352 | print_log_file $LOGFILE "] [$(date +'%d/%m/%y %H:%M:%S')]" | 358 | print_log_file $LOGFILE "] [$(date +'%d/%m/%y %H:%M:%S')]" |
353 | print_warn "[${BASENAME}] Try $redo" 3 | 359 | print_warn "[${BASENAME}] Try $redo" 3 |
354 | else | 360 | else |
355 | redo=-1 | 361 | redo=-1 |
356 | fi | 362 | fi |
357 | else | 363 | else |
358 | redo=-1 | 364 | redo=-1 |
359 | fi | 365 | fi |
360 | done | 366 | done |
361 | rm ${OUTPUT_DIR_BASENAME}/todo.lst > /dev/null 2>&1 | 367 | rm ${OUTPUT_DIR_BASENAME}/todo.lst > /dev/null 2>&1 |
362 | #rm $OUTPUT_DIR_BASENAME/plp_${MODS[$i]}.lst | 368 | #rm $OUTPUT_DIR_BASENAME/plp_${MODS[$i]}.lst |
363 | rm $RES_DIR/*.lock > /dev/null 2>&1 | 369 | rm $RES_DIR/*.lock > /dev/null 2>&1 |
364 | fi | 370 | fi |
365 | done | 371 | done |
366 | 372 | ||
367 | ## Check missing seg and log it | 373 | ## Check missing seg and log it |
368 | if [ "$CHECK" -eq 1 ] | 374 | if [ "$CHECK" -eq 1 ] |
369 | then | 375 | then |
370 | ls $RES_DIR/*.seg | sed -e "s|$RES_DIR\/||g" | sed -e 's/\.seg//' | sort > ${OUTPUT_DIR_BASENAME}/.tmp | 376 | ls $RES_DIR/*.seg | sed -e "s|$RES_DIR\/||g" | sed -e 's/\.seg//' | sort > ${OUTPUT_DIR_BASENAME}/.tmp |
371 | todo=$(cat ${PLP_LIST} 2> /dev/null | wc -l) | 377 | todo=$(cat ${PLP_LIST} 2> /dev/null | wc -l) |
372 | if [ "$todo" -eq 0 ]; then todo=1;fi | 378 | if [ "$todo" -eq 0 ]; then todo=1;fi |
373 | notdone=$(($todo - $(cat ${OUTPUT_DIR_BASENAME}/.tmp | wc -l))) | 379 | notdone=$(($todo - $(cat ${OUTPUT_DIR_BASENAME}/.tmp | wc -l))) |
374 | pourcentage=$((($notdone*100)/$todo)) | 380 | pourcentage=$((($notdone*100)/$todo)) |
375 | 381 | ||
376 | if [ "$notdone" -ne 0 ] | 382 | if [ "$notdone" -ne 0 ] |
377 | then | 383 | then |
378 | print_error "[${BASENAME}] Check ${ERRORFILE}" | 384 | print_error "[${BASENAME}] Check ${ERRORFILE}" |
379 | print_log_file "${ERRORFILE}" "ERROR : Segs not done [" | 385 | print_log_file "${ERRORFILE}" "ERROR : Segs not done [" |
380 | diff ${PLP_LIST} ${OUTPUT_DIR_BASENAME}/.tmp | grep -e "^< " | sed -e "s/< //" >> ${ERRORFILE} | 386 | diff ${PLP_LIST} ${OUTPUT_DIR_BASENAME}/.tmp | grep -e "^< " | sed -e "s/< //" >> ${ERRORFILE} |
381 | print_log_file "${ERRORFILE}" "] $pourcentage% $BASENAME" | 387 | print_log_file "${ERRORFILE}" "] $pourcentage% $BASENAME" |
382 | else | 388 | else |
383 | print_log_file "$LOGFILE" "P1 OK ${BASENAME} | $(date +'%d/%m/%y %H:%M:%S')" | 389 | print_log_file "$LOGFILE" "P1 OK ${BASENAME} | $(date +'%d/%m/%y %H:%M:%S')" |
384 | fi | 390 | fi |
385 | rm ${OUTPUT_DIR_BASENAME}/.tmp | 391 | rm ${OUTPUT_DIR_BASENAME}/.tmp |
386 | fi | 392 | fi |
387 | 393 | ||
388 | #---------------# | 394 | #---------------# |
389 | # Convert res # | 395 | # Convert res # |
390 | #---------------# | 396 | #---------------# |
391 | print_info "[${BASENAME}] Convert .res into .ctm" 1 | 397 | print_info "[${BASENAME}] Convert .res into .ctm" 1 |
392 | # .res => .ctm | 398 | # .res => .ctm |
393 | $SCRIPT_PATH/res2out.pl --dir $RES_DIR --format CTM --ignore $RULES/asupp --out $OUTPUT_DIR_BASENAME/$BASENAME.1pass.ctm | 399 | $SCRIPT_PATH/res2out.pl --dir $RES_DIR --format CTM --ignore $RULES/asupp --out $OUTPUT_DIR_BASENAME/$BASENAME.1pass.ctm |
394 | print_info "[${BASENAME}] Convert .res into .trs" 1 | 400 | print_info "[${BASENAME}] Convert .res into .trs" 1 |
395 | # .res => .trs | 401 | # .res => .trs |
396 | echo -e "name $AUTHOR\nfileName $BASENAME\nfileExt wav\nsegFile $OUTPUT_DIR_BASENAME/$BASENAME.seg" > $OUTPUT_DIR_BASENAME/$BASENAME.trs_cfg | 402 | echo -e "name $AUTHOR\nfileName $BASENAME\nfileExt wav\nsegFile $OUTPUT_DIR_BASENAME/$BASENAME.seg" > $OUTPUT_DIR_BASENAME/$BASENAME.trs_cfg |
397 | $SCRIPT_PATH/res2out.pl --dir $RES_DIR --format TRS --ignore $RULES/asupp --out $OUTPUT_DIR_BASENAME/$BASENAME.1pass.trs --trs_config $OUTPUT_DIR_BASENAME/$BASENAME.trs_cfg | 403 | $SCRIPT_PATH/res2out.pl --dir $RES_DIR --format TRS --ignore $RULES/asupp --out $OUTPUT_DIR_BASENAME/$BASENAME.1pass.trs --trs_config $OUTPUT_DIR_BASENAME/$BASENAME.trs_cfg |
398 | rm $OUTPUT_DIR_BASENAME/$BASENAME.trs_cfg 2> /dev/null | 404 | rm $OUTPUT_DIR_BASENAME/$BASENAME.trs_cfg 2> /dev/null |
399 | print_info "[${BASENAME}] Convert .res into .txt" 1 | 405 | print_info "[${BASENAME}] Convert .res into .txt" 1 |