Skip to content

Commit 6c73f1b

Browse files
committed
Modernize
- use decorator - simplify keyword - add .gitignore - use audioservice
1 parent 8cfd0e6 commit 6c73f1b

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
settings.json
2+
3+
# python compiled files
4+
*.pyc
5+
__pycache__/
6+
7+
# Vim temp files
8+
.*.sw?

__init__.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,12 @@
1717

1818

1919
import random
20-
import time
2120
from os.path import dirname, join
2221

2322
from adapt.intent import IntentBuilder
24-
from mycroft.messagebus.message import Message
25-
from mycroft.skills.core import MycroftSkill
26-
from mycroft.util import play_mp3
27-
from mycroft.util.log import getLogger
28-
29-
__author__ = 'kfezer'
30-
31-
LOGGER = getLogger(__name__)
32-
23+
from mycroft import MycroftSkill, intent_handler
24+
from mycroft.skills.audioservice import AudioService
25+
from mycroft.audio import wait_while_speaking
3326

3427
class SingingSkill(MycroftSkill):
3528
def __init__(self):
@@ -45,24 +38,21 @@ def __init__(self):
4538
}
4639

4740
def initialize(self):
48-
intent = IntentBuilder("SingingIntent").require(
49-
"SingingKeyword").build()
50-
self.register_intent(intent, self.handle_intent)
41+
self.audioservice = AudioService(self.emitter)
5142
self.add_event("mycroft.sing", self.sing, False)
5243

5344
def sing(self, message):
5445
self.process = play_mp3(self.play_list[3])
5546

56-
def handle_intent(self, message):
57-
rando = random.randint(0, 5)
58-
file = self.play_list[rando]
47+
@intent_handler(IntentBuilder('').require('Sing'))
48+
def handle_sing(self, message):
49+
path = random.choice(self.play_list)
5950
try:
6051
self.speak_dialog('singing')
61-
time.sleep(3)
62-
self.process = play_mp3(file)
63-
52+
wait_while_speaking()
53+
self.audioservice.play(path)
6454
except Exception as e:
65-
LOGGER.error("Error: {0}".format(e))
55+
self.log.error("Error: {0}".format(e))
6656

6757
def stop(self):
6858
if self.process and self.process.poll() is None:
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)