Module twilio

Module twilio 

Source
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 media frames 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 media frames;
  • an interruption (Playback::Flush) becomes a Twilio clear message, 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§

MediaFormat
The audio encoding Twilio declares in the start frame.
StartMeta
Metadata delivered by Twilio’s start frame when the stream opens.
TwilioCall
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.
TwilioError
Errors from parsing Twilio frames.

Constants§

TWILIO_HZ
The sample rate of every Twilio Media Stream, both directions.

Functions§

clear_frame
Build a clear frame — Twilio drops all buffered outbound audio. This is barge-in on the telephone: send it on Playback::Flush.
mark_frame
Build a mark frame — Twilio echoes it back once playback reaches it.
media_frame
Build an outbound media frame from mono PCM16 samples @ 8 kHz.
parse_inbound
Parse one Twilio Media Streams text frame.