|
@@ -0,0 +1,63 @@
|
|
1
|
+# This is part of Kaylee
|
|
2
|
+# -- this code is licensed GPLv3
|
|
3
|
+# Copyright 2015-2017 Clayton G. Hobbs
|
|
4
|
+# Portions Copyright 2013 Jezra
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+class PluginBase():
|
|
8
|
+ """Base class for Kaylee plugins
|
|
9
|
+
|
|
10
|
+ Each Kaylee plugin module must define a subclass of this class, named
|
|
11
|
+ ``Plugin``.
|
|
12
|
+ """
|
|
13
|
+
|
|
14
|
+ def __init__(self, config, name):
|
|
15
|
+ """Initialize the plugin
|
|
16
|
+
|
|
17
|
+ All strings to be included in the corpus should be elements of
|
|
18
|
+ ``corpus_strings`` by the end of __init__'s execution. Note however
|
|
19
|
+ that the words required for number support are automatically included,
|
|
20
|
+ so they need not be listed explicitly on a per-plugin basis.
|
|
21
|
+ """
|
|
22
|
+ super().__init__()
|
|
23
|
+ self.config = config
|
|
24
|
+ self.name = name
|
|
25
|
+ self.options = config.plugins[name]
|
|
26
|
+ self.corpus_strings = set()
|
|
27
|
+
|
|
28
|
+ def get_handler(self, text):
|
|
29
|
+ """Return a handler for the given text
|
|
30
|
+
|
|
31
|
+ This method returns a Handler object which handles the command when
|
|
32
|
+ called. If the plugin does not recognize the command at all, this
|
|
33
|
+ method must return None instead. The method must also return None if
|
|
34
|
+ the command is recognized, but for some reason would not perform any
|
|
35
|
+ action currently, e.g. "pause music" when no music player is running.
|
|
36
|
+ """
|
|
37
|
+ return None
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+class Handler:
|
|
41
|
+ """Base class for Kaylee plugin handlers
|
|
42
|
+
|
|
43
|
+ Plugins should subclass this for their own command handlers.
|
|
44
|
+ """
|
|
45
|
+
|
|
46
|
+ def __init__(self, confidence):
|
|
47
|
+ """Initialize the handler
|
|
48
|
+
|
|
49
|
+ The confidence with which this handler will handle the command must be
|
|
50
|
+ passed as ``confidence``, a floating-point number in (0, 1]. A
|
|
51
|
+ confidence of 1 indicates that the handler is definitely supposed to
|
|
52
|
+ handle the command it was created for. Values between 0 and 1 may be
|
|
53
|
+ used to indicate that the plugin may be able to handle the command,
|
|
54
|
+ but it was misunderstood by the speech recognition system.
|
|
55
|
+ """
|
|
56
|
+ self.confidence = confidence
|
|
57
|
+
|
|
58
|
+ def __call__(self, tts):
|
|
59
|
+ """Handle the command
|
|
60
|
+
|
|
61
|
+ When called, ``tts`` is a function which takes a string as its only
|
|
62
|
+ parameter and passes it to Kaylee's configured text-to-speech system.
|
|
63
|
+ """
|