-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrun_beamformit.sh
executable file
·87 lines (73 loc) · 2.26 KB
/
run_beamformit.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# Adapted from ``egs/chime5/s5/local/run_beamformit.sh``
. ./cmd.sh
. ./path.sh
export KALDI_ROOT=`pwd`/../../..
[ -f $KALDI_ROOT/tools/env.sh ] && . $KALDI_ROOT/tools/env.sh
if [ -z BEAMFORMIT ]; then
echo "BEAMFORMIT is not defined. Please run ``tools/install_kaldi.sh``"
echo "and verify that BeamFormit installed successfully"
exit 1
fi
# Config:
cmd=run.pl
bmf="1 2 3 4"
arrays="u01 u02 u03 u04 u05 u06"
sdir=$1
odir=$2
expdir=exp/enhan/`echo $sdir | awk -F '/' '{print $NF}'`_`echo $bmf | tr ' ' '_'`
# Set bash to 'debug' mode, it will exit on :
# -e 'error', -u 'undefined variable', -o ... 'error in pipeline', -x 'print commands',
set -e
set -u
set -o pipefail
mkdir -p $odir
mkdir -p $expdir/log
echo "Will use the following channels: $bmf"
# number of channels
numch=`echo $bmf | tr ' ' '\n' | wc -l`
echo "the number of channels: $numch"
# wavfiles.list can be used as the name of the output files
output_wavfiles=$expdir/wavfiles.list
if [ -f $output_wavfiles ]; then
rm $output_wavfiles
fi
for array in $arrays; do
find -L ${sdir} | grep -i ${array} | awk -F "/" '{print $NF}' | sed -e "s/\.CH.\.wav//" | sort | uniq >> $output_wavfiles
done
sort -o $output_wavfiles $output_wavfiles
# this is an input file list of the microphones
# format: 1st_wav 2nd_wav ... nth_wav
input_arrays=$expdir/channels_$numch
for x in `cat $output_wavfiles`; do
echo -n "$x"
for ch in $bmf; do
echo -n " $x.CH$ch.wav"
done
echo ""
done > $input_arrays
# split the list for parallel processing
# number of jobs are set by the number of WAV files
nj=`wc -l $expdir/wavfiles.list | awk '{print $1}'`
split_wavfiles=""
for n in `seq $nj`; do
split_wavfiles="$split_wavfiles $output_wavfiles.$n"
done
utils/split_scp.pl $output_wavfiles $split_wavfiles || exit 1;
echo -e "Beamforming\n"
# making a shell script for each job
for n in `seq $nj`; do
cat << EOF > $expdir/log/beamform.$n.sh
while read line; do
$BEAMFORMIT/BeamformIt -s \$line -c $input_arrays \
--config_file `pwd`/conf/beamformit.cfg \
--source_dir $sdir \
--result_dir $odir
done < $output_wavfiles.$n
EOF
done
chmod a+x $expdir/log/beamform.*.sh
$cmd JOB=1:$nj $expdir/log/beamform.JOB.log \
$expdir/log/beamform.JOB.sh
rm $odir/*.{del,del2,info,weat}
echo "`basename $0` Done."