【发布时间】:2021-12-02 17:21:03
【问题描述】:
我目前有一个用于天气意图的 API,但我需要翻译主要信息,如雪、太阳、雨等。有没有人知道如何在将它们发送到 speak_output 之前翻译它们?
class wetterHandler(AbstractRequestHandler):
"""Handler for Get Weather Intent."""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return ask_utils.is_intent_name("wetter")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
api_url= "http://api.openweathermap.org/data/2.5/weather?q=München&appid=b9ad6b1c8e80f623ff23a53cdd8832a9&units=metric"
json_data = requests.get(api_url).json()
weather_json = json_data['weather'][0]['main']
temp_json = round(json_data['main']['temp'] )
city = "München"
speak_output = "The weather is {} and temperature is {} °C in {}. " .format(weather_json, temp_json, city)
reprompt = "Want to try again? Or you can say cancel to quit."
handler_input.response_builder
return (
handler_input.response_builder
.speak(speak_output)
.ask(reprompt)
.response
)
【问题讨论】:
标签: python amazon-web-services alexa-skills-kit