-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.sh
More file actions
executable file
·138 lines (127 loc) · 2.56 KB
/
command.sh
File metadata and controls
executable file
·138 lines (127 loc) · 2.56 KB
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
#!/bin/bash
function sayit() {
amixer set Capture toggle 2>&1 > /dev/null
flite -t "$say"
amixer set Capture toggle 2>&1 > /dev/null
}
function listen() {
# :p
rm speech
mkfifo speech
julius -quiet -input mic -C sample.jconf | tee -a speech 2>&1 > /dev/null
}
function detectname() {
if [ "$command" != "" ]; then
#If $command with $name stripped doesn't equal $command then...
if [ ! "${command#$name}" == "$command" ]; then
namesaid="true"
command="${command#$name }"
#echo "Heard my name. Setting name flag and processing \"$command\""
namesaid="true"
fi
fi
}
#set -x
#dep checks
if [ ! $(which julius) ]; then
echo "You need julius. Install julius and julias-voxforge packages."
exit 1
fi
if [ ! $(which flite) ]; then
echo "You need flite. Install flite package."
exit 1
fi
name="JORDAN"
#throw julius in the background writing to a fifo and let settle
listen &
sleep 1
#read from the fifo and process as soon as possible without blocking.
cat speech | while true; do
read rawcommand
command=$(echo $rawcommand | grep sentence1: | sed -e 's/sentence1: <s> \(.*\) <\/s>/\1/')
detectname
#echo "$command"
case $command in
"PLAY MUSIC")
if [ "$namesaid" == "true" ]; then
#echo "Playing music!"
say="What would you like me to play?"
sayit
lastcommand="$command"
namesaid="false"
else
#echo "Need to hear my name to play music"
lastcommand=""
fi
;;
"STOP MUSIC")
if [ "$namesaid" == "true" ]; then
say="Killing VLC instances"
sayit
pkill vlc
else
#echo "Need to hear my name to stop music"
lastcommand=""
fi
;;
"WHAT TIME")
say="The time is $(date "+%l:%M %p")."
sayit
;;
"WHAT DAY")
say="Today is $(date "+%A %B %e")"
sayit
;;
"WHAT UP")
say="Not much. Whats up with you?"
sayit
;;
"GO UP")
say="Going up"
sayit
;;
"GO DOWN")
say="Going down"
sayit
;;
"GO LEFT")
say="Going left"
sayit
;;
"GO RIGHT")
say="Going right"
sayit
;;
"COM PU TER")
say="My name is $name"
sayit
;;
"$name")
let "resp = $RANDOM % 5 +1"
case $resp in
1) say="What?" ;;
2) say="Yes?" ;;
3) say="sir!" ;;
4) say="Can I help you?" ;;
5) say="Need something?" ;;
esac
sayit
lastcommand="$command"
;;
*)
case $lastcommand in
"PLAY MUSIC")
say="searching"
sayit
#google_speech
#./playsome.sh "$query"
nohup vlc "http://www.youtube.com/watch?v=oHg5SJYRHA0" 2&>1 > /dev/null &
lastcommand=""
;;
*)
#lastcommand=""
;;
esac
;;
esac
done;