-
Notifications
You must be signed in to change notification settings - Fork 19
/
__init__.py
66 lines (56 loc) · 2.33 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Copyright 2016 Mycroft AI, Inc.
#
# This file is part of Mycroft Core.
#
# Mycroft Core is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Mycroft Core is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>.
import random
from os.path import dirname, join
from adapt.intent import IntentBuilder
from mycroft import MycroftSkill, intent_handler
from mycroft.skills.audioservice import AudioService
from mycroft.audio import wait_while_speaking
class SingingSkill(MycroftSkill):
def __init__(self):
super(SingingSkill, self).__init__(name="SingingSkill")
self.process = None
self.play_list = {
0: join(dirname(__file__), "popey-favourite.mp3"),
1: join(dirname(__file__), "popey-jackson.mp3"),
2: join(dirname(__file__), "popey-jerusalem.mp3"),
3: join(dirname(__file__), "popey-lose-yourself.mp3"),
4: join(dirname(__file__), "popey-lovemetender.mp3"),
5: join(dirname(__file__), "popey-rocketman.mp3"),
6: join(dirname(__file__), "drnimpo-robots.mp3"),
}
def initialize(self):
self.audioservice = AudioService(self.bus)
self.add_event("mycroft.sing", self.sing, False)
def sing(self, message):
self.audioservice.play(self.play_list[3])
@intent_handler(IntentBuilder('').require('Sing'))
def handle_sing(self, message):
path = random.choice(self.play_list)
try:
self.speak_dialog('singing')
wait_while_speaking()
self.audioservice.play(path)
except Exception as e:
self.log.error("Error: {0}".format(e))
def stop(self):
if self.process and self.process.poll() is None:
self.speak_dialog('singing.stop')
self.process.terminate()
self.process.wait()
def create_skill():
return SingingSkill()