Signals Docs
OneML reference

Gather

The <Gather> verb collects DTMF digits, speech or both from the caller, then sends the result to your action URL. Use it for menus, PIN entry and any prompt that branches on caller input.

Attributes

NameTypeDefaultDescription
actionstring (uri)NoneURL to send the result to. When absent, the next verb in the document runs once gathering ends.
methodstringPOSTHTTP method used to request action. GET or POST.
inputstringdtmfInput to accept: dtmf, speech, or dtmf speech (both, in any order). With both, Signals listens for digits and speech at the same time and the first input to complete wins: digits produce Digits, a finished transcription produces SpeechResult.
timeoutinteger5Seconds to wait for input before gathering ends with no result. For speech, speechTimeout sets the end-of-speech silence window instead.
numDigitsintegerNoneMaximum number of digits to collect. Gathering ends as soon as this many are entered, without waiting for finishOnKey or timeout. When omitted, up to 128 digits are collected.
finishOnKeystring#Key that ends input. A single character: a digit, * or #. Set to an empty string to disable it.
actionOnEmptyResultbooleanfalseWhether to request action when gathering ends with no digits or speech. When false, an empty result moves on to the next verb instead.
languagestringen-USSpeech recognition language, as a BCP-47 tag such as en-US. Applies only when input includes speech.
hintsstringNoneComma-separated words or phrases likely to appear in the caller's speech, to improve recognition. Applies only when input includes speech.
speechTimeoutstringNoneSeconds of silence after the caller stops speaking before recognition ends, bounded by timeout. Set to auto to end as soon as the caller stops talking. A number must be a positive integer. When speechModel is set, speechTimeout must be a number: auto and the default are rejected.
speechModelstringNoneSpeech recognition model to use. Requires speechTimeout to be a positive integer.
partialResultCallbackstring (uri)NoneURL that receives interim transcripts while the caller is still talking. Applies only when input includes speech.
partialResultCallbackMethodstringPOSTHTTP method used to request partialResultCallback. GET or POST.
profanityFilterbooleanNoneWhether to mask profanity in transcripts. Applies only when input includes speech.

Nesting

<Gather> may contain <Say>, <Play> and <Pause> as prompts, played while Signals waits for input. A digit pressed during a prompt stops it and skips any remaining prompts; that digit becomes the first digit of the result.

Action parameters

<Gather> sends different parameters to action depending on what it collected:

NameTypeDescription
DigitsstringDigits collected. Sent when input includes dtmf and the caller entered at least one digit.
SpeechResultstringTranscribed speech. Sent when input includes speech and recognition produced a result.
ConfidencefloatConfidence score for SpeechResult, from 0 to 1. Sent with SpeechResult.

Streaming partial results

When partialResultCallback is set and input includes speech, Signals posts each interim transcript to that URL as recognition progresses, in addition to the final result sent to action:

NameTypeDescription
AccountSidstringYour Voice Account SID.
CallSidstringUnique identifier for the call.
UnstableSpeechResultstringThe interim transcript so far.
ConfidencefloatConfidence score for UnstableSpeechResult, from 0 to 1.

Interim results are not final. Signals does not wait for a response from partialResultCallback, and UnstableSpeechResult may change before gathering completes.

Examples

A DTMF menu with two options:

XMLCode
<?xml version="1.0" encoding="UTF-8"?> <Response> <Gather action="/handle-menu" numDigits="1" timeout="10"> <Say>For sales, press 1. For support, press 2.</Say> </Gather> <Say>We did not receive your selection. Goodbye.</Say> <Hangup/> </Response>

The /handle-menu action handler, complete and runnable:

const express = require("express"); const app = express(); app.use(express.urlencoded({ extended: false })); app.post("/handle-menu", (req, res) => { const messages = { 1: "You selected sales. An agent will call you back shortly.", 2: "You selected support. An agent will call you back shortly.", }; const message = messages[req.body.Digits] || "That is not a valid option. Goodbye."; res.type("text/xml").send(`<?xml version="1.0" encoding="UTF-8"?> <Response> <Say>${message}</Say> <Hangup/> </Response>`); }); app.listen(3000);

A speech gather with recognition hints:

XMLCode
<?xml version="1.0" encoding="UTF-8"?> <Response> <Gather input="speech" action="/handle-destination" language="en-US" hints="Lagos, Abuja, Port Harcourt" speechTimeout="auto"> <Say>Which city are you flying to?</Say> </Gather> </Response>

The /handle-destination handler reads SpeechResult and Confidence the same way the menu handler reads Digits, from req.body (Express) or request.form (Flask).

Requesting action even when the caller enters nothing:

XMLCode
<?xml version="1.0" encoding="UTF-8"?> <Response> <Gather action="/handle-pin" actionOnEmptyResult="true" numDigits="4" timeout="5"> <Say>Enter your four-digit PIN.</Say> </Gather> </Response>

With actionOnEmptyResult="true", Signals requests /handle-pin even if the caller never enters a digit, so your server can react to silence, for example by repeating the prompt. When the caller enters nothing, Digits is absent from the request.

See also

Last modified on