question

AJ avatar image
AJ asked ·

Can we have multiple 'this.response.speak' in Intent functions?

const handlers = {
    'IntentName1': function () {	//First Way

	this.response.speak('TexttoSpeak'); //First
        this.response.speak('TexttoSpeak'); //Second
        this.emit(':responseReady');
    },

    'IntentName2': function () {	//Second Way

	this.response.speak('TexttoSpeak'); //First
	this.emit(':responseReady');
        this.response.speak('TexttoSpeak'); //Second
        this.emit(':responseReady');
    }
}

Can we have multiple Speak/emit functions like above? I tried in many ways but it did not work out. Or is it not allowed and we have to barge everything in a single speak?

alexa skills kitskillintents
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jamie@Amazon avatar image
Jamie@Amazon answered ·

No. As mentioned, you should only ever need one really. Your 'speechOutput' is pretty much a string, and you can build that out on gradually until you're ready to send that back to the user. For example:

var speechOutput;
speechOutput = "hello. ";
speechOutput+= "how are you. ";
speechOutput+= "i am good.";
this.response.speak(speechOutput);      
this.emit(':responseReady');

2 comments
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I have a similar requirement, after entering the intent, Alexa got to say

Step 1: "Welcome to the App, I will load the orders, please wait..",

Step 2: Then call a web service which takes around 5 seconds or so

Step 3: Read the information from the web service " You have 5 orders"

For above example, I do not want to combine the string as I ask the user to wait before I fetch the information, just letting the user know i'm going to get the data, just keeping the user engaged. Just like a "Loading.." information in a browser.

0 Likes 0 ·
LiamDeLee avatar image
LiamDeLee answered ·

As far as i know (no expert at all here) you can only use 1 emit since it will jump out of your intent and go back to the user. BUT you can just add this speak to the other speak and use one emit instead.

i am kind of curious why you would want to use more then one speak/emit, for what use case would you use this?

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.