RelayCall

collect

View as MarkdownOpen in Claude

Collect DTMF digit or speech input without playing a prompt. Use this when you want to listen for input silently or after a prompt has already been played separately. For collecting input with a prompt, use play_and_collect().

This method emits calling.call.collect events. See Call Events for payload details.

Parameters

digits
dict | NoneDefaults to None

DTMF digit collection settings.

digits.max
int

Maximum number of digits to collect.

digits.digit_timeout
float

Seconds to wait between digits before completing.

digits.terminators
str

Characters that terminate digit collection (e.g., "#").

speech
dict | NoneDefaults to None

Speech recognition settings.

speech.end_silence_timeout
float

Seconds of silence to wait before finalizing speech input.

speech.speech_timeout
float

Maximum seconds to listen for speech.

speech.language
str

Speech recognition language code (e.g., "en-US").

speech.hints
list[str]

Words or phrases to boost recognition accuracy.

initial_timeout
float | NoneDefaults to None

Seconds to wait for the first input before ending with no_input.

partial_results
bool | NoneDefaults to None

Enable partial speech recognition results.

continuous
bool | NoneDefaults to None

Keep collecting after each result instead of stopping.

send_start_of_input
bool | NoneDefaults to None

Send an event when input is first detected.

start_input_timers
bool | NoneDefaults to None

Start input timers immediately. If False, call action.start_input_timers() to start them manually.

control_id
str | NoneDefaults to None

Custom control ID. Auto-generated if not provided.

on_completed
Callable[[RelayEvent], Any] | NoneDefaults to None

Callback invoked when collection completes.

Returns

StandaloneCollectAction — An action handle with stop(), start_input_timers(), and wait() methods.

Example

from signalwire.relay import RelayClient
client = RelayClient(
project="your-project-id",
token="your-api-token",
contexts=["default"],
)
@client.on_call
async def handle_call(call):
await call.answer()
# Collect digits silently (e.g., extension entry)
action = await call.collect(
digits={"max": 4, "digit_timeout": 3, "terminators": "#"},
initial_timeout=10,
)
event = await action.wait()
result = event.params.get("result", {})
extension = result.get("digits", "")
print(f"Extension entered: {extension}")
client.run()