Alexa - 在对话中说出破解文本

时间:2018-02-16 12:40:42

标签: aws-lambda alexa alexa-skills-kit alexa-voice-service

尝试为我的Alexa锻炼APP添加20秒的休息时间

我有以下输出语音

“欢迎来到有氧运动。你必须表演。二十秒内跳二次跳。准备好。三。二。一。走。我们已经完成了。让我们再做一次。不要偷懒”

function handleCardioRequest(intent, session, callback) {
        callback(session.attributes,
            buildSpeechletResponseWithoutCard("Welcome to the cardio workout. You must perform. Twenty jumping jacks in twenty seconds. Ready. Three. Two. One. <break time='20s'/> We’re done. Let’s do it again. Don’t be lazy.", "", "true"));
    }

在我的输出语音功能中,我有以下

function buildSpeechletResponse(title,output,repromptText,shouldEndSession){

    return {
        outputSpeech: {
            type: "PlainText",
            text: output,
            "type": "SSML",
            "ssml": "<speak>" + output + "</speak>"
        },
        card: {
            type: "Simple",
            title: "SessionSpeechlet - " + title,
            content: "SessionSpeechlet - " + output
        },
        reprompt: {
            outputSpeech: {
                type: "PlainText",
                text: repromptText
            }
        },
        shouldEndSession: shouldEndSession
    };
}

function buildSpeechletResponseWithoutCard(output, repromptText, shouldEndSession) {
    return {
        outputSpeech: {
            type: "PlainText",
            text: output
        },
        reprompt: {
            outputSpeech: {
                type: "PlainText",
                text: repromptText
            }
        },
        shouldEndSession: shouldEndSession
    };
}

这在用户请求有氧运动时起作用,但不是20秒的休息时间,它会说休息时间为20秒。

更新

function buildSpeechletResponseWithoutCard(output, repromptText, shouldEndSession) {
    return {
        outputSpeech: {
            "type": "SSML",
            "ssml": "<speak>" + output + "</speak>"
        },
        reprompt: {
            outputSpeech: {
                type: "PlainText",
                text: repromptText
            }
        },
        shouldEndSession: shouldEndSession
    };
}

1 个答案:

答案 0 :(得分:0)

您应该在任何非变量属性周围放置引号以确保安全。这对您的所有响应函数都是一个好主意。 因为这可能是导致错误的原因,因为它可能会将shouldEndSession: shouldEndSession视为两个变量,因此将该行返回为true: true
您希望该行返回shouldEndSession: true

试试这个:

function buildSpeechletResponseWithoutCard(output, repromptText, shouldEndSession) {
    return {
        "outputSpeech": {
            "type": "SSML",
            "ssml": "<speak>" + output + "</speak>"
        },
        "reprompt": {
            "outputSpeech": {
                "type": "SSML",
                "ssml": "<speak>" + repromptText + "</speak>"
            }
        },
        "shouldEndSession": shouldEndSession
    };
}

以下是Alexa Response Format的参考资料。它提供了一个详细记录的细分属性是什么类型,哪些是必需的。

如上所述,outputSpeech对象占用了typePlainText中的一个SSMLreprompt对象outputSpeech也是如此 我已将它们设置为SSML,因为您可以使用消息中的SSML标记自由编写回复消息。
但是,如果您从未计划使用SSML标记,则可以将该函数更改为始终输出为"type": "PlainText"

如果您仍然收到错误,请提供handleCardioRequest作为callback发送给{{1}}的功能。