System Requirements
Before installing the AI Voice Testing Platform, ensure your system meets these requirements:- Python: 3.8 or higher
- Operating System: Linux, macOS, or Windows
- Memory: 512 MB RAM minimum (1 GB recommended)
- Network: Internet connection for API calls to OpenAI and ElevenLabs
Installation Methods
Method 1: Standard Installation (Recommended)
This method uses Python’s built-in virtual environment for dependency isolation.Create a virtual environment
Create an isolated Python environment:Or use This creates a
python3 if your system has both Python 2 and 3:.venv directory containing an isolated Python installation.Activate the virtual environment
(.venv).On Windows PowerShell, you may need to enable script execution:
Install dependencies
Install all required packages from This installs:
requirements.txt:| Package | Version | Purpose |
|---|---|---|
flask | 3.0.0 | Web framework for API and UI |
elevenlabs | 1.14.0 | ElevenLabs SDK for voice synthesis |
python-dotenv | 1.0.0 | Environment variable management |
openai | 1.55.0 | OpenAI SDK for GPT-4o-mini chat |
Method 2: System-Wide Installation (Not Recommended)
You can install dependencies globally without a virtual environment:Configuration
Environment Variables
The application uses environment variables for sensitive configuration. These are loaded viapython-dotenv in app.py:15.
Create your .env file
Copy the example file:The
.env.example file contains all required variables with placeholder values.Variable Reference
FLASK_SECRET_KEY (Required)
Purpose: Encrypts Flask session cookies to protect user data. Usage:app.py:18
Generation:
"dev-secret-change-in-production" (only for development)
OPENAI_API_KEY (Required for chat)
Purpose: Authenticates requests to OpenAI for GPT-4o-mini chat completions. Usage:app.py:198, app.py:203
Model: gpt-4o-mini (configured in app.py:205)
Get your key: OpenAI Platform
Fallback: If not set, the chat endpoint returns a placeholder message instead of failing.
ELEVENLABS_API_KEY (Required for voice)
Purpose: Authenticates requests to ElevenLabs for text-to-speech and phone calls. Usage:app.py:28, app.py:96, app.py:106
Voice ID: JBFqnCBsd6RMkjVDRZzb (George voice, configured in app.py:134)
Model: eleven_turbo_v2_5 (configured in app.py:135)
Get your key: ElevenLabs Dashboard
ELEVENLABS_AGENT_ID (Required for phone calls)
Purpose: Specifies which ElevenLabs Conversational AI agent to use for outbound calls. Usage:app.py:242, app.py:248
Setup:
- Create a Conversational AI agent in ElevenLabs
- Enable prompt overrides on the agent
- Copy the agent ID from the dashboard
Prompt overrides must be enabled for the app to inject business descriptions at call time via
conversation_config_override (app.py:75-83).ELEVENLABS_AGENT_PHONE_NUMBER_ID (Required for phone calls)
Purpose: Specifies which phone number to use as the caller ID for outbound calls. Usage:app.py:242, app.py:249
Setup:
- Connect a Twilio phone number in ElevenLabs
- Copy the phone number ID from the ElevenLabs dashboard
/v1/convai/twilio/outbound-call endpoint (app.py:258)
ELEVENLABS_API_BASE (Optional)
Purpose: Override the default ElevenLabs API base URL. Default:https://api.elevenlabs.io
Usage: app.py:20
Use case: Testing against a different ElevenLabs environment or proxy.
Running the Application
Development Mode
Start the Flask development server with debug mode enabled:http://localhost:5000 with:
- Debug mode: Enabled (
app.py:277) - Auto-reload: Changes to
app.pytrigger automatic restart - Detailed errors: Full stack traces in the browser
Production Mode
For production deployments, use a WSGI server like Gunicorn:Run with Gunicorn
-w 4: Use 4 worker processes-b 0.0.0.0:5000: Bind to all interfaces on port 5000app:app: Importappobject fromapp.py
Custom Port
To run on a different port, modifyapp.py:277:
app.py
app.py
File Structure
Key application files:app.py Structure
The main application file contains:| Lines | Component | Description |
|---|---|---|
| 1-14 | Imports | Flask, OpenAI, ElevenLabs, urllib |
| 15-24 | Configuration | Load env vars, set constants |
| 27-92 | Helper Functions | API clients, session management, prompt building |
| 95-124 | ElevenLabs Integration | Generic POST helper for ElevenLabs API |
| 127-137 | Text-to-Speech | Convert text to MP3 using ElevenLabs |
| 140-162 | /tts Endpoint | Standalone TTS endpoint |
| 164-175 | /api/context Endpoint | Initialize conversation session |
| 178-223 | /api/chat Endpoint | Main chat interface with OpenAI + ElevenLabs |
| 226-273 | /api/call Endpoint | Outbound phone call initiation |
| 276-277 | Server | Run Flask development server |
Session Management
The app uses Flask’s encrypted session cookies to maintain conversation state: Stored in session (app.py:174-175):
business_description: Business context for the AIscenario: Caller goal/taskmessages: Conversation history (list of dicts)
app.py:53-54):
FLASK_SECRET_KEY
Sessions are stored client-side in cookies. For high-volume production use, consider Redis or database-backed sessions.
Conversation Flow Implementation
The chat endpoint maintains context using OpenAI’s message history: Initial message (app.py:193-194):
app.py:195):
app.py:204-208):
app.py:212-213):
Phone Call Implementation
Outbound calls are initiated via ElevenLabs’ Twilio integration: Payload structure (app.py:247-255):
app.py:91-92, app.py:24):
+15551234567, +447911123456, etc.
Troubleshooting
Import Errors
Problem:ModuleNotFoundError: No module named 'flask'
Solution: Ensure your virtual environment is activated and dependencies are installed:
Environment Variable Issues
Problem: “ELEVENLABS_API_KEY not set in .env” Solution:- Verify
.envfile exists in the same directory asapp.py - Check for typos in variable names
- Ensure no spaces around
=in.env:
Port Already in Use
Problem:OSError: [Errno 48] Address already in use
Solution: Another process is using port 5000. Either:
- Kill the other process:
- Change the port in
app.py:277
ElevenLabs API Errors
Problem:ElevenLabs API error (401): Unauthorized
Solution: Check your ELEVENLABS_API_KEY is valid and has sufficient credits.
Problem: ElevenLabs API error (404) on phone calls
Solution: Verify ELEVENLABS_AGENT_ID and ELEVENLABS_AGENT_PHONE_NUMBER_ID are correct.
OpenAI API Errors
Problem: Rate limit or quota exceeded Solution: The app usesgpt-4o-mini for cost efficiency (app.py:205). Check your OpenAI usage limits.
Security Best Practices
- Never commit
.envfiles - Add.envto.gitignore - Use strong secret keys - Generate with
secrets.token_hex(32) - Disable debug mode - Set
debug=Falsein production - Use HTTPS - Configure SSL/TLS on your reverse proxy
- Validate inputs - The app validates phone numbers (
app.py:236), but add additional input validation for your use case - Rate limiting - Implement rate limits to prevent API abuse
- Environment isolation - Use separate API keys for dev/staging/production
Next Steps
Quickstart Guide
Learn how to run your first AI conversation
API Reference
Explore detailed API endpoint documentation