Skip to main content

Twilio plugin for Vision Agents - Voice call integration with media streaming

Project description

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 SID
  • TWILIO_AUTH_TOKEN: Your Twilio auth token

Dependencies

  • vision-agents
  • twilio
  • numpy

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vision_agents_plugins_twilio-0.5.4.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vision_agents_plugins_twilio-0.5.4-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file vision_agents_plugins_twilio-0.5.4.tar.gz.

File metadata

  • Download URL: vision_agents_plugins_twilio-0.5.4.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for vision_agents_plugins_twilio-0.5.4.tar.gz
Algorithm Hash digest
SHA256 a944efcc833bc093f2528ac938420e043de32a6578baeec64e212c959eea4b29
MD5 f6a09b1c61c2e5bca769f7f7055cc634
BLAKE2b-256 8a1aaba2d7a2eb73cfc4e59cf728b3a9caecbc0492ea532be1110c2c1e0cb2e7

See more details on using hashes here.

File details

Details for the file vision_agents_plugins_twilio-0.5.4-py3-none-any.whl.

File metadata

  • Download URL: vision_agents_plugins_twilio-0.5.4-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for vision_agents_plugins_twilio-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2f97f4143c9d4063a079444d33b5846f494ab29673bd665f17e4e24095d03ed6
MD5 2b990485771303a36f7b9f9c1967fa22
BLAKE2b-256 7a8bb118ac8b0758341e3f9b6207771e90851050c9cff57187d0b480d93fbda1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page