Plivo helps businesses leverage OpenAI’s cutting-edge Real-time Speech-to-Speech (S2S) capabilities through seamless integration with Plivo’s Audio Streaming API. This powerful combination enables you to create sophisticated AI voice assistants that can engage in natural conversations, handle interruptions gracefully, and provide real-time responses to user queries.
Before beginning your AI voice assistant development, sign up for Plivo or sign in to your existing account. You’ll need to purchase a voice-enabled number through the Voice API or Plivo console.
Ensure you have the following before starting:
git clone https://github.com/plivo/AI-Voice-Agents.git
cd AI-Voice-Agents/Openai-realtime-api/Python
git clone https://github.com/plivo/AI-Voice-Agents.git
cd AI-Voice-Agents/Openai-realtime-api/NodeJS
1. Create a Tunnel with ngrok For local development, you’ll need a public URL to receive webhooks. Open a terminal and run:
ngrok http 5000
Copy the Forwarding URL (format: https://[your-ngrok-subdomain].ngrok.app). You’ll need this for the Plivo Answer XML.
Note: The port 5000 is this application’s default. If you change the PORT in index.js (in case of Node) or server.py (in case of Python), update the ngrok command accordingly. Remember that each new ngrok session creates a new URL requiring configuration updates.
2. Install Required Packages
pip install -r requirements.txt
If you are using Node.js:
npm install
3. Configure Environment Variables
Create a .env file in your project root and set up the following:
PLIVO_AUTH_ID=<YOUR_PLIVO_AUTH_ID>
PLIVO_AUTH_TOKEN=<YOUR_PLIVO_AUTH_TOKEN>
PLIVO_FROM_NUMBER=<YOUR_PLIVO_NUMBER>
PLIVO_TO_NUMBER=<CALLER_PHONE_NUMBER>
OPENAI_API_KEY=<YOUR_OPEN_AI_API_KEY>
Use this template for your Plivo application’s Answer XML:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Speak>Connected to AI Assistant. You may begin speaking.</Speak>
<Stream keepCallAlive="true" audioTrack="both">
wss://[your-ngrok-subdomain].ngrok.app/stream
</Stream>
</Response>
Update the PLIVO_ANSWER_XML variable in your .env file with your Answer URL.
python server.py
node index.js
The application will automatically initiate a call to the number specified in PLIVO_TO_NUMBER. Once the call is answered, you can begin interacting with your AI assistant.
Your AI voice assistant includes:
If you encounter issues:
Consider these enhancements for your AI assistant:
For additional support: