forked from benoitfragit/google2ubuntu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
listen.sh
executable file
·61 lines (50 loc) · 1.4 KB
/
listen.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
#!/bin/sh
# Okay Google hotword activation script
# Josh Chen, 14 Feb 2014
# Feel free to modify as you need
# configuration file
CONFIGURATION="$HOME/.config/google2ubuntu/google2ubuntu.conf"
BASEDIR=$(dirname $0)
cd $BASEDIR
# default recording time
threshold=5
> "/tmp/hotword"
while [ -f "/tmp/hotword" ]; do
# load the config every time, let the user setup the treshold and the hotword
if [ -f "$CONFIGURATION" ];
then
{
# load the configuration
. "$CONFIGURATION"
# small security test
if [ "$threshold" = "" ];
then
threshold=5
fi
}
fi
# Initialize
killall rec 2>/dev/null
rm /tmp/pingvox.flac 2>/dev/null
touch /tmp/pingvox.flac
# If voice detected, record for 2.5s interval
# Listen and record only when sound levels are over 17% (on razor optimal alsamixer settings seem to be 100 Internal mic, 28 Internal mic B)
# >> MIC CONFIGURATION HERE <<
( rec /tmp/pingvox.flac rate 16000 silence 1 0.1 "$threshold"% ) & pid=$!
while [ "$(stat -c%s /tmp/pingvox.flac)" == "0" ]; do
if [ ! -f "/tmp/hotword" ]; then
{
killall rec
exit 0
}
fi
done
( sleep 2s && kill -HUP $pid ) 2>/dev/null & watcher=$!
wait $pid 2>/dev/null && pkill -HUP -P $watcher
echo
echo 'Voice detected, launching listener.py'
# Call script that checks for hotword
python listener.py
wait
done
exit 0;