Browse Source

Give plugins the ability to talk

Finally, some sort of built-in TTS support.  When a plugin emits a "tts"
signal, the Kaylee object will receive it and speak the given text
aloud.  It even stops listening while it speaks to prevent Kaylee from
talking to herself.  If no TTS is configured, it will print the text
instead, but since a default TTS setting is provided in the new
options.json.tmp, that shouldn't happen much.

Currently there's no way for the shell plugin to use TTS.  The D-Bus
interface will change that once I get around to making it.  Speaking of
D-Bus, UIs are broken again and I'm sure I can fix them once they're
separate processes talking to Kaylee by D-Bus.
Clara Hobbs 7 years ago
parent
commit
604bbf7ec3
4 changed files with 18 additions and 2 deletions
  1. 12
    0
      kayleevc/kaylee.py
  2. 3
    1
      kayleevc/plugins/pluginbase.py
  3. 1
    0
      kayleevc/plugins/simple.py
  4. 2
    1
      options.json.tmp

+ 12
- 0
kayleevc/kaylee.py View File

78
         for plugin in self.plugins:
78
         for plugin in self.plugins:
79
             self.recognizer.connect('finished', plugin.recognizer_finished)
79
             self.recognizer.connect('finished', plugin.recognizer_finished)
80
             plugin.connect('processed', self.plugin_processed)
80
             plugin.connect('processed', self.plugin_processed)
81
+            plugin.connect('tts', self.plugin_tts)
81
         self.recognizer.connect('finished', self.recognizer_finished)
82
         self.recognizer.connect('finished', self.recognizer_finished)
82
 
83
 
83
     def update_voice_commands_if_changed(self):
84
     def update_voice_commands_if_changed(self):
144
         print("no matching command {0}".format(text))
145
         print("no matching command {0}".format(text))
145
         self._stop_ui(text)
146
         self._stop_ui(text)
146
 
147
 
148
+    def plugin_tts(self, plugin, text):
149
+        # Stop listening
150
+        self.recognizer.pause()
151
+        # Speak
152
+        try:
153
+            subprocess.call(self.options['tts'] + [text])
154
+        except KeyError:
155
+            print('TTS:', text)
156
+        # Resume listening
157
+        self.recognizer.listen()
158
+
147
     def _stop_ui(self, text):
159
     def _stop_ui(self, text):
148
         # If there is a UI and we are not continuous listen
160
         # If there is a UI and we are not continuous listen
149
         if self.ui:
161
         if self.ui:

+ 3
- 1
kayleevc/plugins/pluginbase.py View File

15
 
15
 
16
     __gsignals__ = {
16
     __gsignals__ = {
17
         'processed' : (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
17
         'processed' : (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
18
-                      (GObject.TYPE_STRING,))
18
+                      (GObject.TYPE_STRING,)),
19
+        'tts' : (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
20
+                (GObject.TYPE_STRING,))
19
     }
21
     }
20
 
22
 
21
     def __init__(self, config, name):
23
     def __init__(self, config, name):

+ 1
- 0
kayleevc/plugins/simple.py View File

29
         if text == self.options['phrase']:
29
         if text == self.options['phrase']:
30
             self.emit('processed', text)
30
             self.emit('processed', text)
31
             print("Simple plugin says:", text)
31
             print("Simple plugin says:", text)
32
+            self.emit('tts', text)
32
             return True
33
             return True
33
         else:
34
         else:
34
             return False
35
             return False

+ 2
- 1
options.json.tmp View File

4
     "microphone": null,
4
     "microphone": null,
5
     "interface": null,
5
     "interface": null,
6
     "valid_sentence_command": null,
6
     "valid_sentence_command": null,
7
-    "invalid_sentence_command": null
7
+    "invalid_sentence_command": null,
8
+    "tts": ["espeak", "-ven-us+f2"]
8
 }
9
 }

Loading…
Cancel
Save