17
17
18
18
19
19
import random
20
- import time
21
20
from os .path import dirname , join
22
21
23
22
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
33
26
34
27
class SingingSkill (MycroftSkill ):
35
28
def __init__ (self ):
@@ -45,24 +38,21 @@ def __init__(self):
45
38
}
46
39
47
40
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 )
51
42
self .add_event ("mycroft.sing" , self .sing , False )
52
43
53
44
def sing (self , message ):
54
45
self .process = play_mp3 (self .play_list [3 ])
55
46
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 )
59
50
try :
60
51
self .speak_dialog ('singing' )
61
- time .sleep (3 )
62
- self .process = play_mp3 (file )
63
-
52
+ wait_while_speaking ()
53
+ self .audioservice .play (path )
64
54
except Exception as e :
65
- LOGGER .error ("Error: {0}" .format (e ))
55
+ self . log .error ("Error: {0}" .format (e ))
66
56
67
57
def stop (self ):
68
58
if self .process and self .process .poll () is None :
0 commit comments