RELAYCall

stream

View as MarkdownOpen in Claude

Start streaming call audio to a WebSocket endpoint. Returns a StreamAction that you can use to stop the stream or wait for it to finish.

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

Parameters

url
strRequired

WebSocket URL to stream audio to (e.g., "wss://example.com/stream").

name
Optional[str]

A name for this stream, useful for identifying multiple concurrent streams.

codec
Optional[str]

Audio codec for the stream.

  • "PCMU" — G.711 mu-law (default for North America)
  • "PCMA" — G.711 A-law (default for international)
  • "OPUS" — Opus codec (higher quality, variable bitrate)
track
Optional[str]

Which audio track to stream.

  • "inbound" — audio received from the caller
  • "outbound" — audio sent to the caller
  • "both" — audio in both directions
status_url
Optional[str]

URL to receive stream status webhooks.

status_url_method
Optional[str]

HTTP method for status webhooks.

  • "GET" — send status updates via GET request
  • "POST" — send status updates via POST request
authorization_bearer_token
Optional[str]

Bearer token for authenticating with the WebSocket server.

custom_parameters
Optional[dict]

Custom key-value pairs sent with the stream start message.

control_id
Optional[str]

Custom control ID. Auto-generated if not provided.

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

Callback invoked when the stream ends.

Returns

StreamAction — An action handle with stop() 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 # Stream audio to an external service for real-time processing
15 action = await call.stream(
16 url="wss://example.com/audio-stream",
17 track="inbound",
18 codec="PCMU",
19 custom_parameters={"session_id": "abc123"},
20 )
21
22 # The stream runs until stopped or the call ends
23 await call.wait_for_ended()
24
25client.run()