Ejemplo n.º 1
0
    def ask(self, reprompt, play_behavior=None):
        # type: (str, PlayBehavior) -> 'ResponseFactory'
        """Provide reprompt speech to the user, if no response for
        8 seconds.

        The should_end_session value will be set to false except when
        the video app launch directive is present in directives.

        :param reprompt: the output speech to reprompt.
        :type reprompt: str
        :param play_behavior: attribute to control alexa's speech
            interruption
        :type play_behavior: ask_sdk_model.ui.play_behavior.PlayBehavior
        :return: response factory with partial response being built and
            access from self.response.
        :rtype: ResponseFactory
        """
        ssml = "<speak>{}</speak>".format(self.__trim_outputspeech(
            speech_output=reprompt))
        output_speech = SsmlOutputSpeech(
            ssml=ssml, play_behavior=play_behavior)
        self.response.reprompt = Reprompt(output_speech=output_speech)
        if not self.__is_video_app_launch_directive_present():
            self.response.should_end_session = False
        return self
    def test_ask(self):
        response_factory = self.response_factory.ask(reprompt=None)

        assert response_factory.response.reprompt == Reprompt(
            output_speech=SsmlOutputSpeech(ssml="<speak></speak>")), (
                "The ask method of ResponseFactory fails to set reprompt")
        assert response_factory.response.should_end_session is False, (
            "The ask method of ResponseFactory fails to set the "
            "should_end_session to False")
    def test_ask_with_play_behavior(self):
        test_play_behavior = PlayBehavior.REPLACE_ALL
        response_factory = self.response_factory.ask(
            reprompt=None, play_behavior=test_play_behavior)

        assert response_factory.response.reprompt == Reprompt(
            output_speech=SsmlOutputSpeech(ssml="<speak></speak>",
                                           play_behavior=test_play_behavior)
        ), ("The ask method of ResponseFactory fails to set play behavior "
            "on reprompt output speech")
Ejemplo n.º 4
0
    def test_response_with_reprompt_directive(self):
        directive = RenderDocumentDirective()
        expected_response = Response(
            output_speech=SsmlOutputSpeech(ssml="<speak>Hello World</speak>"),
            reprompt=Reprompt(directives=[directive]),
            should_end_session=False)

        response_factory = self.response_factory.set_should_end_session(True).add_directive_to_reprompt(
            directive=directive).speak('Hello World')
        assert response_factory.response == expected_response, (
            "The add_directive_to_reprompt method of ResponseFactory fails to add directive")
    def add_directive_to_reprompt(self, directive):
        # type: (Directive) -> 'ResponseFactory'
        """Adds directive to reprompts.

        :param directive: the directive sent back to Alexa device.
        :type directive: ask_sdk_model.directive.Directive
        :return: response factory with partial response being built and
            access from self.response.
        :rtype: ResponseFactory
        """
        if self.response.reprompt is None:
            self.response.reprompt = Reprompt(directives=[])

        if self.response.reprompt.directives is not None:
            self.response.reprompt.directives.append(directive)

        self.set_should_end_session(False)
        return self
    def ask(self, reprompt):
        # type: (str) -> 'ResponseFactory'
        """Provide reprompt speech to the user, if no response for
        8 seconds.

        The should_end_session value will be set to false except when
        the video app launch directive is present in directives.

        :param reprompt: the output speech to reprompt.
        :type reprompt: str
        :return: response factory with partial response being built and
            access from self.response.
        :rtype: ResponseFactory
        """
        reprompt = self.__encode_ssml(reprompt)
        ssml = "<speak>{}</speak>".format(self.__trim_outputspeech(
            speech_output=reprompt))
        output_speech = SsmlOutputSpeech(ssml=ssml)
        self.response.reprompt = Reprompt(output_speech=output_speech)
        return self