RELAYCall

record

View as MarkdownOpen in Claude

Start recording audio from the call. Returns a RecordAction that you can use to pause, resume, stop, or wait for the recording to complete.

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

This method corresponds to the SWML record verb. See the SWML record reference for the full specification.

Parameters

audio
Optional[dict]

Audio recording configuration object.

audio.direction
str

Which audio to record.

  • "listen" — record audio heard by the caller
  • "speak" — record audio spoken by the caller
  • "both" — record audio in both directions
audio.format
str

Recording file format.

  • "mp3" — compressed MP3 format
  • "wav" — uncompressed WAV format
audio.stereo
bool

Record in stereo (each side on a separate channel).

audio.initial_timeout
float

Seconds to wait for audio before ending with no_input.

audio.end_silence_timeout
float

Seconds of silence before stopping automatically.

audio.terminators
str

DTMF digits that stop recording (e.g., "#").

audio.beep
bool

Play a beep before recording starts.

audio.input_sensitivity
float

Sensitivity threshold for detecting audio input.

control_id
Optional[str]

Custom control ID for this operation. Auto-generated if not provided.

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

Callback invoked when recording reaches a terminal state (finished or no_input). The event contains the recording url, duration, and size.

Returns

RecordAction — An action handle with stop(), pause(), resume(), 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 await call.play([{"type": "tts", "text": "Leave a message after the beep."}])
14
15 action = await call.record(
16 audio={"beep": True, "end_silence_timeout": 3, "terminators": "#"},
17 )
18 event = await action.wait()
19
20 url = event.params.get("record", {}).get("url", "")
21 print(f"Recording saved: {url}")
22 await call.hangup()
23
24client.run()