示例#1
0
class PlayPauseButtonTest(unittest.TestCase):
    def setUp(self):
        self.playPauseButton = PlayPauseButton()
        self.playPauseButton.set_enabled(False)
        self.playPauseButton.set_selected(True)

    def testGetData(self):

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

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

    pass
示例#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'正在为你播放歌曲'}
示例#3
0
    def testGetData(self):

        with open('../../json/render_video.json', encoding='utf-8') as f:
            content = f.read()
            self.data = json.loads(content)
        print(self.data)

        content = VideoPlayerInfoContent('title')
        content.set_media_length_in_milliseconds(10000)
        playPauseButton = PlayPauseButton()
        playlistButton = ShowPlayListButton()
        controls = [playPauseButton, playlistButton]

        self.renderVideoPlayerInfo.set_token('test_token')
        self.renderVideoPlayerInfo.set_content(content)
        self.renderVideoPlayerInfo.set_controls(controls)
        self.assertEqual(self.renderVideoPlayerInfo.get_data(), self.data)
    def testSS(self):
        content = VideoPlayerInfoContent('title')
        content.set_media_length_in_milliseconds(10000)
        playPauseButton = PlayPauseButton()
        playlistButton = ShowPlayListButton()
        controls = [playPauseButton, playlistButton]

        self.renderVideoPlayerInfo.set_token('test_token')
        self.renderVideoPlayerInfo.set_content(content)
        self.renderVideoPlayerInfo.set_controls(controls)
        directives = [self.renderVideoPlayerInfo]
        directives = list(
            map(
                lambda value: value.get_data(),
                list(
                    filter(lambda value: isinstance(value, BaseDirective),
                           directives))))
        print(directives)
示例#5
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
        }
示例#6
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']
    }
    def testGetData(self):

        with open('../../json/render_audio.json', encoding='utf-8') as f:
            content = f.read()
            self.data = json.loads(content)

        print(self.data)
        content = AudioPlayerInfoContent()
        content.set_title('title')
        content.set_title_sub_text1('titleSubtext1')
        content.set_title_sub_text2('titleSubtext2')
        content.set_lyric('www.lyric.com')
        content.set_media_length_in_ms(10000)
        content.set_art('www.art.com')
        content.set_provider('provider', 'www.logo.com')

        playPauseButton = PlayPauseButton()
        repeatButton = RepeatButton()
        controls = [playPauseButton, repeatButton]

        self.renderAudioPlayerInfo.set_token('test_token')
        self.renderAudioPlayerInfo.set_content(content)
        self.renderAudioPlayerInfo.set_controls(controls)
        self.assertEqual(self.renderAudioPlayerInfo.get_data(), self.data)
示例#8
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())
示例#9
0
 def setUp(self):
     self.playPauseButton = PlayPauseButton()
     self.playPauseButton.set_enabled(False)
     self.playPauseButton.set_selected(True)