Skip to content

Commit 9fec747

Browse files
Add train_speech_commands.sh
This is a script runs the the training process for a given word in the speech commands dataset
1 parent 735c4f9 commit 9fec747

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

train_speech_commands.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env bash
2+
3+
if [ "$1" != "--clean" ] && [ "$1" != "" ]; then
4+
echo "Usage: $0 [--clean]"
5+
exit 1
6+
fi
7+
8+
cd "$(dirname "$0")" # Cd to script location
9+
set -eE
10+
11+
dataset_url="http://download.tensorflow.org/data/speech_commands_v0.02.tar.gz"
12+
dataset_md5="6b74f3901214cb2c2934e98196829835"
13+
dataset_filename="speech_commands_v0.02.tar.gz"
14+
dataset_folder="speech_commands"
15+
demo_class="marvin"
16+
17+
if [ "$1" = "--clean" ]; then
18+
echo "Cleaning old data..."
19+
rm "data/$dataset_filename"
20+
rm -r "data/$dataset_folder"
21+
fi
22+
23+
echo "Downloading speech commands dataset..."
24+
cur_md5=$(md5sum "data/$dataset_filename" | awk '{print $1}')
25+
if [ "$cur_md5" != "$dataset_md5" ] || [ ! -d "data/$dataset_folder" ]; then
26+
mkdir -p "data/$dataset_folder"
27+
if [ "$cur_md5" != "$dataset_md5" ]; then
28+
wget "$dataset_url" -O "data/$dataset_filename"
29+
fi
30+
pushd "data/$dataset_folder"
31+
tar xvf "../$dataset_filename"
32+
popd 2>/dev/null
33+
else
34+
echo "Skipping, already downloaded."
35+
fi
36+
37+
pushd "data/$dataset_folder"
38+
classes=$(find * -maxdepth 0 -type d -name '[a-zA-Z]*')
39+
for class in $classes; do
40+
if [ -f "tags-$class.txt" ]; then
41+
echo "Already generated tags-$class.txt."
42+
continue
43+
fi
44+
echo "Generating tags-$class.txt..."
45+
{
46+
find "$class" -name '*.wav' | {
47+
while read line; do
48+
printf "${line%.wav}\twake-word\n"
49+
done
50+
}
51+
for other_class in $classes; do
52+
if [ "$class" = "$other_class" ]; then
53+
continue
54+
fi
55+
find "$other_class" -name '*.wav' | {
56+
while read line; do
57+
printf "${line%.wav}\tnot-wake-word\n"
58+
done
59+
}
60+
done
61+
} > "tags-$class.txt"
62+
done
63+
popd 2>/dev/null
64+
65+
echo "Setting up packages..."
66+
./setup.sh
67+
source .venv/bin/activate
68+
69+
echo "Dataset import complete."
70+
71+
mkdir -p models/
72+
train_command="precise-train models/$demo_class.net data/$dataset_folder --tags-file data/$dataset_folder/tags-$demo_class.txt -e 3 --batch-size 128 --sensitivity 0.5"
73+
echo ""
74+
echo "Training $demo_class model with command:"
75+
echo "$ $train_command"
76+
echo ""
77+
echo "Press any key to begin model training..."
78+
read -n 1
79+
eval "$train_command"
80+
81+
echo "Model saved to models/$demo_class.net"
82+
echo ""
83+
84+
test_command="precise-test models/$demo_class.net data/$dataset_folder --tags-file data/$dataset_folder/tags-$demo_class.txt"
85+
echo "Testing $demo_class model with command:"
86+
echo "$ $test_command"
87+
echo ""
88+
echo "Press any key to test model..."
89+
read -n 1
90+
eval "$test_command"
91+
92+
listen_command="precise-listen models/$demo_class.net --sensitivity 0.5"
93+
echo "Running $demo_class model against microphone with command:"
94+
echo "$ $listen_command"
95+
echo ""
96+
echo "Note: This will continuously listen to the microphone and should activate with the word \"$demo_class\". When you are done testing you can exit with Ctrl+C."
97+
echo "Press any key to test against microphone..."
98+
read -n 1
99+
eval "$listen_command"

0 commit comments

Comments
 (0)