简体   繁体   English

如何在 Alexa 中使用没有插槽的 Intent Chaining?

[英]How to use Intent Chaining without slots in Alexa?

I am trying to create an Alexa skill.我正在尝试创建 Alexa 技能。 I only have one intent (LightOnIntent) that it will play audio.我只有一个意图 (LightOnIntent) 它将播放音频。 I wanted the user to just start the skill and immediately be redirected to the intent for the audio (without the user saying anything else).我希望用户刚开始使用该技能并立即被重定向到音频的意图(用户无需说其他任何内容)。 The Intent Chaining doesn't work if the intent has no slots to fill.如果意图没有要填充的插槽,则意图链接不起作用。 How could I solve?我该怎么解决? Here is the code:这是代码:

const LaunchRequestHandler = {
canHandle(handlerInput) {
    return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
},
handle(handlerInput) {
    const speakOutput = 
    `<speak>
        <amazon:effect name="whispered">Welcome.</amazon:effect>.
    </speak>`;

    return handlerInput.responseBuilder
        .speak(speakOutput)
        .addDelegateDirective({
            name: 'LightOnIntent',
            slots: {}
        })
        .getResponse();
}

}; };

const LightOnIntentHandler = {
canHandle(handlerInput) {
    return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
        && Alexa.getIntentName(handlerInput.requestEnvelope) === 'LightOnIntent';
},
handle(handlerInput) {
    const {requestEnvelope, responseBuilder} = handlerInput;
    
    const audioUrl = Util.getS3PreSignedUrl("Media/ding.mp3").replace(/&/g,'&amp;');

    const speakOutput = `<audio src="${audioUrl}"/>`;
    
    return responseBuilder
        .speak(speakOutput)
        //.reprompt('add a reprompt if you want to keep the session open for the user to respond')
        .getResponse();
}

}; };

Couple of follow up questions:几个后续问题:

  1. What is the purpose of the intent for the audio?音频意图的目的是什么? Since you mentioned that you don't want any slots for the intent, do you plan to have any logic for intent confirmation?既然你提到你不想要任何意图的槽,你打算有任何逻辑来确认意图吗?
  2. What happens after the audio plays?音频播放后会发生什么? Do you expect the user to reply?您希望用户回复吗?

Suppose you want to just play audio after user invokes the skill, why not play the audio clip as part of the response to the LaunchRequest?假设您只想在用户调用技能后播放音频,为什么不播放音频剪辑作为对 LaunchRequest 的响应的一部分? Something like this:像这样的东西:

const LaunchRequestHandler = {
canHandle(handlerInput) {
    return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
},
handle(handlerInput) {
const audioUrl = Util.getS3PreSignedUrl("Media/ding.mp3").replace(/&/g,'&amp;');
    const speakOutput = 
    `<speak>
        <amazon:effect name="whispered">Welcome.</amazon: effect>.
        <audio src="${audioUrl}"/>
    </speak>`;

    return handlerInput.responseBuilder
        .speak(speakOutput)
         .shouldEndSession(true)
        .getResponse();
}

Additionally if you want to provide a richer audio experience, you can use APL for Audio instead of speak此外,如果您想提供更丰富的音频体验,您可以使用APL for Audio代替speak

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM