forked from wzpan/wukong-robot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVolume.py
40 lines (34 loc) · 1.46 KB
/
Volume.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
# -*- coding: utf-8-*-
from robot.Player import MusicPlayer
from robot import logging
from robot.sdk.AbstractPlugin import AbstractPlugin
logger = logging.getLogger(__name__)
class Plugin(AbstractPlugin):
def __init__(self, con):
super(Plugin, self).__init__(con)
self.player = None
def handle(self, text, parsed):
if not self.player:
self.player = MusicPlayer([], self)
if self.nlu.hasIntent(parsed, 'CHANGE_VOL'):
slots = self.nlu.getSlots(parsed, 'CHANGE_VOL')
for slot in slots:
if slot['name'] == 'user_d':
word = self.nlu.getSlotWords(parsed, 'CHANGE_VOL', 'user_d')[0]
if word == '--HIGHER--':
self.player.turnUp()
self.say('好的', cache=True)
else:
self.player.turnDown()
self.say('好的', cache=True)
return
elif slot['name'] == 'user_vd':
word = self.nlu.getSlotWords(parsed, 'CHANGE_VOL', 'user_vd')[0]
if word == '--LOUDER--':
self.player.turnUp()
self.say('好的', cache=True)
else:
self.player.turnDown()
self.say('好的', cache=True)
def isValid(self, text, parsed):
return self.nlu.hasIntent(parsed, 'CHANGE_VOL')