Skip to content

exotel/Agent-Stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Voice AI Bot System

A production-ready, conversational AI voice bot that bridges Exotel's WebSocket streaming with OpenAI's Realtime API for natural, speech-to-speech conversations over phone calls.

🎯 What This Bot Does

  • πŸ—£οΈ Natural Conversations: Real-time speech-to-speech using OpenAI's latest Realtime API
  • πŸ“ž Telephony Integration: Seamless integration with Exotel's voice streaming services
  • πŸ›‘ Smart Interruption: Handles conversation interruptions naturally
  • πŸ”Š Audio Enhancement: Built-in noise suppression and audio optimization for telephony
  • ⚑ Real-time Processing: 200ms audio buffering for smooth conversation flow
  • πŸ”’ Security First: Environment-based configuration, no hardcoded secrets
  • 🎡 High-Quality Audio: 24kHz PCM16 audio format for superior voice quality

πŸš€ Quick Start

Prerequisites

  • Python 3.8+
  • OpenAI API key with Realtime API access
  • Exotel account with Voicebot Applet access

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd Agent-Stream
  2. Create a virtual environment:

    python3 -m venv venv
    source venv/bin/activate  # Windows: venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Configure environment variables:

    cp env.example .env
    # Edit .env with your OpenAI API key and other settings

Configuration

Edit your .env file with the following required settings:

# REQUIRED - Get from OpenAI dashboard
OPENAI_API_KEY=your-openai-api-key-here

# SERVER CONFIG
SERVER_HOST=0.0.0.0
SERVER_PORT=5000

# BOT PERSONALITY
COMPANY_NAME=Your Company Name
SALES_BOT_NAME=Sarah

# AUDIO SETTINGS
SAMPLE_RATE=24000
AUDIO_CHUNK_SIZE=200

Running the Bot

# Start the bot
python main.py

# Test the configuration
python main.py --config-check

# Run system tests
python main.py --test

The bot will start a WebSocket server on 0.0.0.0:5000.

πŸ“‘ Exotel Integration

WebSocket URLs

  • Local: ws://localhost:5000
  • Public: Use ngrok or your server's public IP

Exotel Voicebot Applet Configuration

  1. URL: wss://your-domain.com/?sample-rate=24000
  2. Sample Rate: 24kHz (recommended for high quality)
  3. Audio Format: Raw/slin (16-bit PCM)
  4. Bidirectional Streaming: Enabled

Test Message Format

{
  "event": "connected"
}

πŸ—οΈ Project Structure

.
β”œβ”€β”€ .env                 # Environment variables (local)
β”œβ”€β”€ .gitignore           # Git ignore file
β”œβ”€β”€ LICENSE              # Project license
β”œβ”€β”€ README.md            # This README file
β”œβ”€β”€ config.py            # Centralized configuration
β”œβ”€β”€ core/                # Core bot logic and framework
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ bot_framework.py
β”‚   └── openai_realtime_sales_bot.py
β”œβ”€β”€ engines/             # AI engine components (STT, TTS, NLP, etc.)
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ audio_enhancer.py
β”‚   β”œβ”€β”€ media_resampler.py
β”‚   β”œβ”€β”€ nlp_engine.py
β”‚   β”œβ”€β”€ stt_engine.py
β”‚   └── tts_engine.py
β”œβ”€β”€ env.example          # Example environment variables
β”œβ”€β”€ main.py              # Main entry point for the application
β”œβ”€β”€ requirements.txt     # Python dependencies
└── venv/                # Python virtual environment

πŸ”§ Configuration Options

Audio Settings

  • SAMPLE_RATE: Audio sample rate (8000, 16000, 24000)
  • AUDIO_CHUNK_SIZE: Chunk size in milliseconds (default: 200)
  • BUFFER_SIZE_MS: Audio buffer size (default: 160)

Bot Personality

  • COMPANY_NAME: Your company name
  • SALES_BOT_NAME: Bot's name
  • OPENAI_VOICE: Voice selection (coral, nova, shimmer)

Server Settings

  • SERVER_HOST: Server host (default: 0.0.0.0)
  • SERVER_PORT: Server port (default: 5000)

πŸš€ Deployment

Option 1: Development (ngrok)

# Install ngrok
./ngrok http 5000
# Use: wss://xxxxx.ngrok-free.app

Option 2: Cloud VPS

# Setup on DigitalOcean/AWS/GCP
sudo ufw allow 5000
python main.py
# Use: wss://your-server-ip:5000

Option 3: Docker

# Build and run
docker build -t voice-bot .
docker run --env-file .env -p 5000:5000 voice-bot

πŸ§ͺ Testing

Basic Tests

# Test configuration
python main.py --config-check

# Test bot connection
python main.py --test

Manual Testing

# Using wscat
wscat -c ws://localhost:5000

# Send test message
{"event": "connected"}

πŸ”’ Security

  • All sensitive information is stored in environment variables
  • No hardcoded API keys or tokens
  • .env file is gitignored
  • Use HTTPS/WSS in production

πŸ“Š Monitoring

Key Metrics

  • Call Duration
  • Bot Response Time
  • Audio Quality Score
  • Conversation Completion Rate
  • Error Rate

Log Analysis

# Monitor key events
grep "NEW EXOTEL CONNECTION" logs/bot.log
grep "CONVERSATION COMPLETED" logs/bot.log
grep "ERROR" logs/bot.log

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

  • Check the troubleshooting section in the README
  • Review GitHub Issues for similar problems
  • Post detailed issues with logs and configuration

πŸ™ Acknowledgments

About

This is a sample bot to test - voice streaming Exotel Services(Sales Bot)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages