-
Notifications
You must be signed in to change notification settings - Fork 156
/
recognize
executable file
·81 lines (60 loc) · 2.03 KB
/
recognize
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
#!/bin/bash
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# TODO, make this use the mode, context and custom sed script
USER_DIR=$HOME/.palaver.d
# Try to run a command in ./Recognition/bin with useful errors.
function run_command() {
while read line
do
export "$line"
done <$USER_DIR/UserInfo
eval "./Recognition/bin/$1"
if [ $? != 0 ];then
./Recognition/bin/result Error "There was an error while running:" \
"$1" ""
exit 1
fi
}
cd $(dirname $0)
read mode < MODE
speech="$1"
# Use sed scripts here.
if [ -z "$speech" ];then
echo "Speech unable to be transcribed."
./Recognition/bin/result "Speech unable to be transcribed"
exit 1
fi
rm Microphone/result 2>/dev/null
if [ -e "$USER_DIR/personal.dic" ];then
COMMAND=$(./Recognition/dictionary "$speech"\
"$USER_DIR/personal.dic")
EXIT=$?
if [ "$EXIT" == 0 ];then
run_command "$COMMAND"
exit 0
fi
if [ "$EXIT" != 2 ];then
echo "There is an error in $USER_DIR/personal.dic"
fi
fi
COMMAND=$(./Recognition/dictionary "$speech" "./Recognition/modes/${mode}.dic")
EXIT=$?
if [ "$EXIT" == 0 ];then
run_command "$COMMAND"
exit 0
elif [ "$EXIT" == 2 ];then
./Recognition/bin/result Error "'$speech'" "is not a recognized command" ""
else
echo "There is an error in ${mode}.dic"
./Recognition/bin/result Error "There was an error while reading ${mode}.dic" \
"$COMMAND" ""
fi