It's day 13 of our 30-day skill challenge! Today we continue learning about date/time objects to extract times from speech and set timers.
Yesterday we learned about date/time objects and, in particular, how to use pronounce blocks to translate dates and times from a computer format to English. Today we are going to learn how to translate speech into a computer format.
When we set alarms for waking up in the morning, we usually have a specific time in mind for when we want to wake up. If we were to ask someone to wake us up, we would say "Wake me up at 7am."
This is very different for timers and reminders. For timers, we usually have a specific amount of time that we want to elapse before the timer goes off. This usually sounds like, "Set a timer for 15 minutes." When we say "15 minutes" what are we really asking?
We can program computers to do all three options, but some of the options are easier and more efficient. Option #1 and #2, require setting up a clock or timing mechanism which isn't the easiest because if we remember from date/time, computers already have clock system. Option #3 is the easiest because it is using the system clock.
"Set a timer for 15 minutes"
Just like in previous skills, it's helpful to really think about what we are asking someone to do when we ask them to set a timer. In this case, one way to think about it is.
Lucky for you, Chatterbox has specific blocks that solve each of these problems to allow you to focus on how you want to the skill to perform.
Let's try to build a skill by following the order from above. Let's start with how people might ask for a timer. If there are multiple ways to set a timer, then we'll want to use the On phrases block.
Notice that since we are going to be working with a duration of time, it's always good practice to create a variable to store the time "duration."
In a previous skill we used the Pronounce block to translate computer time into something that we can understand. For a timer, we are going in the reverse direction: from spoken time to computer time. Chatterbox has a block called Extract date from utterance.
Now that we have the "extracted date," we need to set an alarm. For this we'll use the Schedule Event block. Let's discuss the Schedule Event block for a bit.
If you look, at the block (pictured below), you'll notice that this block takes a different shape from most of the other blocks that we've used. The block is in a C-shape, similar to the Listen blocks that we've used so far. Like the Listen block, the code blocks that are inside, are only run when the specific utterances are heard. The Schedule Event block has an event name slot which we'll set to "Timer" and a "when" slot that determines when the code inside will run.
Next, we want to decide what will happen when the timer event is executed. For this example, we'll have Chatterbox speak "Your timer is up" when the timer is over.
The last step is to Speak a confirmation to the user AFTER the event is scheduled. It's good practice to wait until after the event is scheduled to confirm that a timer is set in case there is an error scheduling the event.
Your skill should look something similar to the following: