-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathspeech2per.sh
executable file
·93 lines (65 loc) · 2.59 KB
/
speech2per.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
88
89
90
91
92
#!/bin/bash
# (based on speech2text.sh)
#
# Given a plain text file containing words, and an input audio,
# produce a phonetic transcription and compute phone error rate
# of the audio as it relates to the text file as "gold standard"
BASEDIR=$(dirname $0)
echo "$0 $@" # Print the command line for logging
. path.sh
txt=""
trs=""
ctm=""
sbv=""
srt=""
clean=false
nnet2_online=false
. $BASEDIR/utils/parse_options.sh || exit 1;
if [ $# -ne 2 ]; then
echo "Usage: speech2per <text> <audiofile>"
exit 1;
fi
mkdir -p $BASEDIR/build/audio/base build/output
stmfilename=$(basename "$1")
stmbasename="${stmfilename%.*}"
hypfilename=$(basename "$2")
hypbasename="${hypfilename%.*}"
cp -u $2 $BASEDIR/src-audio
# VERY IMPORTANT: clean up first
rm -rf build/output/${basename}.*
rm -rf build/trans/${basename}
rm -rf build/audio/*/${basename}
rm -rf build/diarization/${basename}
nnet2_online_arg="DO_NNET2_ONLINE=no"
(cd $BASEDIR; make build/output/${hypbasename%.*}.{txt,trs,ctm,sbv,srt,labels} || exit 1; if $clean ; then make .${hypbasename%.*}.clean; fi)
cd $BASEDIR
# if not exist, create gold phonetic STM
local/words2phon.sh $1 | paste -s -d ' ' > build/output/${stmbasename}.phon.stm
# put phonetic transcription in output folder (not part of Makefile)
python local/flatphonemes.py build/trans/${hypbasename}/eesen/decode/phones.1.txt > build/trans/${hypbasename}/eesen/decode/${hypbasename}.hyp
# score phonetic transcription against phonetic STM
compute-wer --text ark:build/output/${stmbasename}.phon.stm ark:build/trans/${hypbasename}/eesen/decode/${hypbasename}.hyp build/output/${hypbasename}.dtl > build/output/${hypbasename}.phon.sys
# fix 'WER' to read 'PER" since these are phones
sed -i 's/WER/PER/g' build/output/${hypbasename}.phon.sys
echo ${hypbasename} `grep PER build/output/${hypbasename}.phon.sys` >> build/output/speech2per.log
rm $BASEDIR/src-audio/$hypfilename
echo "Finished transcribing, result is in files $BASEDIR/build/output/${hypbasename%.*}.{txt,trs,ctm,sbv,srt,labels,sys,dtl}"
if [ ! -z $txt ]; then
cp $BASEDIR/build/output/${basename%.*}.txt $txt
echo $txt
fi
if [ ! -z $trs ]; then
cp $BASEDIR/build/output/${basename%.*}.trs $trs
fi
if [ ! -z $ctm ]; then
cp $BASEDIR/build/output/${basename%.*}.ctm $ctm
fi
if [ ! -z $sbv ]; then
cp $BASEDIR/build/output/${basename%.*}.sbv $sbv
fi
if [ ! -z $srt ]; then
cp $BASEDIR/build/output/${basename%.*}.srt $srt
fi
if [ ! -z $labels ]; then
cp $BASEDIR/build/output/${basename%.*}.labels $labels
fi