tap

View as MarkdownOpen in Claude

Start a media tap that streams call audio to an external endpoint. Supports WebSocket (wss://, ws://) and RTP (rtp://) destinations.

Raises ValueError if direction is not "speak", "listen", or "both", if codec is not "PCMU" or "PCMA", or if rtp_ptime is not a positive integer.

Parameters

uri
strRequired

Destination URI for the media stream. Supported formats:

  • "rtp://IP:port" — RTP stream
  • "ws://example.com" — WebSocket stream
  • "wss://example.com" — Secure WebSocket stream
control_id
Optional[str]Defaults to None

Identifier for this tap. Pass the same ID to stop_tap() to end this specific tap. If omitted, a default ID is generated.

direction
strDefaults to both

Audio direction to tap.

  • "speak" — what the party says
  • "hear" — what the party hears
  • "both" — both directions
codec
strDefaults to PCMU

Audio codec for the stream.

  • "PCMU" — G.711 mu-law
  • "PCMA" — G.711 A-law
rtp_ptime
intDefaults to 20

Packetization time in milliseconds for RTP streams. Must be a positive integer.

status_url
Optional[str]Defaults to None

URL to receive tap status change webhooks.

Returns

FunctionResult — self, for chaining.

Example

1from signalwire import AgentBase
2from signalwire import FunctionResult
3
4agent = AgentBase(name="my-agent", route="/agent")
5agent.set_prompt_text("You are a helpful assistant.")
6
7@agent.tool(name="start_monitoring", description="Start monitoring the call audio")
8def start_monitoring(args, raw_data):
9 return (
10 FunctionResult("Call monitoring started.")
11 .tap(
12 uri="wss://monitor.example.com/audio",
13 control_id="supervisor_tap",
14 direction="both"
15 )
16 )
17
18agent.serve()