-
Notifications
You must be signed in to change notification settings - Fork 6
/
transcribe_folder.sh
executable file
·81 lines (64 loc) · 1.57 KB
/
transcribe_folder.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
#!/usr/bin/env bash
cmd(){ echo `basename $0`; }
usage(){
echo "\
`cmd` [OPTION...]
-i, --input; Input wav folder
-o, --output; Output transcription folder
-p, --port; ASR port [default: 50051]
-h, --host; ASR host [default: localhost]
-j, --njobs; Number of cores for parallel execution [default: `grep -c ^processor /proc/cpuinfo`]
" | column -t -s ";"
}
print_usage(){
usage;
exit 2;
}
abnormal_exit(){
usage;
exit 1;
}
SHORT_OPTS=i:o:p:h:j:
LONG_OPTS=input:,output:,port:,host:,njobs:
OPTIONS=`getopt -o ${SHORT_OPTS} --long ${LONG_OPTS} -n "transcribe_folder.sh" -- "$@"`
if [ $? != 0 ] ; then abnormal_exit; fi
INPUT_FOLDER=
OUTPUT_FOLDER=
PORT=50051
HOST=localhost
NJOBS=`grep -c ^processor /proc/cpuinfo`
while true; do
case "$1" in
-i | --input ) INPUT_FOLDER="$2"; shift 2 ;;
-o | --output ) OUTPUT_FOLDER="$2"; shift 2 ;;
-p | --port ) PORT="$2"; shift 2 ;;
-h | --host ) HOST="$2"; shift 2 ;;
-j | --njobs ) NJOBS="$2"; shift 2 ;;
-- ) shift; break ;;
* ) break ;;
esac
done
echo $INPUT_FOLDER
echo $OUTPUT_FOLDER
echo $PORT
echo $HOST
echo $NJOBS
if [ -z "$INPUT_FOLDER" ]
then
abnormal_exit
fi
if [ -z "$OUTPUT_FOLDER" ]
then
abnormal_exit
fi
transcribe_wav() {
wav=$1
host=$2
port=$3
outf=$4
base_wav=${wav%.*}
base_wav=${base_wav##*/}
kaldigrpc-transcribe --host $host --port $port --streaming $wav > ${outf}/${base_wav}.txt
}
export -f transcribe_wav
parallel -j${NJOBS} transcribe_wav {} $HOST $PORT $OUTPUT_FOLDER ::: $(find ${INPUT_FOLDER} -name "*.wav")