|
@@ -38,7 +38,6 @@ class Kaylee:
|
38
|
38
|
for plugin in self.config.plugins.keys():
|
39
|
39
|
pmod = importlib.import_module(plugin, 'kayleevc.plugins')
|
40
|
40
|
pobj = pmod.Plugin(self.config, plugin)
|
41
|
|
- pobj.connect('tts', self.plugin_tts)
|
42
|
41
|
self.plugins.append(pobj)
|
43
|
42
|
|
44
|
43
|
# Create a hasher
|
|
@@ -139,18 +138,18 @@ class Kaylee:
|
139
|
138
|
def recognizer_finished(self, recognizer, text):
|
140
|
139
|
confidence_heap = queue.PriorityQueue()
|
141
|
140
|
min_confidence = self.options['minimum_confidence']
|
142
|
|
- # Add plugins to the heap
|
|
141
|
+ # Add handlers to the heap
|
143
|
142
|
for index, plugin in enumerate(self.plugins):
|
144
|
|
- # Get plugin confidence
|
145
|
|
- confidence = plugin.confidence(text)
|
146
|
|
- # Clamp confidence to [0, 1]
|
147
|
|
- confidence = min(max(confidence, 0), 1)
|
148
|
|
- # If the plugin meets minimum confidence
|
149
|
|
- if ((min_confidence is not None and confidence >= min_confidence)
|
150
|
|
- or (min_confidence is None and confidence > 0)):
|
151
|
|
- # Add a triple to the heap, so plugins are sorted first by
|
152
|
|
- # confidence, then by index to break ties
|
153
|
|
- confidence_heap.put_nowait((1 - confidence, index, plugin))
|
|
143
|
+ # Get a handler
|
|
144
|
+ handler = plugin.get_handler(text)
|
|
145
|
+ # If the handler meets minimum confidence
|
|
146
|
+ if ((handler is not None)
|
|
147
|
+ and ((min_confidence is None)
|
|
148
|
+ or (min_confidence is not None
|
|
149
|
+ and handler.confidence >= min_confidence))):
|
|
150
|
+ # Add a triple to the heap, so handlers are sorted first by
|
|
151
|
+ # their confidence, then by index to break ties
|
|
152
|
+ confidence_heap.put_nowait((handler, index, plugin))
|
154
|
153
|
|
155
|
154
|
# Run valid or invalid sentence command
|
156
|
155
|
if confidence_heap.empty():
|
|
@@ -158,20 +157,24 @@ class Kaylee:
|
158
|
157
|
else:
|
159
|
158
|
self._valid_cmd()
|
160
|
159
|
|
161
|
|
- # Give the command to the plugins that want it
|
|
160
|
+ # Give the command to the handlers that want it
|
162
|
161
|
while True:
|
163
|
162
|
try:
|
164
|
|
- plugin = confidence_heap.get_nowait()[2]
|
165
|
|
- except queue.Empty:
|
166
|
|
- break
|
167
|
|
- # If the plugin successfully handled the command
|
168
|
|
- if plugin.handle(text):
|
|
163
|
+ # Get information about the handler
|
|
164
|
+ info = confidence_heap.get_nowait()
|
|
165
|
+ handler = info[0]
|
|
166
|
+ plugin = info[2]
|
|
167
|
+ # Handle the command
|
|
168
|
+ handler(self.plugin_tts)
|
169
|
169
|
self._log_history(plugin, text)
|
|
170
|
+ except queue.Empty:
|
170
|
171
|
break
|
|
172
|
+ # If an unknown error occurs, ignore it and keep trying
|
|
173
|
+ # FIXME not a good API decision
|
171
|
174
|
|
172
|
175
|
self._stop_ui(text)
|
173
|
176
|
|
174
|
|
- def plugin_tts(self, plugin, text):
|
|
177
|
+ def plugin_tts(self, text):
|
175
|
178
|
# Stop listening
|
176
|
179
|
self.recognizer.pause()
|
177
|
180
|
# Speak
|