【问题标题】:Alexa LaunchRequest is never triggered永远不会触发 Alexa LaunchRequest
【发布时间】:2021-05-22 21:56:41
【问题描述】:

我正在使用 Alexa 技能包的 ask-sdk-core。我有以下 LaunchRequestHandler 和 AudioIntentHandler。我遇到的问题是,当我通过说“Alexa,与 SkillName 交谈”或“Alexa,开始 SkillName”来触发技能时,请求以某种方式发送 AudioIntent 而不是 LaunchRequest 到 lambda 函数,因此,音频流开始播放.我能够通过开发者控制台触发正常行为和错误行为。

const LaunchRequestHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
    },
    handle(handlerInput) {
        const speakOutput = 'This message should be replied if the user launches the skill';
        return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(speakOutput)
            .addAudioPlayerStopDirective()
            .getResponse();
    }
};

还有其他几个 IntentHandler。其中一个 IntentHandler 启动音频流。

const AudioIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && (Alexa.getIntentName(handlerInput.requestEnvelope) === 'AudioIntent'
            || Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.NextIntent'
            || Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.PreviousIntent');
    },
    handle(handlerInput) {
        // this code should only be triggered if an utterance of the intent has been said and 
        // not on launch
        const streamId = crypto.randomBytes(16).toString("hex");
        return handlerInput.responseBuilder
            .addAudioPlayerPlayDirective('REPLACE_ALL', mediaPath, streamId, 0, null, null)
            .withShouldEndSession(true)
            .getResponse();
    }
};

ResumeIntentHandler 支持音频意图处理程序

const AudioResumeIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.ResumeIntent';
    },
    handle(handlerInput) {
        // this code should only be triggered if an utterance of the intent has been said and 
        // not on launch
        const streamId = crypto.randomBytes(16).toString("hex");
        return handlerInput.responseBuilder
            .addAudioPlayerPlayDirective('REPLACE_ALL', mediaPath, streamId, 0, null, null)
            .withShouldEndSession(true)
            .getResponse();
    }
};

还有下面的 AudioPlayer 处理程序

const AudioRequestHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope).includes('AudioPlayer.');
    },
    handle(handlerInput) {
        console.log(`AudioRequestHandler: ${handlerInput.requestEnvelope}`)
        
        if(Alexa.getRequestType(handlerInput.requestEnvelope) === 'AudioPlayer.PlaybackFailed') {
            console.log("Playback Failed : " + JSON.stringify(handlerInput.requestEnvelope.request.error, null, 2));
            return handlerInput.responseBuilder
                .speak('Something went wrong')
                .getResponse();
        } 
        return handlerInput.responseBuilder
            .getResponse();
    }
};

该技能在一次射击时按预期发挥作用,例如Aelxa,向 SkillName 寻求帮助。我能够达到我所有的非音频意图。还可以帮助意图、取消、停止等按预期工作。为什么启动时会触发音频 Intent?

exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(
    LaunchRequestHandler,
    AudioRequestHandler,
    AudioPauseIntentHandler,
    AudioResumeIntentHandler,
    NormalReplyIntentHandler,
    AudioIntentHandler,
    HelpIntentHandler,
    CancelAndStopIntentHandler,
    FallbackIntentHandler,
    SessionEndedRequestHandler,
    IntentReflectorHandler)
.addErrorHandlers(
    ErrorHandler)
.lambda();

我添加了更好的日志记录。错误行为似乎发生在用户第二次启动该技能之后。第一个技能交互效果很好。之后,“start SkillName”触发“AudioIntentHandler”。请求如下所示:

type: IntentRequest
intent: {
  name: AudioIntent
  confirmationStatus: NONE
}

所以在我看来,我的 addRequestHandlers 不是这里的问题,因为它的 Alexa 发送了错误的意图。 AudioIntentHandler 根据错误请求正确触发。

错误请求包含 AudioPlayer 信息。可能来自与该技能的最后一次(第一次交互)。我相信这可能是错误的来源?

AudioPlayer {
   offsetInMilliseconds: 3239,
   playerActivity: STOPPED,
}

如果用户启动技能并且 Alexa 检测到存在停止的音频,Alexa 是否会继续使用音频意图?我在暂停或停止时没有正确清除音频播放器吗?

const AudioPauseIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.PauseIntent';
    },
    handle(handlerInput) {
        console.log('AudioPauseIntentHandler')
        const speakOutput = 'Audio stopped.';

        return handlerInput.responseBuilder
            .speak(speakOutput)
            .addAudioPlayerStopDirective()
            .addAudioPlayerClearQueueDirective('CLEAR_ALL')
            .getResponse();
    }
};

【问题讨论】:

  • 那么在开发者控制台中,当您产生错误行为时,每次都是准确的措辞吗?您是否还可以从您的.addRequestHandlers 的索引文件中提供一个excert。这里的顺序有时是个问题。您是否也尝试过添加!== 'LaunchRequest'?在开发者控制台中,当您“失败”时,您的 requestEnvelope 是什么。
  • 我在上面更新了我的问题。你能再看看吗?非常感谢您的支持!
  • 很高兴第一个建议有所帮助。我没有使用流对 Alexa 进行任何开发,但是整个主题和用法都非常一致。我已经看到文档表明您不能在同一个响应中发送多个音频指令。我对其他指令也有类似的问题。我会看看是否能找到更多细节,但我会从那里开始。这是一个很好的话题和问题。如果你弄明白了,请务必在这里回复。

标签: javascript aws-lambda alexa alexa-skills-kit ask-sdk


【解决方案1】:

我发现了问题。据我所知,这与我的 Skill.json 或 lambda 代码无关。这是 Alexa 的事情,我能够在其他 Alexa 技能中重现同样的怪异行为。

我主要是用德语测试。在英语中,我通常使用以下唤醒词开始技能:

  • Alexa,与技能名称交谈
  • Alexa,开始技能名称

这就是问题所在。在德语中,只有“开始”又名。 “开始”有效。 “交谈”又名。 “spreche mit”似乎随机触发技能内的意图,而不是 LaunchRequest。

我使用第三方技能对此进行了测试,并且能够重现奇怪的行为。

=> 修正:在德语中,以“Alexa,starte Skillname”而不是“Alexa,spreche mit Skillname”开始技能。

【讨论】:

    猜你喜欢
    • 2014-05-15
    • 2015-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-19
    • 2016-06-12
    相关资源
    最近更新 更多