14
14
. ./path.sh
15
15
16
16
if [ $# != 1 ]; then
17
- echo " Usage: $0 <datadir>"
18
- echo " e.g.:"
19
- echo " $0 data/train"
20
- echo " This script prints the frame-shift (e.g. 0.01) to the standard out."
21
- echo " If <datadir> does not contain utt2dur, this script may call utils/data/get_utt2dur.sh,"
22
- echo " which will require write permission to <datadir>"
17
+ cat >&2 << EOF
18
+ Usage: frame_shift=\$ ($0 <datadir>)
19
+ e.g.: frame_shift=\$ ($0 data/train)
20
+
21
+ This script prints the frame-shift in seconds (e.g. 0.01) to the standard out.
22
+ Its output is intended to be captured in a shell variable.
23
+
24
+ If <datadir> does not contain the file utt2dur, this script may invoke
25
+ utils/data/get_utt2dur.sh, which will require write permission to <datadir>.
26
+ EOF
23
27
exit 1
24
28
fi
25
29
26
30
export LC_ALL=C
27
31
28
32
dir=$1
29
33
34
+ if [[ -s $dir /frame_shift ]]; then
35
+ cat $dir /frame_shift
36
+ exit
37
+ fi
38
+
39
+ if [ ! -f $dir /feats.scp ]; then
40
+ echo " $0 : $dir /feats.scp does not exist" 1>&2
41
+ exit 1
42
+ fi
30
43
31
44
if [ ! -s $dir /utt2dur ]; then
32
45
if [ ! -e $dir /wav.scp ] && [ ! -s $dir /segments ]; then
@@ -35,37 +48,27 @@ if [ ! -s $dir/utt2dur ]; then
35
48
exit 0
36
49
fi
37
50
echo " $0 : $dir /utt2dur does not exist: creating it" 1>&2
38
- utils/data/get_utt2dur.sh $dir 1>&2
51
+ utils/data/get_utt2dur.sh 1>&2 $dir || exit 1
39
52
fi
40
53
41
- if [ ! -s $dir /frame_shift ]; then
42
- if [ ! -f $dir /feats.scp ]; then
43
- echo " $0 : $dir /feats.scp does not exist" 1>&2
44
- exit 1
45
- fi
46
-
47
- temp=$( mktemp /tmp/tmp.XXXX)
54
+ temp=$( mktemp /tmp/tmp.XXXX) || exit 1
48
55
49
- feat-to-len " scp:head -n 10 $dir /feats.scp|" ark,t:- > $temp
56
+ feat-to-len --print-args=false " scp:head -n 10 $dir /feats.scp|" ark,t:- > $temp
50
57
51
- if [ -z $temp ]; then
52
- echo " $0 : error running feat-to-len" 1>&2
53
- exit 1
54
- fi
55
-
56
- frame_shift=$( head -n 10 $dir /utt2dur | paste - $temp | \
57
- awk ' { dur += $2; frames += $4; } END { shift = dur / frames; if (shift > 0.01 && shift < 0.0102) shift = 0.01; print shift; }' ) || exit 1;
58
-
59
- echo $frame_shift > $dir /frame_shift
58
+ if [[ ! -s $temp ]]; then
60
59
rm $temp
61
- fi
62
-
63
- frame_shift=$( cat $dir /frame_shift)
64
- if [ -z " $frame_shift " ]; then
65
- echo " $0 : Could not read get frame shift from directory $dir " 1>&2
60
+ echo " $0 : error running feat-to-len" 1>&2
66
61
exit 1
67
62
fi
68
63
69
- echo $frame_shift
64
+ frame_shift=$( head -n 10 $dir /utt2dur | paste - $temp | awk '
65
+ { dur += $2; frames += $4; }
66
+ END { shift = dur / frames;
67
+ if (shift > 0.01 && shift < 0.0102) shift = 0.01;
68
+ print shift; }' ) || exit 1;
70
69
70
+ rm $temp
71
+
72
+ echo $frame_shift > $dir /frame_shift
73
+ echo $frame_shift
71
74
exit 0
0 commit comments