Browse Source

Delegated invalid_sentence_command to Kaylee

Now the Kaylee object handles the invalid_sentence_command as well.  It
does this by having the last handler for the recognizer's 'finished'
signal.  If this handler is ever run, the voice command was obviously
not wanted by any of the plugins, so the invalid_sentence_command should
be run.

Also, I fixed the UIs to work as before.  It's a temporary fix!
Clara Hobbs 8 years ago
parent
commit
a46c6f69fc
2 changed files with 21 additions and 15 deletions
  1. 20
    0
      kayleevc/kaylee.py
  2. 1
    15
      kayleevc/plugins/shell.py

+ 20
- 0
kayleevc/kaylee.py View File

@@ -73,6 +73,7 @@ class Kaylee:
73 73
         for plugin in self.plugins:
74 74
             self.recognizer.connect('finished', plugin.recognizer_finished)
75 75
             plugin.connect('processed', self.plugin_processed)
76
+        self.recognizer.connect('finished', self.recognizer_finished)
76 77
 
77 78
     def update_voice_commands_if_changed(self):
78 79
         """Use hashes to test if the voice commands have changed"""
@@ -127,6 +128,25 @@ class Kaylee:
127 128
             with open(self.config.history_file, 'w') as hfile:
128 129
                 for line in self.history:
129 130
                     hfile.write(line + '\n')
131
+        self._stop_ui(text)
132
+
133
+    def recognizer_finished(self, recognizer, text):
134
+        # No loaded plugin wanted the text, so run the invalid_sentence_command
135
+        # if it's set
136
+        if self.options['invalid_sentence_command']:
137
+            subprocess.call(self.options['invalid_sentence_command'],
138
+                            shell=True)
139
+        print("no matching command {0}".format(text))
140
+        self._stop_ui(text)
141
+
142
+    def _stop_ui(self, text):
143
+        # If there is a UI and we are not continuous listen
144
+        if self.ui:
145
+            if not self.continuous_listen:
146
+                # Stop listening
147
+                self.recognizer.pause()
148
+            # Let the UI know that there is a finish
149
+            self.ui.finished(text)
130 150
 
131 151
     def run(self):
132 152
         if self.ui:

+ 1
- 15
kayleevc/plugins/shell.py View File

@@ -38,6 +38,7 @@ class Plugin(PluginBase):
38 38
             cmd = self.commands[text]
39 39
             self._run_command(cmd)
40 40
             return True
41
+        # Is there a matching command with numbers substituted?
41 42
         elif numt in self.commands:
42 43
             self.emit('processed', text)
43 44
             cmd = self.commands[numt]
@@ -45,19 +46,4 @@ class Plugin(PluginBase):
45 46
             self._run_command(cmd)
46 47
             return True
47 48
         else:
48
-            # TODO: This could be implemented as a plugin, implicitly loaded
49
-            # last
50
-            # Run the invalid_sentence_command if it's set
51
-            if self.options['invalid_sentence_command']:
52
-                subprocess.call(self.options['invalid_sentence_command'],
53
-                                shell=True)
54
-            print("no matching command {0}".format(text))
55 49
             return False
56
-        # TODO: Make the D-Bus interface so this can leave the main process
57
-        ## If there is a UI and we are not continuous listen
58
-        #if self.ui:
59
-        #    if not self.continuous_listen:
60
-        #        # Stop listening
61
-        #        self.recognizer.pause()
62
-        #    # Let the UI know that there is a finish
63
-        #    self.ui.finished(text)

Loading…
Cancel
Save