Skip to content

RTP Voice Backend

The RTP backend sends and receives voice audio over RTP for integration with PBX/SIP gateways or any system that speaks RTP.

Install with: pip install roomkit[rtp]

Quick start

from roomkit.voice.backends.rtp import RTPVoiceBackend

backend = RTPVoiceBackend(
    local_addr=("0.0.0.0", 10000),
    remote_addr=("192.168.1.100", 20000),
)

See the full RTP example for a complete runnable script.

API Reference

RTPVoiceBackend

RTPVoiceBackend(*, local_addr=('0.0.0.0', 0), remote_addr=None, payload_type=0, clock_rate=8000, dtmf_payload_type=101, rtcp_interval=5.0)

Bases: VoiceBackend

VoiceBackend that sends and receives audio over RTP.

Each :meth:connect call creates a new aiortp.RTPSession bound to the configured local address and sending to the remote address.

Inbound audio is decoded by aiortp (G.711, L16, Opus) and delivered as AudioFrame objects via the on_audio_received callback. DTMF digits are received out-of-band via RFC 4733 and delivered via on_dtmf_received callbacks.

Parameters:

Name Type Description Default
local_addr tuple[str, int]

(host, port) to bind RTP. Use port 0 for OS-assigned.

('0.0.0.0', 0)
remote_addr tuple[str, int] | None

(host, port) to send RTP to. May be None if supplied per-session via metadata["remote_addr"] in :meth:connect.

None
payload_type int

RTP payload type number (default 0 = PCMU).

0
clock_rate int

Clock rate in Hz (default 8000 for G.711).

8000
dtmf_payload_type int

RTP payload type for RFC 4733 DTMF events (default 101).

101
rtcp_interval float

Seconds between RTCP sender reports.

5.0

send_transcription async

send_transcription(session, text, role='user')

Log transcription text (no UI channel in RTP mode).

on_dtmf_received

on_dtmf_received(callback)

Register a callback for inbound DTMF digits (RFC 4733).

Parameters:

Name Type Description Default
callback DTMFReceivedCallback

Function called with (session, dtmf_event).

required

Capabilities

The RTP backend declares DTMF_SIGNALING (RFC 4733 out-of-band DTMF) and INTERRUPTION (cancel outbound audio mid-stream).

DTMF

Inbound DTMF digits are received via RFC 4733 and delivered as DTMFEvent objects. Hook into them with HookTrigger.ON_DTMF:

@kit.hook(HookTrigger.ON_DTMF, execution=HookExecution.ASYNC)
async def on_dtmf(event, ctx):
    print(f"DTMF: {event.digit}")

Per-session remote address

Pass metadata={"remote_addr": (host, port)} to connect() to override the remote address per session, useful for multi-tenant PBX setups.