> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes. # playAndCollect > Play audio and collect DTMF or speech input. [collectaction]: /docs/server-sdks/reference/typescript/relay/actions [calling-call-collect]: /docs/server-sdks/reference/typescript/relay/call#events [call-events]: /docs/server-sdks/reference/typescript/relay/call#events [play]: /docs/server-sdks/reference/typescript/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. > **Note** > > 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. > **Info** > > This method emits [`calling.call.collect`][calling-call-collect] events. See [Call Events][call-events] for payload details. ## **Parameters** **`media`** `Record[]` — required Array of media items to play as the prompt. Same format as [`play()`][play] media items. --- **`collect`** `Record` — required Input collection configuration. --- **`collect.digits`** `Record` DTMF digit collection settings. --- **`collect.digits.max`** `number` Maximum number of digits to collect. --- **`collect.digits.digit_timeout`** `number` Seconds to wait between digits before completing. --- **`collect.digits.terminators`** `string` Characters that terminate digit collection (e.g., `"#"`). --- **`collect.speech`** `Record` Speech recognition settings. --- **`collect.speech.end_silence_timeout`** `number` Seconds of silence to wait before finalizing speech input. --- **`collect.speech.speech_timeout`** `number` Maximum seconds to listen for speech. --- **`collect.speech.language`** `string` Speech recognition language code (e.g., `"en-US"`). --- **`collect.speech.hints`** `string[]` Words or phrases to boost recognition accuracy. --- **`volume`** `number | undefined` Volume adjustment in dB for the prompt audio. --- **`controlId`** `string | undefined` Custom control ID. Auto-generated if not provided. --- **`onCompleted`** `(event: RelayEvent) => void | Promise` Callback invoked when collection completes. --- ## **Returns** `Promise<`[`CollectAction`][collectaction]`>` -- An action handle with `stop()`, `volume()`, `startInputTimers()`, and `wait()` methods. ## **Example** ```typescript {12} import { RelayClient } from '@signalwire/sdk'; const client = new RelayClient({ project: process.env.SIGNALWIRE_PROJECT_ID!, token: process.env.SIGNALWIRE_API_TOKEN!, contexts: ['default'] }); client.onCall(async (call) => { await call.answer(); const action = await call.playAndCollect( [{ type: 'tts', text: 'Press 1 for sales, 2 for support.' }], { digits: { max: 1, digit_timeout: 5, terminators: '#' } } ); const event = await action.wait(); const result = event.params.result as Record ?? {}; const digits = (result.digits ?? '') as string; if (digits === '1') { await call.transfer('sales'); } else if (digits === '2') { await call.transfer('support'); } else { await call.hangup(); } }); await client.run(); ``` > Play audio and collect DTMF or speech input.