Twilio Plugin
Twilio plugin for Vision Agents enabling voice call integration with real-time audio streaming.
Features
- Media Streaming: Bidirectional audio streaming via Twilio Media Streams
- Call Registry: Track active calls with metadata (caller info, timestamps)
- Audio Conversion: Automatic mulaw/PCM conversion for Twilio compatibility
- WebSocket Management: Handle Twilio WebSocket connections
Installation
uv add "vision-agents[twilio]"
# or directly
uv add vision-agents-plugins-twilio
Usage
from vision_agents.plugins import twilio
# Create a call registry to track active calls
registry = twilio.CallRegistry()
# When receiving a voice webhook, register the call
call = registry.create(call_sid="CA123...", form_data={"From": "+1234567890", ...})
# Create a media stream for the WebSocket connection
stream = twilio.MediaStream(websocket)
await stream.accept()
# Associate stream with call
call.twilio_stream = stream
# Run the stream (blocks until call ends)
await stream.run()
Components
TwilioCall
Dataclass representing an active call session:
@dataclass
class TwilioCall:
call_sid: str
form_data: dict[str, Any] # All Twilio webhook data
twilio_stream: Optional[TwilioMediaStream]
stream_call: Optional[Any] # Stream video call
started_at: datetime
ended_at: Optional[datetime]
# Convenience properties
from_number: str # Caller's phone number
to_number: str # Called phone number
call_status: str # Current call status
TwilioCallRegistry
In-memory registry for managing active calls:
registry = twilio.CallRegistry()
registry.create(call_sid, form_data) # Register new call
registry.get(call_sid) # Look up call
registry.remove(call_sid) # Remove and mark ended
registry.list_active() # List active calls
TwilioMediaStream
Manages Twilio Media Stream WebSocket connections:
stream = twilio.MediaStream(websocket)
await stream.accept()
# Access the audio track for publishing
stream.audio_track # AudioStreamTrack at 8kHz
# Send audio back to Twilio
await stream.send_audio(pcm_data)
# Run until stream ends
await stream.run()
Audio Utilities
from vision_agents.plugins.twilio import mulaw_to_pcm, pcm_to_mulaw, TWILIO_SAMPLE_RATE
# Convert Twilio mulaw to PCM
pcm = mulaw_to_pcm(mulaw_bytes)
# Convert PCM to Twilio mulaw
mulaw = pcm_to_mulaw(pcm_data)
Configuration
| Parameter | Description | Default |
|---|---|---|
TWILIO_SAMPLE_RATE |
Twilio audio sample rate | 8000 (8kHz) |
Environment Variables
TWILIO_ACCOUNT_SID: Your Twilio account SIDTWILIO_AUTH_TOKEN: Your Twilio auth token
Dependencies
- vision-agents
- twilio
- numpy
Metadata
Release files for vision-agents-plugins-twilio 0.6.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vision_agents_plugins_twilio-0.6.9.tar.gz | 10.3 kB | Without provenance | Details for vision_agents_plugins_twilio-0.6.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vision_agents_plugins_twilio-0.6.9-py3-none-any.whl | Python 3 | none | any | Details for vision_agents_plugins_twilio-0.6.9-py3-none-any.whl |
Total release size: 22.4 kB
Release files / vision_agents_plugins_twilio-0.6.9.tar.gz
| Download URL | vision_agents_plugins_twilio-0.6.9.tar.gz |
|---|---|
| Size | 10.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
235138800b72f309f087495736058003624091f3dd2696bf269050fe4a9be82e
|
|
BLAKE2b-256 checksum How to use checksums |
86f759f1837e1de6b4d11ad16068fc66b7bb647ebb0fb4b389a27b9a13dedea6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / vision_agents_plugins_twilio-0.6.9-py3-none-any.whl
| Download URL | vision_agents_plugins_twilio-0.6.9-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
89ef807d0751c26f55b91f3ce60710d357e0befc539af84c030f185c7e1682e6
|
|
BLAKE2b-256 checksum How to use checksums |
868ffa1cc8b364a169a66e47193d8e2a8cae2179c1b3ecaae129287b3639b76a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for vision-agents-plugins-twilio 0.6.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.