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 7 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
         for plugin in self.plugins:
73
         for plugin in self.plugins:
74
             self.recognizer.connect('finished', plugin.recognizer_finished)
74
             self.recognizer.connect('finished', plugin.recognizer_finished)
75
             plugin.connect('processed', self.plugin_processed)
75
             plugin.connect('processed', self.plugin_processed)
76
+        self.recognizer.connect('finished', self.recognizer_finished)
76
 
77
 
77
     def update_voice_commands_if_changed(self):
78
     def update_voice_commands_if_changed(self):
78
         """Use hashes to test if the voice commands have changed"""
79
         """Use hashes to test if the voice commands have changed"""
127
             with open(self.config.history_file, 'w') as hfile:
128
             with open(self.config.history_file, 'w') as hfile:
128
                 for line in self.history:
129
                 for line in self.history:
129
                     hfile.write(line + '\n')
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
     def run(self):
151
     def run(self):
132
         if self.ui:
152
         if self.ui:

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

38
             cmd = self.commands[text]
38
             cmd = self.commands[text]
39
             self._run_command(cmd)
39
             self._run_command(cmd)
40
             return True
40
             return True
41
+        # Is there a matching command with numbers substituted?
41
         elif numt in self.commands:
42
         elif numt in self.commands:
42
             self.emit('processed', text)
43
             self.emit('processed', text)
43
             cmd = self.commands[numt]
44
             cmd = self.commands[numt]
45
             self._run_command(cmd)
46
             self._run_command(cmd)
46
             return True
47
             return True
47
         else:
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
             return False
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