fbpx
Chatterbox
SHOP NOW

Shopping Cart

No products in the cart.

SHOP NOW

Shopping Cart

No products in the cart.

Kevin Elgan
April 13, 2020

Day 13: Timers

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.

Let's talk about time

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?

  • Option #1 is to start a stop watch and tell us when 15 minutes is up.
  • Option #2 is to count backwards from 15 minutes.
  • Option #3 is to add 15 minutes to the current time and set an alarm.

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.

What's in a timer?

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

  1. Get the time that we should be notified
  2. Set an alarm for time
  3. When alarm goes off, tell the user that "Timer is up"

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.

Building a Timer skill

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.

The extract date block will analyze the utterance fed to it and create a variable called extracted_date that we can use.

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.

The Schedule Event block will run any code blocks inside the C-shape when the time condition is met.

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.

Let's put it all together

Your skill should look something similar to the following:

Get a 10% discount code when you sign up for our newsletter!

Chatterbox
The educational smart speaker to teach kids about coding, artificial intelligence and privacy.
powered by Mycroft
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram