Skip to main content
The Plivo Stream SDK provides official libraries for Python, Node.js, and Java to build AI voice agents using Plivo’s Audio Streaming API. These SDKs handle WebSocket connections, audio encoding/decoding, and event management, letting you focus on your AI integration logic.

What You Can Build

  • AI Voice Assistants - Natural conversations powered by speech-to-text, LLMs, and text-to-speech
  • Real-time Transcription - Live call transcription with speech recognition services
  • Voice Bots - Automated IVR systems with intelligent responses
  • Call Analytics - Real-time audio analysis and sentiment detection

Get Started with Plivo

Before developing your AI voice agent, sign up for Plivo or sign in to your existing account. Purchase a voice-enabled number through the Plivo console.

Prerequisites

Required Accounts

  • Plivo - Account with Auth ID and Auth Token
  • Deepgram - Sign up for speech-to-text
  • OpenAI - Sign up for conversational AI
  • ElevenLabs - Sign up for text-to-speech

Language Requirements

  • Python 3.8 or later
  • pip package manager

Installation

The Python SDK supports two WebSocket implementations:
  • FastAPI - For production applications using ASGI
  • websockets - Lightweight option for simple use cases

Core Concepts

Audio Streaming Flow

  1. Caller dials your Plivo number
  2. Plivo connects to your WebSocket endpoint
  3. SDK receives START event with stream metadata
  4. Audio flows as MEDIA events (base64-encoded mu-law)
  5. Your app processes audio through AI services
  6. SDK sends audio back to the caller

Event Types

Audio Formats


Quick Start

Step 1: Create a WebSocket Handler

Step 2: Configure Plivo to Stream Audio

Create an XML application that routes calls to your WebSocket endpoint:

Step 3: Set Up Local Development

For local testing, use ngrok to expose your WebSocket endpoint:
Update your Plivo XML with the ngrok URL:
For complete AI voice agent examples with Deepgram, OpenAI, and ElevenLabs integration, see Clone the Example Repositories or the Deepgram + OpenAI + ElevenLabs Guide.

SDK Reference

Sending Audio to Caller

Event Handlers

Getting Stream Information


Configuration Options

Environment Variables

Create a .env file with your credentials:

Plivo Stream XML Options


Troubleshooting

WebSocket Connection Issues

  1. Verify ngrok is running and the URL matches your XML configuration
  2. Check firewall rules allow WebSocket connections on your server
  3. Validate SSL certificates if using custom domains

Audio Quality Issues

  1. Use correct audio format - mu-law at 8kHz for standard telephony
  2. Check sample rate matches between incoming and outgoing audio
  3. Monitor latency - keep processing under 200ms for natural conversation

No Audio Received

  1. Verify audioTrack is set to both or inbound in your XML
  2. Check handler is registered before calling start()
  3. Confirm call is connected - START event should fire first

Clone the Example Repositories

Full working examples are available in the SDK repositories:

Support