ソースを参照

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年前
コミット
604bbf7ec3
4個のファイルの変更18行の追加2行の削除
  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 ファイルの表示

@@ -78,6 +78,7 @@ class Kaylee:
78 78
         for plugin in self.plugins:
79 79
             self.recognizer.connect('finished', plugin.recognizer_finished)
80 80
             plugin.connect('processed', self.plugin_processed)
81
+            plugin.connect('tts', self.plugin_tts)
81 82
         self.recognizer.connect('finished', self.recognizer_finished)
82 83
 
83 84
     def update_voice_commands_if_changed(self):
@@ -144,6 +145,17 @@ class Kaylee:
144 145
         print("no matching command {0}".format(text))
145 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 159
     def _stop_ui(self, text):
148 160
         # If there is a UI and we are not continuous listen
149 161
         if self.ui:

+ 3
- 1
kayleevc/plugins/pluginbase.py ファイルの表示

@@ -15,7 +15,9 @@ class PluginBase(GObject.Object):
15 15
 
16 16
     __gsignals__ = {
17 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 23
     def __init__(self, config, name):

+ 1
- 0
kayleevc/plugins/simple.py ファイルの表示

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

+ 2
- 1
options.json.tmp ファイルの表示

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

読み込み中…
キャンセル
保存