Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Alexa countdown in seconds

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" />

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!!!

like image 264
ProGrammar Avatar asked Nov 19 '25 20:11

ProGrammar


1 Answers

function buildCountdown(seconds, break) {
    var countdown = "";

    for (var i = seconds; i > 0; i--) {
        var count = i.toString + "<break time='" + break.toString() + "s' />\n";
        countdown.concat(count);
    }

    return countdown;
}

And then just provide the outputSpeech property:

"outputSpeech": {
    "type": "SSML",
    "ssml": buildCountdown(15, 0.85)
}

I'm not sure about any ASK built-ins for building SSML, but writing functions that generate markup is pretty common when working with Javascript frameworks, so it seems appropriate here.

like image 62
mrshl Avatar answered Nov 22 '25 22:11

mrshl