Ejemplo n.º 1
0
class PlayPauseButtonTest(unittest.TestCase):
    def setUp(self):
        self.previousButton = PreviousButton()
        self.previousButton.set_enabled(False)
        self.previousButton.set_selected(True)

    def testGetData(self):

        ret = {
            'type': 'BUTTON',
            'name': 'PREVIOUS',
            'enabled': False,
            'selected': True
        }

        self.assertEqual(self.previousButton.get_data(), ret)

    pass
Ejemplo n.º 2
0
    def audioPlay(self):
        '''
        播放指令
        '''
        directives = []
        directive1 = Play(
            'http://audio.xmcdn.com/group27/M07/91/30/wKgJW1kVpTTysDS9ABG_opoNMoA008.m4a',
            PlayBehaviorEnum.REPLACE_ALL)
        playerInfo = PlayerInfo()
        playerInfo.set_title('Python')
        playerInfo.set_title_subtext1('python')
        playerInfo.set_art(
            'https://imagev2.xmcdn.com/group26/M03/94/DD/wKgJWFkVpOyzKhU_AABPh3rraa8772.jpg!op_type=5&upload_type=cover&device_type=ios&name=web_meduim&strip=0&quality=7'
        )

        playpause = PlayPauseButton()
        previous = PreviousButton()
        next = NextButton()
        showPlayList = ShowPlayListButton()
        showPlayList.set_enabled(False)
        controls = [playpause, previous, next, showPlayList]
        # controls = [playpause, previous]
        playerInfo.set_controls(controls)
        # playerInfo.add_control(NextButton())
        directive1.set_player_info(playerInfo)

        # directive2 = Play('http://audio.xmcdn.com/group27/M04/91/28/wKgJW1kVpMfRrzE5AAzyjIkEf9s698.m4a', PlayBehaviorEnum.ENQUEUE)
        # playerInfo = PlayerInfo()
        # playerInfo.set_title('子夜吴歌')
        # playerInfo.set_art(
        #     'https://imagev2.xmcdn.com/group26/M03/94/DD/wKgJWFkVpOyzKhU_AABPh3rraa8772.jpg!op_type=5&upload_type=cover&device_type=ios&name=web_meduim&strip=0&quality=7')
        # playpause = PlayPauseButton()
        # previous = PreviousButton()
        # previous.set_selected(True)
        # controls = [playpause, previous]
        # playerInfo.set_controls(controls)
        # playerInfo.add_control(NextButton())
        # directive2.set_player_info(playerInfo)
        # directive3 = Play('http://audio.xmcdn.com/group27/M04/91/28/wKgJW1kVpMfRrzE5AAzyjIkEf9s698.m4a', PlayBehaviorEnum.ENQUEUE)
        #
        # playerInfo = PlayerInfo()
        # playerInfo.set_title('子夜吴歌')
        # playerInfo.set_art(
        #     'https://imagev2.xmcdn.com/group26/M03/94/DD/wKgJWFkVpOyzKhU_AABPh3rraa8772.jpg!op_type=5&upload_type=cover&device_type=ios&name=web_meduim&strip=0&quality=7')
        # playpause = PlayPauseButton()
        # previous = PreviousButton()
        # previous.set_selected(True)
        # controls = [playpause, previous]
        # playerInfo.set_controls(controls)
        # playerInfo.add_control(NextButton())
        # directive3.set_player_info(playerInfo)
        directives.append(directive1)
        # directives.append(directive2)
        # directives.append(directive3)

        return {'directives': directives, 'outputSpeech': r'正在为你播放歌曲'}
Ejemplo n.º 3
0
    def getAnimalResponse(self, animal):
        name = Utils.getName(animal)
        content = Utils.getDescribtion(animal)
        imgUrl = Utils.getImageUrl(animal)
        soundUrl = Utils.getSoundUrl(animal)

        self.set_session_attribute('name', name, None)

        play = Play(soundUrl, PlayBehaviorEnum.REPLACE_ALL)

        playerInfo = PlayerInfo()

        playpause = PlayPauseButton()
        previous = PreviousButton()
        next = NextButton()

        previous.set_selected(True)

        controls = [previous, playpause, next]
        playerInfo.set_controls(controls)
        playerInfo.set_title(name)
        playerInfo.set_title_subtext1(content)
        playerInfo.set_art(imgUrl)
        play.set_player_info(playerInfo)

        template = BodyTemplate3()
        template.set_title(name)
        template.set_plain_content(content)
        template.set_image(Utils.getImageUrl(animal))
        template.set_background_image(Utils.getImageUrl(animal))

        renderTemplate = RenderTemplate(template)
        outputSpeech = name

        return {
            'directives': [play],
            'reprompt': content,
            'outputSpeech': outputSpeech
        }
Ejemplo n.º 4
0
def build_audio_play(index, audio):
    audio_url = audio['audio_path']
    directive = Play(audio_url)
    audio_content = AudioPlayerInfoContent()
    audio_content.set_title(audio['audio_name'])
    audio_content.set_title_subtext1(audio['audio_name'])
    audio_content.set_art(
        'http://imagev2.xmcdn.com/group10/M0B/85/50/wKgDZ1YgthSi0SHEAACtQo3lZK8096.jpg!op_type=5&upload_type=header&device_type=ios&name=web_x_large&strip=0&quality=7'
    )
    previous = PreviousButton()
    pause = PlayPauseButton()
    next = NextButton()
    play_list = ShowPlayListButton()
    play_info = AudioPlayerInfo(audio_content,
                                [previous, pause, next, play_list])
    directive.set_player_info(play_info)
    token = 'playlist:%s' % index
    directive.set_token(token)
    hint = Hint(['下一个/上一个'])
    return {
        'directives': [hint, directive],
        'outputSpeech': '即将播放:%s' % audio['audio_name']
    }
Ejemplo n.º 5
0
        if StreamFormatEnum.inEnum(streamFormat):
            self.data['audioItem']['stream'][
                'streamFormat'] = streamFormat.value
        else:
            self.data['audioItem']['stream'][
                'streamFormat'] = StreamFormatEnum.STREAM_FORMAT_MP3.value
        return self


if __name__ == '__main__':
    directive = Play('http://www.baidu.com')
    directive.setStreamFormat('AUDIO_M3U8')

    playerInfo = PlayerInfo()

    # 创建暂停按钮
    playpause = PlayPauseButton()
    previous = PreviousButton()
    previous.setSelected(True)
    controls = [playpause, previous]
    playerInfo.setControls(controls)
    playerInfo.addControl(NextButoon())

    playerInfo.setTitle('周杰伦')
    playerInfo.setTitleSubtext1('七里香')
    playerInfo.setArt('http://adfadfa')

    # 设置Play指令的PlayerInfo
    directive.setPlayerInfo(playerInfo)
    print(directive.getData())
Ejemplo n.º 6
0
 def setUp(self):
     self.previousButton = PreviousButton()
     self.previousButton.set_enabled(False)
     self.previousButton.set_selected(True)