如何在几秒钟内使Alexa倒计时 [英] How to make Alexa countdown in seconds
问题描述
我希望我的技巧能够使Alexa(听觉上)倒计时15秒.我知道我可以在SSML中< break time ="15s"/>
.但这是听不到的.我也知道我可以做到:
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闲暇的人的帮助下):
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屋!