|
@@ -29,12 +29,14 @@ if not os.path.exists(lang_dir):
|
29
|
29
|
|
30
|
30
|
class Blather:
|
31
|
31
|
def __init__(self, opts):
|
|
32
|
+
|
32
|
33
|
#import the recognizer so Gst doesn't clobber our -h
|
33
|
34
|
from Recognizer import Recognizer
|
34
|
35
|
self.ui = None
|
35
|
36
|
self.options = {}
|
36
|
37
|
ui_continuous_listen = False
|
37
|
38
|
self.continuous_listen = False
|
|
39
|
+
|
38
|
40
|
self.commands = {}
|
39
|
41
|
self.read_commands()
|
40
|
42
|
self.recognizer = Recognizer(lang_file, dic_file, opts.microphone )
|
|
@@ -44,7 +46,7 @@ class Blather:
|
44
|
46
|
self.load_options()
|
45
|
47
|
#merge the opts
|
46
|
48
|
for k,v in opts.__dict__.items():
|
47
|
|
- if not k in self.options:
|
|
49
|
+ if (not k in self.options) or opts.override:
|
48
|
50
|
self.options[k] = v
|
49
|
51
|
|
50
|
52
|
print "Using Options: ", self.options
|
|
@@ -120,12 +122,18 @@ class Blather:
|
120
|
122
|
t = text.lower()
|
121
|
123
|
#is there a matching command?
|
122
|
124
|
if self.commands.has_key( t ):
|
|
125
|
+ #run the valid_sentence_command if there is a valid sentence command
|
|
126
|
+ if self.options['valid_sentence_command']:
|
|
127
|
+ subprocess.call(self.options['valid_sentence_command'], shell=True)
|
123
|
128
|
cmd = self.commands[t]
|
124
|
129
|
print cmd
|
125
|
130
|
subprocess.call(cmd, shell=True)
|
126
|
131
|
self.log_history(text)
|
127
|
132
|
else:
|
128
|
|
- print "no matching command"
|
|
133
|
+ #run the invalid_sentence_command if there is a valid sentence command
|
|
134
|
+ if self.options['invalid_sentence_command']:
|
|
135
|
+ subprocess.call(self.options['invalid_sentence_command'], shell=True)
|
|
136
|
+ print "no matching command %s" %(t)
|
129
|
137
|
#if there is a UI and we are not continuous listen
|
130
|
138
|
if self.ui:
|
131
|
139
|
if not self.continuous_listen:
|
|
@@ -169,22 +177,36 @@ class Blather:
|
169
|
177
|
return False
|
170
|
178
|
|
171
|
179
|
|
172
|
|
-
|
173
|
180
|
if __name__ == "__main__":
|
174
|
181
|
parser = OptionParser()
|
175
|
182
|
parser.add_option("-i", "--interface", type="string", dest="interface",
|
176
|
183
|
action='store',
|
177
|
184
|
help="Interface to use (if any). 'q' for Qt, 'g' for GTK, 'gt' for GTK system tray icon")
|
|
185
|
+
|
178
|
186
|
parser.add_option("-c", "--continuous",
|
179
|
187
|
action="store_true", dest="continuous", default=False,
|
180
|
188
|
help="starts interface with 'continuous' listen enabled")
|
|
189
|
+
|
|
190
|
+ parser.add_option("-o", "--override",
|
|
191
|
+ action="store_true", dest="override", default=False,
|
|
192
|
+ help="override config file with command line options")
|
|
193
|
+
|
181
|
194
|
parser.add_option("-H", "--history", type="int",
|
182
|
195
|
action="store", dest="history",
|
183
|
196
|
help="number of commands to store in history file")
|
|
197
|
+
|
184
|
198
|
parser.add_option("-m", "--microphone", type="int",
|
185
|
199
|
action="store", dest="microphone", default=None,
|
186
|
200
|
help="Audio input card to use (if other than system default)")
|
187
|
201
|
|
|
202
|
+ parser.add_option("--valid-sentence-command", type="string", dest="valid_sentence_command",
|
|
203
|
+ action='store',
|
|
204
|
+ help="command to run when a valid sentence is detected")
|
|
205
|
+
|
|
206
|
+ parser.add_option( "--invalid-sentence-command", type="string", dest="invalid_sentence_command",
|
|
207
|
+ action='store',
|
|
208
|
+ help="command to run when an invalid sentence is detected")
|
|
209
|
+
|
188
|
210
|
(options, args) = parser.parse_args()
|
189
|
211
|
#make our blather object
|
190
|
212
|
blather = Blather(options)
|