亚马逊alexa技能套件(ASK)

时间:2017-12-12 10:15:52

标签: amazon alexa-skills-kit

亚马逊alexa中this.emit(:ask)this.response(:speak)之间的区别是什么? EG:

let handler = {
    'PlayVideoIntent' : function() {

        // VideoApp.Play directives can be added to the response
        if (this.event.context.System.device.supportedInterfaces.VideoApp) {
            this.response.playVideo('http://path/to/my/video.mp4');
        } else {
            this.response.speak("The video cannot be played on your device. " +
                "To watch this video, try launching the skill from your echo show device.");
        }

        this.emit(':responseReady');
    }
}

2 个答案:

答案 0 :(得分:2)

Alexa Skills Kit documentation有详细解释。

来自Response vs ResponseBuilder部分:

  

目前,有两种方法可以在Node.js SDK中生成响应对象。第一种方法是使用格式this.emit(:${action}, 'responseContent')

     

如果您想手动创建自己的回复,可以使用this.response来提供帮助。 this.response包含一系列函数,可用于设置响应的不同属性。这使您可以利用Alexa Skills Kit的内置音频和视频播放器支持。设置好回复后,您只需致电this.emit(':responseReady')即可将回复发送给Alexa。 this.response中的函数也是可链接的,因此您可以连续使用任意数量的函数。

     

完成设置回复后,只需致电this.emit(':responseReady')即可发送回复。下面是两个使用多个响应对象构建响应的示例:

     

例1:

     

this.response.speak(speechOutput) .listen(repromptSpeech); this.emit(':responseReady');

     

示例2

     

this.response.speak(speechOutput) .cardRenderer(cardTitle, cardContent, cardImage) .renderTemplate(template) .hint(hintText, hintType); this.emit(':responseReady');

     

由于responseBuilder可以更灵活地构建丰富的响应对象,因此我们更倾向于使用此方法来构建响应。

答案 1 :(得分:1)

欢迎使用StackOverflow。答案可以在问题本身中找到。

当你拥有ask时,它实质上意味着会话仍然被维护,而Alexa期待来自用户的某些东西。而另一方面,如果你要告诉,这意味着没有可用的会话。以下示例将有所帮助。

<强>告诉

User: Alexa, how are you doing.

Alexa: I'm doing good thank you. 

--Conversation ended

<强>问

User: Alexa set an alarm
Alexa: sure, at what time? <-- This is where we use ask, as the conversation is incomplete
User: at 5:30 AM
Alexa: Alarm set <-- This is where we use tell, as the task is done and there is no use of user's input anymore.

希望这会对你有所帮助。

快乐编码!!!

相关问题