> For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

# play_and_collect

> Play audio and collect DTMF or speech input.

[collectaction]: /docs/server-sdks/reference/python/relay/actions

[calling-call-collect]: /docs/server-sdks/reference/python/relay/call#events

[call-events]: /docs/server-sdks/reference/python/relay/call#events

[play]: /docs/server-sdks/reference/python/relay/call/play

Play audio content as a prompt and simultaneously collect user input via DTMF
digits or speech recognition. Returns a
[`CollectAction`][collectaction] that resolves when
input is collected, the operation times out, or an error occurs.

The `CollectAction` resolves only on collect events, not on play events. This
means `await action.wait()` blocks until the user provides input (or the
operation terminates), not when the audio finishes playing.

This method emits [`calling.call.collect`][calling-call-collect] events. See [Call Events][call-events] for payload details.

## **Parameters**

List of media items to play as the prompt. Same format as
[`play()`][play] media items.

Input collection configuration.

DTMF digit collection settings.

Maximum number of digits to collect.

Seconds to wait between digits before completing.

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

Speech recognition settings.

Seconds of silence to wait before finalizing speech input.

Maximum seconds to listen for speech.

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

Words or phrases to boost recognition accuracy.

Volume adjustment in dB for the prompt audio.

Custom control ID. Auto-generated if not provided.

Callback invoked when collection completes.

## **Returns**

[`CollectAction`][collectaction] -- An action handle with
`stop()`, `volume()`, `start_input_timers()`, and `wait()` methods.

## **Example**

```python {14}
from signalwire.relay import RelayClient

client = RelayClient(
    project="your-project-id",
    token="your-api-token",
    host="your-space.signalwire.com",
    contexts=["default"],
)

@client.on_call
async def handle_call(call):
    await call.answer()

    action = await call.play_and_collect(
        media=[{"type": "tts", "params": {"text": "Press 1 for sales, 2 for support."}}],
        collect={
            "digits": {"max": 1, "digit_timeout": 5, "terminators": "#"},
        },
    )
    event = await action.wait()

    result = event.params.get("result", {})
    digits = result.get("digits", "")
    if digits == "1":
        await call.transfer("sales")
    elif digits == "2":
        await call.transfer("support")
    else:
        await call.hangup()

client.run()
```