是否有可能获得用户使用 Alexa 回答命令所需的时间alexa-sdk
?为了使其更直观,我正在尝试测量以下内容:
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"
我在文档中找不到任何东西,我通常会尝试process.hrtime
在做出响应之前和之后使用类似启动计时器的东西,但是我的处理程序看起来像这样:
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();
}
};
然而,这在 Alexa 开始命令之前开始计数,所以我得到的时间是 Alexa 说出命令所需的时间 + 用户延迟回复。
现在我用秒表测量了 Alexa 的响应时间,我从总时间中减去了它,但这并不理想。