def enqueue(handler_input):
        # type: (HandlerInput) -> Response
        response_builder = handler_input.response_builder
        type, cur_num = handler_input.request_envelope.request.token.split(' ')
        logger.info("In Controller.enqueue with " + cur_num)

        if (int(cur_num) < 1):
            logger.info("Finish")
            return handler_input.response_builder.response

        play_behavior = PlayBehavior.ENQUEUE

        if (int(cur_num) == 1):
            logger.info("Enqueue for final file")
            response_builder.add_directive(
                PlayDirective(
                    play_behavior=play_behavior,
                    audio_item=AudioItem(stream=Stream(
                        token=type + " " + str((int(cur_num) - 1)),
                        url=
                        "https://sndup.net/6vgx/Fri+Jul+24+2020+%28mp3cutnet%29.mp3",
                        offset_in_milliseconds=0,
                        expected_previous_token=handler_input.request_envelope.
                        request.token),
                                         metadata=None)))
        elif (type == "M"):
            logger.info("Enqueue for sound file")
            response_builder.add_directive(
                PlayDirective(
                    play_behavior=play_behavior,
                    audio_item=AudioItem(stream=Stream(
                        token=type + " " + str((int(cur_num) - 1)),
                        url=
                        "https://sndup.net/3qhy/Homework+%28mp3cutnet%29.mp3",
                        offset_in_milliseconds=0,
                        expected_previous_token=handler_input.request_envelope.
                        request.token),
                                         metadata=None)))
        else:
            logger.info("Enqueue for silent file")
            response_builder.add_directive(
                PlayDirective(
                    play_behavior=play_behavior,
                    audio_item=AudioItem(stream=Stream(
                        token=type + " " + str((int(cur_num) - 1)),
                        url="https://sndup.net/7n44/1-minute-of-silence.mp3",
                        offset_in_milliseconds=0,
                        expected_previous_token=handler_input.request_envelope.
                        request.token),
                                         metadata=None)))

        return response_builder.response
예제 #2
0
    def handle_playback_nearly_finished(self):
        current_episode = self.state.get_current_episode()
        if current_episode is None:
            return

        previous_episode = current_episode

        if not self.state.get_repeat():
            previous_episode = self.episodes_provider.get_previous(current_episode)

        if previous_episode is None and self.state.get_loop():
            previous_episode = self.episodes_provider.get_latest()

        if previous_episode is None:
            return

        self.handler_input.response_builder.add_directive(
            PlayDirective(
                play_behavior=PlayBehavior.ENQUEUE,
                audio_item=AudioItem(
                    stream=Stream(
                        token=previous_episode["pub"],
                        url=previous_episode["address"],
                        offset_in_milliseconds=0,
                        expected_previous_token=current_episode["pub"]),
                    metadata=None))
        ).set_should_end_session(True)
예제 #3
0
    def play(handler_input, is_playback=False):
        # type: (HandlerInput) -> Response
        playback_info = get_playback_info(handler_input)
        response_builder = handler_input.response_builder

        play_order = playback_info.get("play_order")
        offset_in_ms = playback_info.get("offset_in_ms")
        link = playback_info.get("link")
        index = playback_info.get("index")

        logger.info("In play controller")

        play_behavior = PlayBehavior.REPLACE_ALL
        #podcast = data.AUDIO_DATA[play_order[index]]
        token = play_order[index]
        playback_info['next_stream_enqueued'] = False
        response_builder.add_directive(
            PlayDirective(play_behavior=play_behavior,
                          audio_item=AudioItem(stream=Stream(
                              token=token,
                              url=link,
                              offset_in_milliseconds=offset_in_ms,
                              expected_previous_token=None),
                                               metadata=None)))

        return response_builder.response
예제 #4
0
def play(url, offset, text, data, response_builder, document, datasources,
         apl_enabled):
    """Function to play audio.
    Using the function to begin playing audio when:
        - Play Audio Intent is invoked.
        - Resuming audio when stopped / paused.
        - Next / Previous commands issues.
    https://developer.amazon.com/docs/custom-skills/audioplayer-interface-reference.html#play
    REPLACE_ALL: Immediately begin playback of the specified stream,
    and replace current and enqueued streams.
    This also adds an APL document
    """
    # Using URL as token as they are all unique
    response_builder.add_directive(
        PlayDirective(
            play_behavior=PlayBehavior.REPLACE_ALL,
            audio_item=AudioItem(
                stream=Stream(token=url,
                              url=url,
                              offset_in_milliseconds=offset,
                              expected_previous_token=None),
                metadata=add_screen_background(data) if data else None)))
    if apl_enabled:
        response_builder.add_directive(
            RenderDocumentDirective(
                token="APLTemplate",
                document=_load_apl_document(document),
                datasources=datasources)).set_should_end_session(True)
    else:
        response_builder.set_should_end_session(True)

    if text:
        response_builder.speak(text)
    return response_builder.response
예제 #5
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In PlaybackNearlyFinishedHandler")

        persistent_attr = handler_input.attributes_manager.persistent_attributes
        playback_info = persistent_attr.get("playback_info")
        playback_setting = persistent_attr.get("playback_setting")

        if playback_info.get("next_stream_enqueued"):
            return handler_input.response_builder.response

        enqueue_index = (playback_info.get("index") + 1) % len(data.AUDIO_DATA)
        if enqueue_index == 0 and not playback_setting.get("loop"):
            return handler_input.response_builder.response

        playback_info["next_stream_enqueued"] = True
        enqueue_token = playback_info.get("play_order")[enqueue_index]
        play_behavior = PlayBehavior.ENQUEUE
        podcast = data.AUDIO_DATA[enqueue_token]
        expected_previous_token = playback_info.get("token")
        offset_in_ms = 0

        handler_input.response_builder.add_directive(
            PlayDirective(play_behavior=play_behavior,
                          audio_item=AudioItem(stream=Stream(
                              token=enqueue_token,
                              url=podcast.get("url"),
                              offset_in_milliseconds=offset_in_ms,
                              expected_previous_token=expected_previous_token),
                                               metadata=None)))

        return handler_input.response_builder.response
예제 #6
0
    def handle(self, handler_input) -> Response:

        auth_response = authenticate()

        if auth_response.status_code != 200:
            handler_input.response_builder.speak("Sorry. I am unable to authenticate for Chirp API!").set_card(
                SimpleCard("Failed to send WiFi credentials!", "Unable to authenticate for Chirp API!"))\
                .set_should_end_session(True)
        else:
            speech_text = "Check it out!"
            auth_token = auth_response.json()['token']

            payload = (WIFI_SSID + ":" + WIFI_PASSWORD).encode()
            hex_payload = codecs.encode(payload, 'hex-codec').decode()
            # This endpoint will play the payload with the default protocol of your application
            # https://audio.chirp.io/v3/default
            # See more details about Chirp API at https://developers.chirp.io/connect/getting-started/audio-api/
            audio_url = "https://audio.chirp.io/v3/default/" + hex_payload + "?token=" + auth_token

            handler_input.response_builder.speak(speech_text).set_card(
                SimpleCard(
                    speech_text, "Credentials are being sent.")).add_directive(
                        PlayDirective(
                            play_behavior=PlayBehavior.REPLACE_ALL,
                            audio_item=AudioItem(
                                stream=Stream(token=auth_token,
                                              url=audio_url,
                                              offset_in_milliseconds=0,
                                              expected_previous_token=None)))
                    ).set_should_end_session(True)

        return handler_input.response_builder.response
예제 #7
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        # go to beginning of track
        logger.info("In StartOverHandler")
        persistence_attr = handler_input.attributes_manager.persistent_attributes
        track_number = int(persistence_attr["track_number"])

        audio_key = trackInfo.track_info[track_number]["url"]
        audio_url = create_presigned_url(audio_key)
        persistence_attr["playback_settings"]["offset_in_milliseconds"] = 0
        persistence_attr["playback_settings"]["url"] = audio_url
        persistence_attr["playback_settings"]["token"] = audio_key

        persistence_attr["playback_settings"]["next_stream_enqueued"] = False

        handler_input.attributes_manager.persistent_attributes = persistence_attr

        card = StandardCard(title=trackInfo.track_info[track_number]["title"],
                            text=trackInfo.track_info[track_number]["artist"],
                            image=Image(small_image_url=small_image_url,
                                        large_image_url=large_image_url))

        directive = PlayDirective(play_behavior=PlayBehavior.REPLACE_ALL,
                                  audio_item=AudioItem(stream=Stream(
                                      token=audio_key,
                                      url=audio_url,
                                      offset_in_milliseconds=0,
                                      expected_previous_token=None),
                                                       metadata=None))

        handler_input.response_builder.set_card(card).add_directive(
            directive).set_should_end_session(True)

        return handler_input.response_builder.response
예제 #8
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In PlayMetronomeHandler")

        tempo = int(get_slot_value(handler_input, "tempo"))
        if tempo < 20 or tempo > 240:
            handler_input.response_builder.speak(strings.TEMPO_NOT_IN_RANGE)
            return handler_input.response_builder.response

        duration = (get_slot_value(handler_input, "duration")
                    or strings.DEFAULT_DURATION)
        seconds = iso_8601_duration_to_seconds(duration)
        if seconds < 10 or seconds > 600:
            handler_input.response_builder.speak(strings.DURATION_NOT_IN_RANGE)
            return handler_input.response_builder.response

        logger.info("tempo={} duration={} seconds={}".format(
            tempo, duration, seconds))

        speak = strings.PLAYING.format(
            tempo, "{}'{}\"".format(int(seconds / 60), seconds % 60))

        data = {
            "card": {
                "title": strings.SKILL_NAME,
                "text": strings.CARD_TEXT.format(tempo),
                "small_image_url": strings.ICON_URL,
                "large_image_url": strings.ICON_URL
            },
            "url": get_metronome_url(tempo, seconds),
        }

        card = StandardCard(
            title=data["card"]["title"],
            text=data["card"]["text"],
            image=Image(small_image_url=data["card"]["small_image_url"],
                        large_image_url=data["card"]["large_image_url"]))

        directive = PlayDirective(
            play_behavior=PlayBehavior.REPLACE_ALL,
            audio_item=AudioItem(
                stream=Stream(expected_previous_token=None,
                              token=data["url"],
                              url=data["url"],
                              offset_in_milliseconds=0),
                metadata=AudioItemMetadata(
                    title=data["card"]["title"],
                    subtitle=data["card"]["text"],
                    art=display.Image(
                        content_description=data["card"]["title"],
                        sources=[display.ImageInstance(url=strings.ICON_URL)]),
                    background_image=display.Image(
                        content_description=data["card"]["title"],
                        sources=[display.ImageInstance(url=strings.ICON_URL)
                                 ]))))
        (handler_input.response_builder.speak(speak).set_card(
            card).add_directive(directive).set_should_end_session(True))
        return handler_input.response_builder.response
    def play(handler_input, num_minutes, with_music):
        # type: (HandlerInput) -> Response
        logger.info("In Controller.play with " + str(num_minutes))
        response_builder = handler_input.response_builder

        play_behavior = PlayBehavior.REPLACE_ALL

        if with_music:
            s3Key = "Media/musicPreference.txt"
            obj = s3.get_object(
                Bucket='391494fe-6b75-43db-89eb-a22dad514b56-us-east-1',
                Key=s3Key)
            data = obj['Body'].read()
            contents = data.decode('utf-8')
            dataDict = json.loads(contents)

            musicUrl = dataDict["musicPreference"]

            response_builder.add_directive(
                PlayDirective(play_behavior=play_behavior,
                              audio_item=AudioItem(
                                  stream=Stream(token="M " + str(num_minutes),
                                                url=musicUrl,
                                                offset_in_milliseconds=0,
                                                expected_previous_token=None),
                                  metadata=None))).set_should_end_session(True)
            response_builder.speak("Ok, playing study music")
        else:
            response_builder.add_directive(
                PlayDirective(
                    play_behavior=play_behavior,
                    audio_item=AudioItem(stream=Stream(
                        token="S " + str(num_minutes),
                        url="https://sndup.net/7n44/1-minute-of-silence.mp3",
                        offset_in_milliseconds=0,
                        expected_previous_token=None),
                                         metadata=None))
            ).set_should_end_session(True)
            response_builder.speak(
                "Ok, I will let you know when your timer is over.")

        return response_builder.response
예제 #10
0
 def handle(self, handler_input):
     handler_input.response_builder.add_directive(
         PlayDirective(
             play_behavior=PlayBehavior.REPLACE_ALL,
             audio_item=AudioItem(stream=Stream(
                 token=
                 "https://samarthalexasongbucket.s3.eu-west-2.amazonaws.com/matargashti.mp3",
                 url=
                 "https://samarthalexasongbucket.s3.eu-west-2.amazonaws.com/matargashti.mp3",
                 expected_previous_token=None))))
     return handler_input.response_builder.response
예제 #11
0
    def getNotImplementedResponse(self):
        """Plays an audio announcement that this feature is forthcoming.

        Until a shared calendar is in place, I cannot look up calendar events.
        So that the user knows that this feature is coming, this plays a nice
        song with a happy announcer telling the user that the feature is on
        its way.

        Args:
            N/A

        Raises:
            N/A

        Returns:
            str, str, str, ask_sdk_model.interfaces.audioplayer.PlayDirective, dict
            The speech for Alexa to speak,
            the title to display on the card,
            the text to display on the card,
            the play directive telling Alexa what audio file to play,
            session attributes to be passed to Alexa.

        """
        url = "https://st-killian-resources.s3.amazonaws.com/calendarGeneric_mixdown.mp3"
        token = "calendarGeneric_mixdown"
        speech = ""
        title = "St. Kilian calendar events"
        text = "Calendar events coming soon! Watch the bulletin for news."
        self.userSession.lastToken = token
        self.userSession.lastTrack = url
        self.userSession.savePersistentAttrs()

        sessionAttrs = {
            "lastTrack": url,
            "lastToken": token
        }
        directive = PlayDirective(
            play_behavior=PlayBehavior.REPLACE_ALL,
            audio_item=AudioItem(
                stream=Stream(
                    expected_previous_token=None,
                    token=token,
                    url=url,
                    offset_in_milliseconds=0
                ),
                metadata=AudioItemMetadata(
                    title="Calendar Events",
                    subtitle=text
                )
            )
        )
        return speech, title, text, directive, sessionAttrs
예제 #12
0
 def handle(self, handler_input):
     """
     Creates a response for the given input
     Args:
         handler_input(HandlerInput): The input to the handler
     Returns: (Response) The response
     """
     handler_input.response_builder.add_directive(
         PlayDirective(
             PlayBehavior.REPLACE_ALL,
             AudioItem(Stream(token="lyra_token", url="https://"),
                       AudioItemMetadata("Highway to hell"))))
     return handler_input.response_builder.response
예제 #13
0
    def handle(self, handler_input):

        for key in s3_result['Contents']:
            handler_input.response_builder.add_directive(
                PlayDirective(
                    play_behavior=PlayBehavior.REPLACE_ALL,
                    audio_item=AudioItem(stream=Stream(
                        token=key,
                        url=
                        "https://samarthalexasongbucket.s3.eu-west-2.amazonaws.com/alexa/%"
                        % (key),
                        expected_previous_token=None))))
        return handler_input.response_builder.response
예제 #14
0
    def handle(self, handler_input):
        language_prompts = handler_input.attributes_manager.request_attributes[
            "_"]
        persistent_attributes = handler_input.attributes_manager.persistent_attributes

        playlist = persistent_attributes['playlist']
        loop = persistent_attributes["playback_session_data"]["loop"]
        index = int(persistent_attributes["playback_session_data"]["index"])

        if index != 0:
            index -= 1
        elif (index == 0) and loop:
            index = len(playlist) - 1
        else:
            speech_output = speech_output = random.choice(
                language_prompts["START_OF_PLAYLIST"])
            return handler_input.response_builder.speak(
                speech_output).set_should_end_session(True).response

        token = playlist[index]['token']
        url = playlist[index]['url']
        offset = 0
        title = playlist[index]['title']
        subtitle = "Episode {}".format(token)
        persistent_attributes["playback_session_data"].update({
            'token':
            token,
            'url':
            playlist[index]['url'],
            'offset':
            offset,
            'title':
            playlist[index]['title'],
            'index':
            index
        })
        handler_input.attributes_manager.save_persistent_attributes()

        audio_directive = PlayDirective(
            play_behavior=PlayBehavior.REPLACE_ALL,
            audio_item=AudioItem(stream=Stream(
                token=token,
                url=url,
                offset_in_milliseconds=offset,
            ),
                                 metadata=AudioItemMetadata(
                                     title=title, subtitle=subtitle)))

        return (handler_input.response_builder.add_directive(
            audio_directive).set_should_end_session(True).response)
예제 #15
0
    def handle(self, handler_input):
        # get state from Dynamo
        item = awsutils.get_offset(
            handler_input.request_envelope.session.user.user_id)

        handler_input.response_builder.add_directive(
            PlayDirective(
                play_behavior=PlayBehavior.REPLACE_ALL,
                audio_item=AudioItem(
                    stream=Stream(token=item['Url'],
                                  url=item['Url'],
                                  offset_in_milliseconds=item['Offset'],
                                  expected_previous_token=None)))
        ).set_should_end_session(True)
        return handler_input.response_builder.response
예제 #16
0
    def play(self, episode):
        if episode is None:
            return False

        self.handler_input.response_builder.add_directive(
            PlayDirective(
                play_behavior=PlayBehavior.REPLACE_ALL,
                audio_item=AudioItem(
                    stream=Stream(
                        token=episode["pub"],
                        url=episode["address"],
                        offset_in_milliseconds=self.state.get_offset(),
                        expected_previous_token=None),
                    metadata=None))
        ).set_should_end_session(True)

        return True
예제 #17
0
    def play(handler_input, filename):
        # type: (HandlerInput) -> Response

        response_builder = handler_input.response_builder
        play_behavior = PlayBehavior.REPLACE_ALL
        audioUrl = "https://inanutshell-mediafiles.s3.amazonaws.com/" + filename + ".mp3"
        speech = "playing " + filename + " audio file"
        response_builder.speak(speech).add_directive(
            PlayDirective(play_behavior=play_behavior,
                          audio_item=AudioItem(
                              stream=Stream(token=0,
                                            url=audioUrl,
                                            offset_in_milliseconds=0,
                                            expected_previous_token=None),
                              metadata=None))).set_should_end_session(True)

        return response_builder.response
예제 #18
0
    def play(handler_input, is_playback=False):
        # type: (HandlerInput) -> Response
        playback_info = get_playback_info(handler_input)
        response_builder = handler_input.response_builder

        play_order = playback_info.get("play_order")
        offset_in_ms = playback_info.get("offset_in_ms")
        index = playback_info.get("index")

        play_behavior = PlayBehavior.REPLACE_ALL
        podcast = data.AUDIO_DATA[play_order[index]]
        token = play_order[index]
        playback_info['next_stream_enqueued'] = False

        response_builder.add_directive(
            PlayDirective(
                play_behavior=play_behavior,
                audio_item=AudioItem(
                    stream=Stream(
                        token=token,
                        url=podcast.get("url"),
                        offset_in_milliseconds=offset_in_ms,
                        expected_previous_token=None),
                    metadata=None))
        ).set_should_end_session(True)

        if not is_playback:
            # Add card and response only for events not triggered by
            # Playback Controller
            handler_input.response_builder.speak(
                data.PLAYBACK_PLAY.format(podcast.get("title")))

            if can_throw_card(handler_input):
                response_builder.set_card(StandardCard(
                    title=data.PLAYBACK_PLAY_CARD.format(
                        podcast.get("title")),
                    text=data.PLAYBACK_PLAY_CARD.format(
                        podcast.get("title")),
                    image=Image(
                        small_image_url="https://quisutdeusapp.altervista.org/sanmichele_108.png",
                        large_image_url="https://quisutdeusapp.altervista.org/sanmichele_512.png"
                    )
                ))

        return response_builder.response
예제 #19
0
    def handle(self, handler_input):
        language_prompts = handler_input.attributes_manager.request_attributes[
            "_"]
        persistent_attributes = handler_input.attributes_manager.persistent_attributes

        if persistent_attributes.get("playback_session_data") is not None:
            token = persistent_attributes["playback_session_data"]['token']
            url = persistent_attributes["playback_session_data"]['url']
            offset = persistent_attributes["playback_session_data"]["offset"]
            title = persistent_attributes["playback_session_data"]["title"]
            subtitle = "Episode {}".format(token)

        else:
            playlist = populate_playlist_from_rss(rss_url)
            index = len(playlist) - 1
            token = playlist[index]['token']
            url = playlist[index]['url']
            offset = 0
            title = playlist[index]['title']
            subtitle = "Episode {}".format(token)

            handler_input.response_builder.speak(
                random.choice(language_prompts["PLAY_LATEST_EPISODE"]))

            persistent_attributes['playlist'] = playlist
            persistent_attributes["playback_session_data"] = {
                'token': token,
                'url': url,
                'offset': offset,
                'title': title,
                'index': index,
                'loop': False,
                'shuffle': False
            }
            handler_input.attributes_manager.save_persistent_attributes()

        audio_directive = PlayDirective(
            play_behavior=PlayBehavior.REPLACE_ALL,
            audio_item=AudioItem(stream=Stream(token=token,
                                               url=url,
                                               offset_in_milliseconds=offset),
                                 metadata=AudioItemMetadata(
                                     title=title, subtitle=subtitle)))
        return (handler_input.response_builder.add_directive(
            audio_directive).set_should_end_session(True).response)
예제 #20
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In PlaybackNearlyFinishedHandler")

        audio_key = "Media/RemovalMen_Borderline.mp3"

        audio_url = create_presigned_url(audio_key)

        directive = PlayDirective(play_behavior=PlayBehavior.REPLACE_ENQUEUED,
                                  audio_item=AudioItem(stream=Stream(
                                      token=audio_key,
                                      url=audio_url,
                                      offset_in_milliseconds=0,
                                      expected_previous_token=None),
                                                       metadata=None))
        handler_input.response_builder.set_card(card).add_directive(
            directive).set_should_end_session(True)
        return handler_input.response_builder.response
예제 #21
0
    def handle(self, handler_input):
        language_prompts = handler_input.attributes_manager.request_attributes[
            "_"]
        persistent_attributes = handler_input.attributes_manager.persistent_attributes

        print("REACHED THIS POINT")

        if persistent_attributes["playback_session_data"]["next_track_queued"]:
            return handler_input.response_builder.response

        playlist = persistent_attributes['playlist']
        loop = persistent_attributes["playback_session_data"]["loop"]
        index = int(persistent_attributes["playback_session_data"]["index"])

        if index != len(playlist) - 1:
            index += 1
        elif (index == len(playlist) - 1) and loop:
            index = 0
        else:
            return handler_input.response_builder.response

        old_token = persistent_attributes["playback_session_data"]["token"]
        new_token = playlist[index]['token']
        url = playlist[index]['url']
        offset = 0
        title = playlist[index]['title']
        subtitle = "Episode {}".format(new_token)
        persistent_attributes["playback_session_data"].update(
            {'next_track_queued': True})
        handler_input.attributes_manager.save_persistent_attributes()
        #persistent_attributes["playback_session_data"].update({ 'next_track_queued': True, 'token': new_token, 'url': playlist[index]['url'], 'offset': offset, 'title': playlist[index]['title'], 'index': index})
        #handler_input.attributes_manager.save_persistent_attributes()

        audio_directive = PlayDirective(
            play_behavior=PlayBehavior.ENQUEUE,
            audio_item=AudioItem(
                stream=Stream(token=new_token,
                              url=url,
                              offset_in_milliseconds=offset,
                              expected_previous_token=old_token),
                metadata=AudioItemMetadata(title=title, subtitle=subtitle)))
        print(audio_directive)
        return (handler_input.response_builder.add_directive(
            audio_directive).response)
예제 #22
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("in AudioPlayIntent")
        speech_text = "Welcome to my audio player"
        audio_key = "Media/RemovalMen_Borderline.mp3"

        audio_url = create_presigned_url(audio_key)

        directive = PlayDirective(play_behavior=PlayBehavior.REPLACE_ALL,
                                  audio_item=AudioItem(stream=Stream(
                                      token=audio_key,
                                      url=audio_url,
                                      offset_in_milliseconds=0,
                                      expected_previous_token=None),
                                                       metadata=None))
        handler_input.response_builder.speak(speech_text).set_card(
            card).add_directive(directive).set_should_end_session(True)

        return handler_input.response_builder.response
예제 #23
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        print("PlayRadio...")

        handler_input.response_builder.set_card(
            StandardCard(title="FIP Rock", text="La radio InRock"))
        handler_input.response_builder.add_directive(
            PlayDirective(
                play_behavior=PlayBehavior.REPLACE_ALL,
                audio_item=AudioItem(stream=Stream(
                    token="France Inter",
                    url=
                    "https://chai5she.cdn.dvmr.fr/fip-webradio1.mp3?ID=radiofrance",
                    offset_in_milliseconds=0,
                    expected_previous_token=None),
                                     metadata=None))).set_should_end_session(
                                         False)
        handler_input.response_builder.speak("En avant la musique")
        return handler_input.response_builder.response
예제 #24
0
def play_later(url, card_data, response_builder):
    """Play the stream later.

    https://developer.amazon.com/docs/custom-skills/audioplayer-interface-reference.html#play
    REPLACE_ENQUEUED: Replace all streams in the queue. This does not impact the currently playing stream.
    """
    # type: (str, Dict, ResponseFactory) -> Response
    # Using URL as token as they are all unique
    response_builder.add_directive(
        PlayDirective(play_behavior=PlayBehavior.REPLACE_ENQUEUED,
                      audio_item=AudioItem(
                          stream=Stream(token=url[len(url) - 20:len(url) - 1],
                                        url=url,
                                        offset_in_milliseconds=0,
                                        expected_previous_token=None),
                          metadata=add_screen_background(card_data) if
                          card_data else None))).set_should_end_session(True)

    return response_builder.response
 def handle(self,handler_input):
     stream = STREAMS[0]
     return ( handler_input.response_builder
                 .add_directive(
                     PlayDirective(
                         play_behavior=PlayBehavior.REPLACE_ALL,
                         audio_item=AudioItem(
                             stream=Stream(
                                 token=stream["token"],
                                 url=stream["url"],
                                 offset_in_milliseconds=0,
                                 expected_previous_token=None),
                             metadata=stream["metadata"]
                         )
                     )
                 )
                 .set_should_end_session(True)
                 .response
             )
예제 #26
0
 def handle(self, handler_input):
     """
     Creates a response for the given input
     Args:
         handler_input(HandlerInput): The input to the handler
     Returns: (Response) The response
     """
     pellicula_slot = get_most_probable_value_for_slot(
         handler_input, "pellicula")
     if pellicula_slot is None:
         handler_input.response_builder.add_directive(
             PlayDirective(
                 PlayBehavior.REPLACE_ALL,
                 AudioItem(Stream(token="cantare_token", url="https://"),
                           AudioItemMetadata("Highway to hell"))))
     else:
         handler_input.response_builder \
             .add_directive(LaunchDirective(VideoItem("https://", Metadata("Orpheus et Eurydike"))))
     return handler_input.response_builder.response
예제 #27
0
    def handle(self, handler_input):
        language_prompts = handler_input.attributes_manager.request_attributes[
            "_"]
        persistent_attributes = handler_input.attributes_manager.persistent_attributes

        playlist = populate_playlist_from_rss(rss_url)
        token = handler_input.request_envelope.request.intent.slots[
            "EpisodeNumber"].value
        if token is None:
            token = handler_input.request_envelope.request.intent.slots[
                "OrdinalNumber"].value
        index = int(token) - 1
        url = playlist[index]['url']
        offset = 0
        title = playlist[index]['title']
        subtitle = "Episode {}".format(token)
        persistent_attributes['playlist'] = playlist
        persistent_attributes["playback_session_data"] = {
            'next_track_queued': False,
            'token': token,
            'url': url,
            'offset': offset,
            'title': title,
            'index': index,
            'loop': False,
            'shuffle': False
        }
        handler_input.attributes_manager.save_persistent_attributes()

        speech_output = random.choice(
            language_prompts["PLAYING_CHOSEN_EPISODE"]).format(token)

        audio_directive = PlayDirective(
            play_behavior=PlayBehavior.REPLACE_ALL,
            audio_item=AudioItem(stream=Stream(token=token,
                                               url=url,
                                               offset_in_milliseconds=offset),
                                 metadata=AudioItemMetadata(
                                     title=title, subtitle=subtitle)))
        return (
            handler_input.response_builder.speak(speech_output).add_directive(
                audio_directive).set_should_end_session(True).response)
예제 #28
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        speech_output = "Welcome to the long dark -- 24 hours of Winter Solstice audio."
        card_title = "Winter Solstice on Dos Burros"
        card_text = "Welcome to the long dark -- 24 hours of Winter Solstice audio."
        small_image = 'https://wiki.dosburros.com/images/2/29/PathInTheDark.jpg'
        large_image = 'https://wiki.dosburros.com/images/2/29/PathInTheDark.jpg'
        stream_url = 'https://raw.githubusercontent.com/kjoenth/Goofing/master/test.m3u'

        theDirective = PlayDirective(
            play_behavior=PlayBehavior.REPLACE_ALL,
            audio_item=AudioItem(stream=Stream(expected_previous_token=None,
                                               token=stream_url,
                                               url=stream_url,
                                               offset_in_milliseconds=0)))

        return (handler_input.response_builder.speak(
            speech_output).add_directive(theDirective).set_card(
                ui.StandardCard(card_title, card_text,
                                ui.Image(small_image, large_image))).response)
예제 #29
0
def play_morning_call_intent_handler(handler_input):
    """Handler for Play Morning Call Intent."""
    # type: (HandlerInput) -> Response

    assistant = SafraAssistant.deserialize(handler_input.attributes_manager.session_attributes.get("assistant"))
    (speech_text, url) = assistant.play_morning_call()

    return handler_input.response_builder.speak(speech_text).set_card(
        SimpleCard("Easy Safra", speech_text)).add_directive(
        PlayDirective(
            play_behavior=PlayBehavior.REPLACE_ALL,
            audio_item=AudioItem(
                stream=Stream(
                    token=url,
                    url=url,
                    offset_in_milliseconds=0,
                    expected_previous_token=None)
            )
        )
    ).set_should_end_session(True).response
예제 #30
0
    def handle(self, handler_input):
        persistent_attributes = handler_input.attributes_manager.persistent_attributes

        playlist = persistent_attributes['playlist']
        token = persistent_attributes["playback_session_data"]["token"]
        url = persistent_attributes["playback_session_data"]["url"]
        offset = 0
        title = persistent_attributes["playback_session_data"]["title"]
        subtitle = "Episode {}".format(token)

        audio_directive = PlayDirective(
            play_behavior=PlayBehavior.REPLACE_ALL,
            audio_item=AudioItem(stream=Stream(token=token,
                                               url=url,
                                               offset_in_milliseconds=offset),
                                 metadata=AudioItemMetadata(
                                     title=title, subtitle=subtitle)))
        logger.info("Playback Failed: {}".format(
            handler_input.request_envelope.request.error))
        return (handler_input.response_builder.add_directive(
            audio_directive).set_should_end_session(True).response)