Exemplo n.º 1
0
 def isValidImmersive(self, text, parsed):
     """ 判断是否当前音乐模式下的控制指令 """
     return any(
         unit.hasIntent(parsed, intent) for intent in [
             'CHANGE_MUSIC', 'CHANGE_TO_LAST', 'CHANGE_TO_NEXT',
             'CHANGE_VOL', 'CLOSE_MUSIC', 'PAUSE'
         ]) or '什么歌' in text
Exemplo n.º 2
0
def isValid(text, parsed=None, immersiveMode=None):
    """
        Returns True if the input is related to weather.

        Arguments:
        text -- user-input, typically transcribed speech
        parsed -- NLU structure parsed by Baidu UNIT
    """
    return unit.hasIntent(parsed, 'USER_WEATHER')
Exemplo n.º 3
0
def isValid(text, parsed=None, immersiveMode=None):
    """
        Returns True if the input is related to weather.

        Arguments:
        text -- user-input, typically transcribed speech
        parsed -- NLU structure parsed by Baidu UNIT
        immersiveMode -- current immersive mode
    """
    return unit.hasIntent(parsed, INTENT) and '写' in text and '诗' in text
        
        
Exemplo n.º 4
0
 def handle(self, text, parsed):
     global music_player
     if not music_player:
         self.init_music_player(
             config.get('/{}/channel'.format(self.SLUG), DEFAULT_CHANNEL))
     if unit.hasIntent(parsed, 'MUSICRANK') or any(
             word in text for word in [u"百度音乐", u"百度电台"]):
         music_player.play()
     elif unit.hasIntent(parsed, 'CHANGE_MUSIC'):
         self.say('换歌')
         self.init_music_player(random.choice(range(0, 40)))
         music_player.play()
     elif unit.hasIntent(parsed, 'CHANGE_TO_NEXT'):
         self.say('下一首歌')
         music_player.next()
     elif unit.hasIntent(parsed, 'CHANGE_TO_LAST'):
         self.say('上一首歌')
         music_player.prev()
     elif unit.hasIntent(parsed, 'CLOSE_MUSIC') or unit.hasIntent(
             parsed, 'PAUSE'):
         music_player.stop()
         self.say('退出播放')
     elif '什么歌' in text:
         info = music_player.get_current_song_info()
         if info is not None and info != {}:
             if info['artist_name']:
                 self.say('正在播放的是:{} 的 {}'.format(info['artist_name'],
                                                  info['song_name']))
             else:
                 self.say('正在播放的是:{}'.format(info['song_name']))
             time.sleep(3)
             music_player.play()
     else:
         self.say('没听懂你的意思呢,要退出播放,请说退出播放')
         music_player.play()
Exemplo n.º 5
0
def handle(text, mic, parsed=None):
    global music_player
    if not music_player:
        init_music_player(mic, config.get('/{}/channel'.format(SLUG, DEFAULT_CHANNEL)))
    if unit.hasIntent(parsed, 'MUSICRANK') or any(word in text for word in [u"百度音乐", u"百度电台"]):
        music_player.play()
    elif unit.hasIntent(parsed, 'CHANGE_MUSIC'):
        mic.say('换歌', plugin=__name__, cache=True)
        init_music_player(mic, random.choice(range(0, 40)))        
        music_player.play()
    elif unit.hasIntent(parsed, 'CHANGE_TO_NEXT'):
        mic.say('下一首歌', plugin=__name__, cache=True)
        music_player.next()
    elif unit.hasIntent(parsed, 'CHANGE_TO_LAST'):
        mic.say('上一首歌', plugin=__name__, cache=True)
        music_player.prev()
    elif unit.hasIntent(parsed, 'CLOSE_MUSIC') or unit.hasIntent(parsed, 'PAUSE'):        
        music_player.stop()
        mic.say('退出播放', plugin=__name__, cache=True)
    elif '什么歌' in text:
        info = music_player.get_current_song_info()
        if info is not None and info != {}:
            if info['artist_name']:
                mic.say('正在播放的是:{} 的 {}'.format(info['artist_name'], info['song_name']), plugin=__name__, cache=True)
            else:
                mic.say('正在播放的是:{}'.format(info['song_name']), plugin=__name__, cache=True)
            time.sleep(3)
            music_player.play()
    else:
        mic.say('没听懂你的意思呢,要退出播放,请说退出播放', plugin=__name__, cache=True)
        music_player.play()
Exemplo n.º 6
0
 def isValid(self, text, parsed):
     return unit.hasIntent(parsed, 'RUNHASS')
Exemplo n.º 7
0
 def isValid(self, text, parsed):
     return unit.hasIntent(parsed, 'GET_WEIBO')
Exemplo n.º 8
0
 def isValid(self, text, parsed):
     return unit.hasIntent(parsed, 'USER_WEATHER')
Exemplo n.º 9
0
 def isValid(self, text, parsed):
     parsed = unit.getUnit(text, SERVICE_ID, API_KEY,
                           SECRET_KEY)  # 调试用,发布时删除
     # 判断是否包含 HELLO_WORLD 意图
     return unit.hasIntent(parsed, 'HELLO_WORLD')
Exemplo n.º 10
0
 def isValid(self, text, parsed):
     return unit.hasIntent(parsed, INTENT) and '写' in text and '诗' in text
Exemplo n.º 11
0
def isControlCommand(text, parsed, immersiveMode):
    """ 判断是否当前音乐模式下的控制指令 """
    return immersiveMode == SLUG and any(unit.hasIntent(parsed, intent) for intent in ['CHANGE_MUSIC', 'CHANGE_TO_LAST', 'CHANGE_TO_NEXT', 'CHANGE_VOL', 'CLOSE_MUSIC', 'PAUSE']) or '什么歌' in text