Skip to main content
Real-time bidirectional audio streaming enables Voice AI applications, live transcription, voice assistants, and custom audio processing on Plivo calls.

Prerequisites

1. Plivo Account

Sign up for Plivo and get your credentials:

2. Phone Number

You need a voice-enabled Plivo number to make or receive calls. Get a number:
  1. Go to Phone Numbers > Buy Numbers
  2. Select country and type (local, toll-free, mobile)
  3. Filter by voice_enabled = true
  4. Purchase
Indian phone numbers require KYC compliance:Submit compliance at Compliance Application before purchasing. See Rent India Numbers for details.

3. WebSocket Server

Your server must:
  • Accept WebSocket connections over wss://
  • Be publicly accessible (use ngrok for local development)
  • Handle Plivo’s stream events (start, media, dtmf, stop)

4. AI Service Credentials (Optional)

For voice AI applications, you’ll typically need:
  • Speech-to-Text: Deepgram, Google Speech, AWS Transcribe
  • LLM: OpenAI, Anthropic, Google Gemini
  • Text-to-Speech: ElevenLabs, Google TTS, Amazon Polly

How It Works

Plivo streams real-time audio between phone calls and your WebSocket server.

Architecture

Step-by-Step Flow

  1. Call Initiation: A caller dials your Plivo number, or your application initiates an outbound call.
  2. Answer URL Request: Plivo makes an HTTP request to your configured Answer URL.
  3. Stream XML Response: Your server responds with XML containing the <Stream> element, specifying the WebSocket URL and streaming parameters.
  4. WebSocket Connection: Plivo establishes a WebSocket connection to your specified URL.
  5. Start Event: Plivo sends a start event containing call metadata (call ID, stream ID, media format).
  6. Media Streaming:
    • Inbound: Plivo continuously sends media events containing base64-encoded audio chunks from the caller.
    • Outbound: Your server sends playAudio events with base64-encoded audio to be played to the caller.
  7. DTMF Events: When the caller presses keys, Plivo sends dtmf events with the digit information.
  8. Control Events: Your server can send clearAudio to interrupt playback or checkpoint to track playback progress.
  9. Connection Close: When the call ends or streaming stops, the WebSocket connection closes.

Stream XML

The <Stream> XML element initiates audio streaming for a call. Include it in your Answer URL response.

Basic Syntax

Parameters

Supported Content Types

Examples

Bidirectional Stream with mu-law Codec

Stream with Status Callbacks and Extra Headers


Stream APIs

Control active streams programmatically via REST API calls.

Base URL

Authentication

Use HTTP Basic Authentication with your Plivo Auth ID and Auth Token.

Stop a Stream

Endpoint: DELETE /v1/Account/{auth_id}/Call/{call_uuid}/Stream/

Get Stream Details

Endpoint: GET /v1/Account/{auth_id}/Call/{call_uuid}/Stream/

Using the Plivo SDK

Node.js

Python


Stream Status Callbacks

Configure a callback URL to receive notifications about stream lifecycle events.

Configuration

Callback Parameters

Example Handler


Signature Validation

Plivo signs WebSocket connection requests to verify authenticity. Validate these signatures to ensure requests originate from Plivo.

V3 Signature Headers

Using the Plivo SDK

Using the Node.js Stream SDK

The plivo-stream-sdk-node handles signature validation automatically:
When validateSignature is enabled, connections with invalid signatures are automatically rejected with a 1008 WebSocket close code.

WebSocket Events

All communication over the WebSocket uses JSON messages. Here are the essential events you need to handle.

Events from Plivo (Input)

Events to Plivo (Output)

Quick Example

For complete event schemas, TypeScript types, and detailed field documentation, see the Audio Streaming Protocol Reference.

X-Headers

Pass custom metadata from your Stream XML to your WebSocket server.

Usage

Parsing


Limits

WebSocket and Stream Limits


Best Practices

Use mu-law 8000Hz

Why mu-law at 8kHz is recommended:
  1. Native Telephony Format: No transcoding required, lowest latency
  2. Bandwidth Efficient: Compresses 16-bit audio to 8-bit while maintaining voice quality
  3. Universal Compatibility: Every STT/TTS service supports mu-law
  4. Sufficient for Voice: Human speech is well-represented at 8kHz

Minimize Latency

For a responsive Voice AI experience, aim for under 1 second total response time: Server Location: Deploy your WebSocket server close to your expected caller locations. Plivo routes calls through the edge location closest to the caller.

Handle Interruptions

Always support user interruption using clearAudio:

Integration Guides

For complete code examples and step-by-step tutorials:

Plivo Stream SDK

Official SDKs for Python, Node.js, and Java with full examples using Deepgram, OpenAI, and ElevenLabs

Pipecat

Build with the Pipecat framework for simplified voice AI pipelines

Next Steps


Support

For questions, issues, or feature requests:
Last updated: January 2026