Example #1
0
    def handle(self, handler_input):
        """Handle the request.

        In case we need to resume this playback later, we need to store
        the track being played along with its offset in time, expressed as
        milliseconds offset from zero. We then need to build and deliver
        the stop directive.

        Ends session as is required by the AudioPlayer.

        Args:
            handler_input (ask_sdk_core.handler_input.HandlerInput):
                Input from Alexa.

        """
        msg = "Cancel, Stop, or Pause intent received."
        LOGGER.info(msg)

        env = handler_input.request_envelope
        audioPlayer = env.context.audio_player
        if audioPlayer.to_dict().get("player_activity") == "STOPPED":
            LOGGER.info("Audio player has been stopped.")
            oim = audioPlayer.to_dict().get("offset_in_milliseconds", 0)
            userSession = session.KilianUserSession(handler_input)
            userSession.offsetInMilliseconds = oim
            LOGGER.info("Saving offset of {} milliseconds".format(oim))
            userSession.savePersistentAttrs()

        directive = StopDirective()
        handler_input.response_builder.add_directive(directive)
        handler_input.response_builder.set_should_end_session(True)

        return handler_input.response_builder.response
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In AudioStopIntentHandler")

        (handler_input.response_builder.speak(
            strings.STOP_MESSAGE).add_directive(StopDirective()))
        return handler_input.response_builder.response
 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(StopDirective())
     return handler_input.response_builder.response
Example #4
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        speech_text = "Goodbye"

        directive = StopDirective()

        handler_input.response_builder.speak(speech_text).add_directive(
            directive).set_should_end_session(True)
        return handler_input.response_builder.response
 def handle(self, handler_input):
     return ( handler_input.response_builder
                 .add_directive(
                     ClearQueueDirective(
                         clear_behavior=ClearBehavior.CLEAR_ALL)
                     )
                 .add_directive(StopDirective())
                 .set_should_end_session(True)
                 .response
             )
Example #6
0
def stop(text, response_builder):
    """Issue stop directive to stop the audio.
    Issuing AudioPlayer.Stop directive to stop the audio.
    Attributes already stored when AudioPlayer.Stopped request received.
    """
    response_builder.add_directive(StopDirective())
    if text:
        response_builder.speak(text)

    return response_builder.set_should_end_session(True).response
Example #7
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("in AudioStopIntent and request")
        logger.info(handler_input.request_envelope.request)
        speech_text = "Goodbye"

        directive = StopDirective()

        handler_input.response_builder.speak(speech_text).add_directive(
            directive).set_should_end_session(True)
        return handler_input.response_builder.response
Example #8
0
def stop(text, response_builder):
    """Issue stop directive to stop the audio.

    Issuing AudioPlayer.Stop directive to stop the audio.
    Attributes already stored when AudioPlayer.Stopped request received.
    """
    # type: (str, ResponseFactory) -> Response
    response_builder.add_directive(StopDirective())
    if text:
        response_builder.speak(text)

    return response_builder.response
Example #9
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("in AudioStopIntent")
        speech_text = "Paused"
        # Note when your skill is playing audio, utterances such as 'stop' send your skill an AMAZON.PauseIntent instead of an AMAZON.StopIntent
        # so you can't easily just say goodbye when user says 'stop'

        directive = StopDirective()
        # this causes PlaybackStopped request which saves current offset

        handler_input.response_builder.speak(speech_text).add_directive(
            directive).set_should_end_session(True)
        return handler_input.response_builder.response
Example #10
0
    def handle(self, handler_input):
        # type: (handler_input) -> Response

        logger.info(">>>>> In CancelOrStopIntentHandler")
        locale = ask_utils.get_locale(handler_input)
        with open("language_strings.json") as language_prompts:
            language_data = json.load(language_prompts)
        try:
            loc_data = language_data[locale[:2]]
            skill_name = loc_data['SKILL_NAME']
        except KeyError:
            loc_data = language_data['en']
            skill_name = loc_data['SKILL_NAME']
        speak_output = loc_data['GOODBYE']
        directive = StopDirective()

        return (handler_input.response_builder.speak(speak_output).
                add_directive(directive).set_should_end_session(True).response)
Example #11
0
    def play_next(handler_input, is_playback=False):
        persistent_attr = handler_input.attributes_manager.persistent_attributes

        playback_info = persistent_attr.get("playback_info")
        playback_setting = persistent_attr.get("playback_setting")
        next_index = (playback_info.get("index") + 1) % len(data.AUDIO_DATA)

        if next_index == 0 and not playback_setting.get("loop"):
            if not is_playback:
                handler_input.response_builder.speak(data.PLAYBACK_NEXT_END)

            return handler_input.response_builder.add_directive(
                StopDirective()).response

        playback_info["index"] = next_index
        playback_info["offset_in_ms"] = 0
        playback_info["playback_index_changed"] = True

        return Controller.play(handler_input, is_playback)
Example #12
0
    def play_previous(handler_input, is_playback=False):
        persistent_attr = handler_input.attributes_manager.persistent_attributes

        playback_info = persistent_attr.get("playback_info")
        playback_setting = persistent_attr.get("playback_setting")
        prev_index = playback_info.get("index") - 1

        if prev_index == -1:
            if playback_setting.get("loop"):
                prev_index += len(data.AUDIO_DATA)
            else:
                if not is_playback:
                    handler_input.response_builder.speak(
                        data.PLAYBACK_PREVIOUS_END)

                return handler_input.response_builder.add_directive(
                    StopDirective()).response

        playback_info["index"] = prev_index
        playback_info["offset_in_ms"] = 0
        playback_info["playback_index_changed"] = True

        return Controller.play(handler_input, is_playback)
Example #13
0
    def handle(self, handler_input):
        audio_directive = StopDirective()

        return (handler_input.response_builder.add_directive(
            audio_directive).set_should_end_session(True).response)
Example #14
0
 def stop(handler_input):
     # type: (HandlerInput) -> Response
     handler_input.response_builder.add_directive(StopDirective())
     return handler_input.response_builder.response
Example #15
0
 def stop(handler_input):
     handler_input.response_builder.add_directive(StopDirective())
     return handler_input.response_builder.response
Example #16
0
 def stop(self):
     self.handler_input.response_builder.add_directive(StopDirective())
Example #17
0
 def handle(self, handler_input):
     logger.info("In PauseIntentHandle")
     logger.info(handler_input.request_envelope.request.__repr__())
     handler_input.response_builder.add_directive(StopDirective())
     return handler_input.response_builder.response