time grammar

Collects a time of day.

The grammar accepts spoken time utterances from the caller. Recognized phrases may include times given in 12-hour format (for example, "5 o'clock") and 24-hour format ("twenty_three fifteen"). In addition, it recognizes "qualified" times such as "before 5 o'clock" and "about 5."

Return keys/values

Key

Value

MEANING

Contains the spoken time in HHMMP format, where HH is the hour, MM is the minute, and P is one of:

  • p (for p.m.)
  • a (for a.m.)
  • h (for times spoken in 24-hour form, for example, 22:15)
  • ? (for unknown)

The HHMMP format conforms to VoiceXML. The time can range from 0000 to 2359.

SWI_literal

Contains the exact text that was recognized.

HOUR

2-character value (00 to 24) corresponding to the hour.

MINUTE

2-character value (00 to 59) corresponding to the minute.

AMPM

One of "p" (for p.m.), "a" (for a.m.), "h" for 24-hour times, "?" for unknown.

QUALIFIER

One of "exact," "approx" (abbreviation for approximately), "before," or "after" depending on whether the caller spoke a word to qualify the time (for example, "before 9" would lead to qualifier of "before.") The default is "exact," if no qualifier is heard.

Properties

The more narrowly you set these properties, the higher the recognition accuracy. However, narrow settings also limit the range of possibilities that callers are allowed to speak. Your settings must balance the need for accuracy with the expectations of your callers.

Property

Description

minallowed

Earliest time recognized (default=0000)

maxallowed

Latest time recognized (default=2359)

minexpected

Earliest likely time (default=0000)

maxexpected

Latest likely time (default=2359)

granularityallowed

Allowed granularity in minutes (default=1)

granularityexpected

Expected granularity in minutes (default=1)

Setting an allowed range tells the Recognizer to only allow times inside the range you specify. Times outside the range are not recognized. Setting an expected range is meant to include the most likely 90% of times callers may speak, and is used by the recognition engine to improve accuracy on those times.

You can use both allowed and expected ranges at the same time. The expected range must fall within the allowed range or an error is returned.

Depending on your application, you may also want to allow recognition of varying degrees of granularity in the caller’s response. If an office schedules appointments in half-hour intervals, you may want to restrict the Recognizer to understand times in half-hour increments.

The time built-in grammar supports a notion of allowed and expected granularity. Setting an allowed granularity tells the Recognizer to allow utterances that match only the allowed granularity. For example, if you set an allowed granularity of 30 then the Recognizer returns success only if a person says a multiple of 30. Setting an expected granularity tells the Recognizer to accept any time the caller says that matches the allowed granularity but to give higher preference to recognition hypotheses that match the expected granularity.

If you use both allowed and expected granularities at once, the expected granularity must be a multiple of the allowed granularity or an error is returned.

You may set the granularity to any number of minutes that you want, but even divisors and multiples of 60 (1, 5, 10, 15, 20, 30, 60, 120) work the best, since callers are used to talking about fractions of an hour.

The maximum number of minutes (59) is used even if you set the minutes to a greater value. For example, if you set the minallowed property to 0480, the grammar uses 0459 instead.

Example

builtin:grammar/time?language=en-US;minallowed=0600;
   maxallowed=1200;minexpected=1000;maxexpected=1100;
   granularityallowed=5;granularityexpected=15

DTMF interpretation

The grammar returns the same keys and MEANING when callers press touchtones instead of speaking. The format must be 4 digits (24-hour time in the range of 0000 and 2400).