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
Optional[dict]

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
Optional[dict]

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
Optional[float]

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

partial_results
Optional[bool]

Enable partial speech recognition results.

continuous
Optional[bool]

Keep collecting after each result instead of stopping.

send_start_of_input
Optional[bool]

Send an event when input is first detected.

start_input_timers
Optional[bool]

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

control_id
Optional[str]

Custom control ID. Auto-generated if not provided.

on_completed
Optional[Callable[[RelayEvent], Any]]

Callback invoked when collection completes.

Returns

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

Example

1from signalwire.relay import RelayClient
2
3client = RelayClient(
4 project="your-project-id",
5 token="your-api-token",
6 host="your-space.signalwire.com",
7 contexts=["default"],
8)
9
10@client.on_call
11async def handle_call(call):
12 await call.answer()
13
14 # Collect digits silently (e.g., extension entry)
15 action = await call.collect(
16 digits={"max": 4, "digit_timeout": 3, "terminators": "#"},
17 initial_timeout=10,
18 )
19 event = await action.wait()
20
21 result = event.params.get("result", {})
22 extension = result.get("digits", "")
23 print(f"Extension entered: {extension}")
24
25client.run()