Browse Source

Added a simple example plugin

It prints a single phrase when it hears the same phrase spoken.  Nothing
to brag about, just a cute example to show how to write a plugin.
Clara Hobbs 8 years ago
parent
commit
03f613f77d
1 changed files with 34 additions and 0 deletions
  1. 34
    0
      kayleevc/plugins/simple.py

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

@@ -0,0 +1,34 @@
1
+# This is part of Kaylee
2
+# -- this code is licensed GPLv3
3
+# Copyright 2015-2016 Clayton G. Hobbs
4
+# Portions Copyright 2013 Jezra
5
+
6
+"""A simple plugin to serve as an example
7
+
8
+This is an extremely minimal Kaylee plugin to serve as an example for
9
+developing more complex plugins.  It takes a single configuration
10
+option, "phrase", which is a sentence to be recognized.  Once this is
11
+heard, the plugin prints "Simple plugin says: [phrase]".
12
+"""
13
+
14
+from .pluginbase import PluginBase
15
+
16
+
17
+class Plugin(PluginBase):
18
+    """Main class for the simple plugin"""
19
+
20
+    def __init__(self, config, name):
21
+        """Initialize the simple plugin"""
22
+        super().__init__(config, name)
23
+
24
+        self.corpus_strings.add(self.options['phrase'])
25
+
26
+    def recognizer_finished(self, recognizer, text):
27
+        """Print the phrase when it is spoken"""
28
+        # Is there a matching command?
29
+        if text == self.options['phrase']:
30
+            self.emit('processed', text)
31
+            print("Simple plugin says:", text)
32
+            return True
33
+        else:
34
+            return False

Loading…
Cancel
Save