【问题标题】:How to get time passed from Alexa response to user reply?如何获得从 Alexa 响应到用户回复的时间?
【发布时间】:2018-09-23 19:57:46
【问题描述】:

是否可以让用户使用alexa-sdk 来回答来自 Alexa 的命令所花费的时间?为了使其更直观,我正在尝试测量以下内容:

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 的响应时间,我从总时间中减去了它,但这并不理想。

【问题讨论】:

    标签: node.js alexa alexa-skills-kit alexa-skill alexa-sdk-nodejs


    【解决方案1】:

    Alexa 停止说出命令的时间和用户开始响应的时间信息是用户隐私信息,不会向开发人员公开。

    注意:您当前使用秒表和减法的方法没有给出正确的时间度量,因为您没有考虑用户设备将信息发送到 AVS(Alexa 语音服务)云所花费的时间和时间AVS 需要调用你的技能 lambda。

    【讨论】:

    • 我明白了,我想我现在可能会坚持硬编码等待时间的“猜测”。谢谢!
    【解决方案2】:

    只需添加 > SSML 标签

    例子:-

    const speakOutput = "Hello, here is your test <break time = '300ms'/>" ;
    
    handlerInput.responseBuilder
                    .speak(speakOutput)
                    .getResponse();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-25
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多