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
str | NoneDefaults to None

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

codec
str | NoneDefaults to None

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
str | NoneDefaults to None

Which audio track to stream.

  • "inbound" — audio received from the caller
  • "outbound" — audio sent to the caller
  • "both" — audio in both directions
status_url
str | NoneDefaults to None

URL to receive stream status webhooks.

status_url_method
str | NoneDefaults to None

HTTP method for status webhooks.

  • "GET" — send status updates via GET request
  • "POST" — send status updates via POST request
authorization_bearer_token
str | NoneDefaults to None

Bearer token for authenticating with the WebSocket server.

custom_parameters
dict | NoneDefaults to None

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

control_id
str | NoneDefaults to None

Custom control ID. Auto-generated if not provided.

on_completed
Callable[[RelayEvent], Any] | NoneDefaults to None

Callback invoked when the stream ends.

Returns

StreamAction — An action handle with stop() and wait() methods.

Example

from signalwire.relay import RelayClient
client = RelayClient(
project="your-project-id",
token="your-api-token",
contexts=["default"],
)
@client.on_call
async def handle_call(call):
await call.answer()
# Stream audio to an external service for real-time processing
action = await call.stream(
url="wss://example.com/audio-stream",
track="inbound",
codec="PCMU",
custom_parameters={"session_id": "abc123"},
)
# The stream runs until stopped or the call ends
await call.wait_for_ended()
client.run()