4

我一直在构建alexa-skills-kit-js/samples/ 中的示例

但他们没有任何您将图像添加到响应卡的位置。

response.askWithCard(speechOutput, repromptOutput, cardTitle, cardContent);

图像去哪儿了?cardContent 通常是一个字符串。我只是把它变成一个包含图像的对象......?

4

2 回答 2

3

我关注了Mark Stringer 在亚马逊开发者支持论坛上对类似问题的回复:

我自己一直在努力解决这个问题,现在让它工作。如果您使用的是 Amazon 提供的示例 AlexaSkill.js 模块,那么您需要在其中添加几个部分来处理图片卡。

在 buildSpeechletResponse 部分中,在类似类型的“简单”部分之后添加:

    if (options.cardSmallImageURL && options.cardLargeImageURL) {
        alexaResponse.card = {
            type: "Standard",
            title: options.cardTitle,
            text: options.cardContent,
            image: {
                smallImageUrl: options.cardSmallImageURL,
                largeImageUrl: options.cardLargeImageURL
            }
        };
    }

然后在 askWithCard 定义之后再往下添加:

    askWithPictureCard: function(speechOutput, repromptSpeech, cardTitle, cardContent, smallImageURL, largeImageURL) {
        this._context.succeed(buildSpeechletResponse({
            session: this._session,
            output: speechOutput,
            reprompt: repromptSpeech,
            cardTitle: cardTitle,
            cardContent: cardContent,
            cardSmallImageURL: smallImageURL,
            cardLargeImageURL: largeImageURL,
            shouldEndSession: false
        }));

现在你可以调用它了,可能使用变量而不是我正在测试的常量;

response.askWithPictureCard('这是语音输出', '这是reprompt', '这是卡片标题', '这是卡片文字, 注意该字段称为文本而不是卡片内容', ' https://s3 .amazonaws.com/thisisthesmallpictureurl-small.jpg ', ' https://s3.amazonaws.com/thisisthebigpictureurl-big.jpg ');

然后按照类似的过程添加一个tellWithPictureCard 函数。

代码中有一个小错字,Stringer在他的意思是我在上面的粘贴中更正的卡片时输入了crd 。除此之外,这种方法对我有用。

于 2017-01-18T14:18:25.640 回答
0

不幸的是,看起来“简单”是硬编码的,大小图像 URL 都需要“标准”卡。这是来自的代码

https://github.com/amzn/alexa-skills-kit-js/blob/master/samples/historyBuff/src/AlexaSkill.js#L142

    if (options.cardTitle && options.cardContent) {
        alexaResponse.card = {
            type: "Simple",
            title: options.cardTitle,
            content: options.cardContent
        };
    }

您需要修改 AlexaSkill.js 的本地副本以添加该功能。

这是 Flask-Ask 库(我的)的 API 用法,展示了卡片的工作原理:

https://johnwheeler.org/flask-ask/responses.html#displaying-cards-in-the-alexa-smartphone-tablet-app

于 2016-05-31T21:00:58.410 回答