Renato Pagano
Renato Pagano

Reputation: 1

Make Alexa speak the result of a request in Python

I want Alexa to speak the result of the output of get_func(). What is the correct way to pass the value on to her?

The output of get_func() is an integer.

Here is my code

class ConsultaTempIntentHandler(AbstractRequestHandler):
    """Handler for Hello World Intent."""
    def can_handle(self, handler_input):
        # type: (HandlerInput) -> bool
        return ask_utils.is_intent_name("ConsultaTempIntent")(handler_input)

    def handle(self, handler_input):
        #type: (HandlerInput) -> Response
        response_builder = handler_input.response_builder
        logging.info("LaunchRequest was trigerred")
        
        slot = ask_sdk_core.utils.request_util.get_slot(handler_input, "TempAG")
        
        if slot.value:
            temp = get_func()
            speak_output = "The tempeture is {temp} degrees"
            
            return (
               handler_input.response_builder
              #      .speak(speak_output)
                # .ask("add a reprompt if you want to keep the session open for the user to respond")
                    .response
            )        

Upvotes: 0

Views: 483

Answers (1)

Timothy Aaron
Timothy Aaron

Reputation: 3078

You need to make speak_output an f-string (by adding an "f" before the first quote)…

speak_output = f"The tempeture is {temp} degrees"

Then you need to uncomment your .speak function call…

#      .speak(speak_output)

From what I can see, everything else should work.

ps. it's spelled "temperature"

Upvotes: 2

Related Questions