Я добавляю функцию рассылки новостей к моему навыку Alexa, и у меня возникает странное поведение, когда дело доходит до завершения аудиопотока.
tl; dr, почему звук возобновляется после выхода из навыка, даже если я приостанавливаю / останавливаю его перед выходом?
Вот пример того, что я имею в виду:
"play the newsletter."
-> the newsletter plays
"Alexa, pause"
-> PauseIntent is called, which gives a StopDirective - ending the audio.
"Exit."
-> SessionEndedRequest is received, but then the audio *starts to play again*
Единственный способ заставить его работать — это вызвать PauseIntent, а затем сказать Alexa, Stop, который вызывает намерение Stop / Cancel, которое дает директиву stop и устанавливает для should_end_session значение true.
Я подумал, что могу добавить еще один StopDirective к ответу, возвращаемому обработчиком SessionEndedRequest, но оказалось Your skill cannot return a response to SessionEndedRequest.
Ни один из моих кодов на самом деле не отличается от примера кода, поэтому мне любопытно, ожидается ли такое поведение.
Вот соответствующий код:
class PauseIntentHandler(AbstractRequestHandler):
"""Single handler for Cancel and Stop Intent."""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return ask_utils.is_intent_name("AMAZON.PauseIntent")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
logger.info('|============== Entered PauseIntent =============|')
offset = get_offset(handler_input)
set_session_attr(handler_input, 'offset', offset)
speak_output = 'Okay. You can say stop to exit, or resume to continue.'
reprompt = 'You can say stop to exit, or resume to continue.'
return (
handler_input.response_builder
.speak(speak_output)
.ask(reprompt)
.add_directive(StopDirective())
.set_should_end_session(False)
.response
class CancelOrStopIntentHandler(AbstractRequestHandler):
"""Single handler for Cancel and Stop Intent."""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return (ask_utils.is_intent_name("AMAZON.CancelIntent")(handler_input) or
ask_utils.is_intent_name("AMAZON.StopIntent")(handler_input))
def handle(self, handler_input):
# type: (HandlerInput) -> Response
logger.info('|============== Entered CancelIntent =======|')
speak_output = "Okay. Goodbye!"
return (
handler_input.response_builder
.speak(speak_output)
.add_directive(StopDirective())
.set_should_end_session(True)
.response
)
Заранее спасибо.
Связано ли это с stackoverflow.com/questions/52532272/? — person jjcurrado schedule 16.06.2021