-
Notifications
You must be signed in to change notification settings - Fork 1
/
pocketsphinx_sequential_decoder_batch.sh
76 lines (59 loc) · 2.16 KB
/
pocketsphinx_sequential_decoder_batch.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
#!/usr/bin/env bash
# sudo apt install pocketsphinx pocketsphinx-en-us
# pocketsphinx_continuous -inmic yes
if [ $# -ne 2 ]; then
echo "usage ${0} <configuration file> <wave dir>";
exit -1;
fi
# read cfg file
source ${1}
printf "hmm:%s\n" ${hmm}
printf "lm:%s\n" ${lm}
printf "dict:%s\n" ${dict}
in_dir=${2}
wav_dir=$(echo ${in_dir} | sed "s/\/storage\/recordings\///" | sed "s/\//_/g")
wav_dir=~/waves/${wav_dir}
printf "in_dir: %s\n" ${in_dir}
printf "wav_dir: %s\n" ${wav_dir}
read -p "Convert to wav? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
##################################################
mkdir -p ${wav_dir}
for f in ${in_dir}/.ts; do file_name=$(basename ${f}); ffmpeg -i ${f} -ar 16000 -ac 1 ${wav_dir}/${file_name}.wav; done
printf "%s\n" "conversion to wave format is done"
##################################################
fi
printf "%s\n" "make fileids file (the control file)"
ls -d ${wav_dir}/* | sed -n 's/\.wav//p' > ${wav_dir}/clt.fileid
printf "%s\n" "making fileids file is done"
# a handy SECONDS builtin variable that tracks the number of seconds that have passed since the shell was started.
SECONDS=0
pocketsphinx_batch \
-adcin yes \
-cepdir ${wav_dir} \
-cepext .wav \
-ctl ${wav_dir}/clt.fileid \
-lm ${lm} \
-dict ${dict} \
-hmm ${hmm} \
-hyp ${in_dir}_batch.hyp
# -logfn ${log}
echo "done"
decode_duration=$SECONDS
echo "total decode time: $(($decode_duration / 60)) minutes and $(($decode_duration % 60)) seconds."
total_duration=0.0
for file in ${in_dir}/*.wav
do
duration=$(sox --i -D "$file")
total_duration=$(python -c "print($total_duration+$duration)")
s_rate=$(sox --i -r "$file")
channels=$(sox --i -c "$file")
filename=$(basename "$file")
#printf "duration: %s sample rate: %s channels: %d file:%s\n" "$duration" "$s_rate" "$channels" "$filename"
done
printf "total wav duration in minutes: %.2f minutes\n" $(python -c "print($total_duration/60)")
printf "total wav duration in hours: %.2f minutes\n" $(python -c "print($total_duration/60/60)")
decode_duration=$SECONDS
echo "total decode time: $(($decode_duration / 60)) minutes and $(($decode_duration % 60)) seconds."