Is it possible to get the time users take to answer a command from Alexa using the alexa-sdk
? To make it more visual, I'm trying to measure the following:
User says: "Alexa open my app"
Alexa says: "Welcome to my app, say next to go to the next section"
-- A few seconds pass here, this is what I need to know --
User says: "Next"
I couldn't find anything in the docs, I'd normally try to use something like process.hrtime
to start a timer before and after the response is made, however my handler looks something like this:
let timer;
const StartIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
handlerInput.requestEnvelope.request.intent.name === 'StartIntent'
);
},
handle(handlerInput) {
timer = process.hrtime();
const speechText = 'Welcome to my app, say next to go to the next section';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
const NextIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
handlerInput.requestEnvelope.request.intent.name ===
'NextIntent'
);
},
handle(handlerInput) {
const diff = process.hrtime(timer);
const timeInNanoseconds = diff[0] * 1e9 + diff[1];
return handlerInput.responseBuilder
.speak(`${timeInNanoseconds} nanoseconds`)
.getResponse();
}
};
However this starts counting just before Alexa starts the command so the time I get is the time it takes Alexa to speak the command + the user delay to reply.
Right now I measured Alexa's response time using a stopwatch and I'm subtracting that from the total time but it's less than ideal.