python - Alexa Skills Kit(AudioPlayer 接口):在 SessionEndedRequest 之后没有提示的音频恢复
问题描述
我一直在为我的 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 意图,它给出一个停止指令并将should_end_session设置为 true。
我以为我可以在 SessionEndedRequest 处理程序返回的响应中添加另一个 StopDirective,但事实证明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
)
提前致谢。
解决方案
推荐阅读
- php - 如何使用 Laravel 6 将数组值推送到数据库中?
- html - bash:将 html 实体转换为 UTF-8,但保留现有的 UTF-8
- excel - 根据使用 VBA 的 If 语句有粗底边框
- android - 奇怪的 AsyncTaskLoader 行为
- regex - 使用单个正则表达式删除固定模式中特定字符的多次出现
- python - 将两个列表压缩在一起 - Python
- python - 使用 python3 进行 HTTP 检索
- angular - 不是从根路径调用 Angular 应用程序
- azure-logic-apps - 如何安全地检查 JSON 对象是否存在属性
- sqlite - 根据另一张表获取一张表的计数和总和