Skip to content

Commit

Permalink
Modernize
Browse files Browse the repository at this point in the history
- use decorator
- simplify keyword
- add .gitignore
- use audioservice
  • Loading branch information
forslund committed Apr 25, 2018
1 parent 8cfd0e6 commit 6c73f1b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
settings.json

# python compiled files
*.pyc
__pycache__/

# Vim temp files
.*.sw?
30 changes: 10 additions & 20 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,12 @@


import random
import time
from os.path import dirname, join

from adapt.intent import IntentBuilder
from mycroft.messagebus.message import Message
from mycroft.skills.core import MycroftSkill
from mycroft.util import play_mp3
from mycroft.util.log import getLogger

__author__ = 'kfezer'

LOGGER = getLogger(__name__)

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):
Expand All @@ -45,24 +38,21 @@ def __init__(self):
}

def initialize(self):
intent = IntentBuilder("SingingIntent").require(
"SingingKeyword").build()
self.register_intent(intent, self.handle_intent)
self.audioservice = AudioService(self.emitter)
self.add_event("mycroft.sing", self.sing, False)

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

def handle_intent(self, message):
rando = random.randint(0, 5)
file = self.play_list[rando]
@intent_handler(IntentBuilder('').require('Sing'))
def handle_sing(self, message):
path = random.choice(self.play_list)
try:
self.speak_dialog('singing')
time.sleep(3)
self.process = play_mp3(file)

wait_while_speaking()
self.audioservice.play(path)
except Exception as e:
LOGGER.error("Error: {0}".format(e))
self.log.error("Error: {0}".format(e))

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

0 comments on commit 6c73f1b

Please sign in to comment.