Expand description
Twilio Media Streams — a phone call as two channels of JSON text frames.
Twilio’s Media Streams
forks a live call’s audio over a WebSocket: μ-law 8 kHz frames arrive as
base64 inside JSON text messages, and JSON text messages you send play
back to the caller. This module speaks that protocol and adapts it onto
voice::pump — so a governed Live session answers
the phone with the same barge-in guarantees as a local microphone:
- inbound
mediaframes are μ-law-decoded to PCM16 @ 8 kHz and fed to the pump, which resamples to the session’s 16 kHz input; - session audio comes back from the pump at 8 kHz, is μ-law-encoded, and
sent as outbound
mediaframes; - an interruption (
Playback::Flush) becomes a Twilioclearmessage, dropping every frame Twilio has buffered — the telephone form of “stop talking the instant the caller does”; - DTMF digits land in session state under
KEY_DTMF/KEY_DTMF_HISTORY, where flow guards and watchers read them like any other fact.
The bridge owns no socket. TwilioCall::attach returns a sender for the
text frames Twilio delivers and a receiver of the text frames to forward
back — wire them to any WebSocket server (see examples/telephony for an
axum one). Raw SIP (no Twilio in the path) is out of scope here; that is
the roadmap’s rsipstack integration.
Re-exports§
pub use super::bridge::KEY_CALL_SID;pub use super::bridge::KEY_DTMF;pub use super::bridge::KEY_DTMF_HISTORY;pub use super::bridge::KEY_STREAM_SID;
Structs§
- Media
Format - The audio encoding Twilio declares in the
startframe. - Start
Meta - Metadata delivered by Twilio’s
startframe when the stream opens. - Twilio
Call - A live phone call attached to a session — the telephone counterpart of
Talk::talk.
Enums§
- Inbound
- One decoded frame from Twilio, ready for application handling.
- Twilio
Error - Errors from parsing Twilio frames.
Constants§
- TWILIO_
HZ - The sample rate of every Twilio Media Stream, both directions.
Functions§
- clear_
frame - Build a
clearframe — Twilio drops all buffered outbound audio. This is barge-in on the telephone: send it onPlayback::Flush. - mark_
frame - Build a
markframe — Twilio echoes it back once playback reaches it. - media_
frame - Build an outbound
mediaframe from mono PCM16 samples @ 8 kHz. - parse_
inbound - Parse one Twilio Media Streams text frame.