如何在几秒钟内让 Alexa 倒计时 [英] How to make Alexa countdown in seconds

查看:27
本文介绍了如何在几秒钟内让 Alexa 倒计时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在我的技能中让 alexa(听得见)倒计时 15 秒.我知道我可以在 SSML 中 .但那是听不见的.我也知道我可以做到:

I want to be able to have alexa (audibly) countdown 15 seconds in my skill. I know I can just <break time="15s" /> in SSML. But that isn't audible. I also know I can just do:

15<break time="1s" />
14<break time="1s" /> 

或者更好(考虑到说出数字所需的时间)

or better yet (to account for the time it takes to say the number)

15<break time="0.85s" />
14<break time="0.85s" />

但如果我重复多次,那将是大量重复的代码.所以我可能会编写一个函数,它接收一个数字和一个秒数,并在该时间间隔内产生一个 SSML 倒计时.

But that's going to be a ton of repeated code if I do this many times over. So I'm probably going to write a function that takes in a number and a number of seconds, and produces an SSML countdown in that interval.

但是,在我这样做之前,我想知道是否有适当的内置方法来执行此操作?或者,如果有人已经为此构建了一个功能?谢谢!!!

Before I do that, however, I was wondering if there's a proper, built-in way of doing this? Or if someone has a function they've already built for this? Thanks!!!

推荐答案

我最终得到了以下功能(在 Alexa slack 上的某人的帮助下):

I ended up with the following function (with the help of someone on the Alexa slack):

function countDown(numSeconds, breakTime) {
    return Array.apply(null, {length: numSeconds})
        .map((n, i) => {return `<say-as interpret-as="cardinal">${numSeconds-i}</say-as>` })
        .join(`<break time="${breakTime ? breakTime : 0.85}s" />`) + `<break time="${breakTime ? breakTime : 0.85}s" />`;
}

这篇关于如何在几秒钟内让 Alexa 倒计时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆