Skip to content

Commit 02b3239

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 20be762 commit 02b3239

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

train_speech_commands.sh

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

0 commit comments

Comments
 (0)