如何使用Alexa APL视频组件?



我正在编写一个Alexa应用程序,并在python SDK中使用'RenderDocumentDirective'设置多模式响应。

关于信息,我在lambda函数中使用AWS托管技能。

我使用RddAPL来添加APL和RddAPLA来添加APLA。

APLA工作良好。APL停止工作了,我不知道为什么。我之前让它工作,现在我不知道是什么问题。控制台中没有错误信息。

APLA模板工作,所以这不是一个权限问题,它工作。我只是不知道发生了什么变化。如果我删除RddAPL指令,那么一切都可以正常工作。

你能帮我检查一下APL部分,看看是否有错误吗?

下面是设置应用程序文档的函数:

import config
if config.vars.APL_SUPPORTED == True:
config.apl.DOCUMENT = 'apl/myAPL.json'
config.apl.APLA_DOCUMENT = 'apl/myAPLA.json'
下面是调用apl文档的函数:
import config
from ask_sdk_model.interfaces.alexa.presentation.apl import (
RenderDocumentDirective as RddAPL)
from ask_sdk_model.interfaces.alexa.presentation.apla import (
RenderDocumentDirective as RddAPLA)
def load_apl_document(file_path):
with open(file_path) as f:
return json.load(f)
def myResponse(handler_input, speak_output):
if config.vars.APL_SUPPORTED == True:
#creates url for video
videoUrl = create_presigned_url("video/myvideo.mp4")
handler_input.response_builder.add_directive(
RddAPL(
token = 'myToken',
document = load_apl_document(config.apl.DOCUMENT),
datasources = {
"videoUrl": videoUrl
}
)
)
#creates url for audio
audioUrl = create_presigned_url("audio/myaudio.mp3")       
handler_input.response_builder.add_directive(
RddAPLA(
token = 'myToken',
document = load_apl_document(config.apl.APLA_DOCUMENT),
datasources = {
"speech": speak_output,
"audioUrl": audioUrl
}
)
)

return (
handler_input.response_builder
.set_should_end_session(False)
.response
)

else:
return (
handler_input.response_builder
.speak(speak_output)
.set_should_end_session(False)
.response
)

,这些是相关的JSON文件:

{
"type": "APL",
"version": "1.8",
"license": "Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.nSPDX-License-Identifier: LicenseRef-.amazon.com.-AmznSL-1.0nLicensed under the Amazon Software License  http://aws.amazon.com/asl/",
"settings": {},
"theme": "dark",
"import": [],
"resources": [],
"styles": {},
"onMount": [],
"graphics": {},
"commands": {},
"layouts": {},
"mainTemplate": {
"parameters": [
"payload"
],
"items": [
{
"items": [
{
"source": "${payload.videoUrl}",
"autoplay": true,
"type": "Video",
"width": "100%",
"height": "100%"
}
],
"layoutDirection": "inherit",
"alignItems": "center",
"type": "Container",
"width": "100%",
"height": "100%"
}
]
}
}
{
"type": "APLA",
"version": "0.91",
"mainTemplate": {
"parameters": [
"payload"
],
"item": [
{
"type": "Mixer",
"items": [
{
"type": "Sequencer",
"items": [
{
"type": "Audio",
"description": "The Audio component plays the provided audio file, such as an MP3 file. See docs for more information.",
"source": "soundbank://soundlibrary/a_sound_from_the_library"
},
{
"type": "Speech",
"content": "${payload.speech}"
}
]
},
{
"type": "Audio",
"source": "${payload.audioUrl}",
"duration": "trimToParent",
"filter": [
{
"type": "Volume",
"amount": "50%"
},
{
"type": "FadeOut",
"duration": 2000
}
]
}
]
}
]
}
}

经过几个小时的测试,我意识到您需要在文件夹中保存.json应用程序模板的文件__init__.py

我最后的答案实际上是错误的。

这是来自音频开发文档的APL的文本,它解释了APL文档的不同之处:

Note: For APL for Audio, use the payload parameter to bind the entire datasources object to your document. This is different from APL 1.3 for screen devices, where you can bind the mainTemplate.parameters parameter to the name of the data source instead.
因此,我将我的代码修改如下:api .json
{
"type": "APL",
"version": "1.8",
"license": "Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.nSPDX-License-Identifier: LicenseRef-.amazon.com.-AmznSL-1.0nLicensed under the Amazon Software License  http://aws.amazon.com/asl/",
"settings": {},
"theme": "dark",
"import": [],
"resources": [],
"styles": {},
"onMount": [],
"graphics": {},
"commands": {},
"layouts": {},
"mainTemplate": {
"parameters": [
"myDocumentData"
],
"items": [
{
"items": [
{
"source": "${myDocumentData.videoUrl}",
"autoplay": true,
"type": "Video",
"width": "100%",
"height": "100%"
}
],
"layoutDirection": "inherit",
"alignItems": "center",
"type": "Container",
"width": "100%",
"height": "100%"
}
]
}
}

和数据源:

#creates url for video
videoUrl = create_presigned_url("video/myvideo.mp4")
handler_input.response_builder.add_directive(
RddAPL(
token = 'myToken',
document = load_apl_document(config.apl.DOCUMENT),
datasources = {
myDocumentData: {
"videoUrl": videoUrl
}
}
)
)

最新更新