-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.sh
executable file
·192 lines (128 loc) · 4.9 KB
/
test.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/bash
# Copyright 2021 Matt Haynes <[email protected]>
# 2021 Misa Ogura <[email protected]>
# Apache 2.0
#
# Simple script to test the repo confirms to various coding standards and the
# the VAD and segmentation scripts function as expected.
set -eo pipefail
# -----------------------------------------------------------------------------
# Check .py files for coding standards
echo "Checking .py files look good"
for py_file in recipe/local/*.py; do
flake8 "$py_file"
if ! grep -q "# Copyright" "$py_file"; then
echo "No Copyright notice in $py_file"
exit 1
fi
if ! grep -q "# Apache 2.0" "$py_file"; then
echo "No Apache 2.0 license notice in $py_file"
exit 1
fi
if ! grep -q "#!/usr/bin/env python3" "$py_file"; then
echo "No shebang in $py_file"
exit 1
fi
done
# -----------------------------------------------------------------------------
# Check .sh files for coding standards
echo "Checking .sh files look good"
for sh_file in test.sh recipe/*.sh recipe/local/*.sh; do
if ! grep -q "# Copyright" "$sh_file"; then
echo "No Copyright notice in $sh_file"
exit 1
fi
if ! grep -q "# Apache 2.0" "$sh_file"; then
echo "No Apache 2.0 license notice in $sh_file"
exit 1
fi
if ! grep -q "#!/bin/bash" "$sh_file"; then
echo "No shebang in $sh_file"
exit 1
fi
done
# -----------------------------------------------------------------------------
# Run segmentation and check if all works
cd recipe
tmp_dir=$(mktemp -d)
# --help
echo "Checking run-segmentation.sh --help"
./run-segmentation.sh --help 2>&1 \
| grep -q "usage: run-segmentation.sh"
# --no-vad
echo "Checking run-segmentation.sh --no-vad"
./run-segmentation.sh --no-vad true ../test.wav ../test.stm "$tmp_dir" 2>&1 \
| grep "INFO 5 Skipping" > /dev/null
./run-segmentation.sh --no-vad true ../test.wav ../test.stm "$tmp_dir" 2>&1 \
| grep "INFO 8 Skipping" > /dev/null
ls $tmp_dir/diarize.rttm $tmp_dir/diarize.stm > /dev/null
rm -rf $tmp_dir
# --vad-method individual
echo "Checking run-segmentation.sh --vad-method individual"
./run-segmentation.sh --vad-method individual \
../test.wav ../test.stm "$tmp_dir" 2>&1 \
| grep "INFO 5 Filtering unvoiced xvectors" \
> /dev/null
./run-segmentation.sh --vad-method individual \
../test.wav ../test.stm "$tmp_dir" 2>&1 \
| grep "INFO 8 Skipping" > /dev/null
ls $tmp_dir/diarize.rttm $tmp_dir/diarize.stm > /dev/null
rm -rf $tmp_dir
# --vad-method segment
echo "Checking run-segmentation.sh --vad-method segment"
./run-segmentation.sh --vad-method segment \
../test.wav ../test.stm "$tmp_dir" 2>&1 \
| grep "INFO 8 Filtering unvoiced clusters" \
> /dev/null
./run-segmentation.sh --vad-method segment \
../test.wav ../test.stm "$tmp_dir" 2>&1 \
| grep "INFO 5 Skipping" > /dev/null
ls $tmp_dir/diarize.rttm $tmp_dir/diarize.stm > /dev/null
rm -rf $tmp_dir
# -----------------------------------------------------------------------------
# Ensure xvector_utils.py commands work as expected
mkdir -p $tmp_dir
echo "test /wrk/test.wav" > $tmp_dir/test.scp
# make-xvectors
echo "Checking local/xvector_utils.py make-xvectors"
python3 local/xvector_utils.py make-xvectors \
$tmp_dir/test.scp /wrk/test.stm $tmp_dir/test.xvectors.ark 2>&1 \
| grep "INFO 4 X-vector extraction completed" > /dev/null
if [ ! -s "$tmp_dir/test.xvectors.ark" ]; then
echo "X-vectors empty"
exit 1
fi
copy-vector ark:$tmp_dir/test.xvectors.ark \
ark,t:$tmp_dir/test.xvectors.ark.txt >/dev/null 2>&1
num_xvectors=$( wc -l $tmp_dir/test.xvectors.ark.txt | awk '{print $1}' )
if (( "$num_xvectors" != 38 )); then
echo "The number of x-vectors extracted doesn't match the expected"
exit 1
fi
# visualize
echo "Checking local/xvector_utils.py visualize"
python3 local/xvector_utils.py visualize \
/wrk/test.stm $tmp_dir/test.xvectors.ark $tmp_dir/viz 2>&1 \
| grep "INFO:xvector_utils.main:Saving the dataset" > /dev/null
if [ ! -s "$tmp_dir/viz/visualization.png" ]; then
echo "Visualization empty"
exit 1
fi
# visualize
echo "Checking local/xvector_utils.py train"
python3 local/xvector_utils.py train \
/wrk/test.stm $tmp_dir/test.xvectors.ark $tmp_dir/model.pkl 2>&1 \
| grep "INFO:xvector_utils.main:Saving the model" > /dev/null
if [ ! -s "$tmp_dir/model.pkl" ]; then
echo "Model empty"
exit 1
fi
echo "Checking local/xvector_utils.py evaluate"
python3 local/xvector_utils.py evaluate \
/wrk/recipe/data/bbc-vad-eval/reference.stm \
/wrk/recipe/data/bbc-vad-eval/xvectors.ark \
/wrk/recipe/model/xvector-classifier.pkl 2>&1 \
| grep "Accuracy: 0.974" > /dev/null
rm -rf $tmp_dir
cd ..
echo "All checks passed"