A comprehensive, intelligent WebSocket echo server with conversational AI behavior and real-time monitoring dashboard specifically designed for testing Exotel's voice streaming functionality. Features advanced audio buffering, silence detection, and interactive analytics.
🧠 Conversational AI Echo: Listens first, detects silence, then responds naturally - no more immediate echo interruptions
🎧 Audio Buffering: Intelligently buffers incoming audio and responds after silence detection
🛑 Smart Interruption: Handles CLEAR events to stop speaking and reset conversation state
📊 Real-time Dashboard: Live monitoring with interactive latency metrics and event visualization
🔍 Advanced Protocol Testing: Handles all Exotel WebSocket events with enhanced logging and response acknowledgments
⚡ Production Ready: Robust error handling, session management, and multiline log parsing
🚀 Easy Setup: One-command installation with automated dependency management
- Listen → Silence → Respond: Natural conversation flow instead of immediate echo
- Audio Buffering: Collects audio chunks during listening phase
- Silence Detection: 2-second silence threshold before responding
- Clear Interruption: Instantly stops and resets on CLEAR events
- Session Management: Per-call state tracking and cleanup
- Real-time Event Feed: Live stream of all voice bot activities
- Latency Analytics: Inter-event, first media, and end-to-end latency tracking
- Interactive Tooltips: Hover explanations for all metrics
- Call Session Tracking: Detailed per-call event analysis
- Multiline Log Parsing: Accurate DTMF digit extraction and event correlation
Note: The dashboard is provided as a sample reference implementation. While it provides valuable insights into system behavior, data accuracy may vary depending on log timing and parsing complexity. Use it for monitoring and debugging purposes.
- Python 3.8+
- Ports 5000 (server) and 5001 (dashboard) available
- Internet connection
# Clone the repository
git clone https://github.com/exotel/Agent-Stream-echobot.git
cd Agent-Stream-echobot
# One-command setup
chmod +x setup.sh && ./setup.sh# Start both server and dashboard
./start.sh
# Or start individually:
# Enhanced Echo Server (port 5000)
source venv/bin/activate && python3 simple_server.py &
# AgentStream Dashboard (port 5001)
source venv/bin/activate && python3 dashboard.py &Access Points:
- 🤖 Echo Server:
ws://localhost:5000 - 📊 Dashboard:
http://localhost:5001
To test with Exotel, you need a public WSS URL:
# Install ngrok (if not already installed)
brew install ngrok # macOS
# or download from https://ngrok.com/
# Configure your ngrok authtoken
ngrok config add-authtoken YOUR_NGROK_TOKEN
# Make your server public
ngrok http 5000Use the wss:// URL from ngrok in your Exotel configuration.
# Test local server
python3 test_connection.py
# Test public ngrok URL
python3 test_connection.py wss://your-ngrok-url.ngrok.io# Test conversational behavior and all features
python3 test_enhanced_features.py- URL:
wss://your-ngrok-url.ngrok.io - Custom Parameters: Optional (will be logged)
- Record: Enable if you want call recordings
- Next Applet: Configure your next flow step
- Action: Start
- URL:
wss://your-ngrok-url.ngrok.io - Next Applet: Configure your next flow step
User speaks → Immediate echo → Interruption → Poor UX
1. 🎧 LISTENING: User speaks → Audio buffering
2. 🤔 SILENCE: 2s silence detected → Prepare response
3. 🗣️ SPEAKING: Send buffered audio naturally
4. 🛑 CLEAR: Handle interruptions gracefully
5. 👂 RESET: Ready for next turn
- 📈 Live Metrics: Calls, media packets, events with tooltips
- ⏱️ Latency Tracking:
- Avg Latency: Time between consecutive events
- First Media: Connection to first audio packet
- End-to-End: Complete call duration
- 🎯 Event Feed: Real-time activity stream with filtering
- 📱 Call Sessions: Interactive call selection and analysis
- 🧹 Log Management: Clear logs and export functionality
The server creates comprehensive logs in the logs/ directory:
voice_bot_echo.log: Enhanced server activity with conversation flowcalls.log: Individual call details in JSON format
# Watch enhanced server logs
tail -f logs/voice_bot_echo.log
# Monitor conversational behavior
grep -E "(LISTENING|BUFFERING|SILENCE|SPEAKING|CLEAR)" logs/voice_bot_echo.log
# Watch specific events
grep "DTMF EVENT" logs/voice_bot_echo.logAgent-Stream-echobot/
├── simple_server.py # Enhanced conversational echo server
├── dashboard.py # Real-time monitoring dashboard
├── dashboard_fixed.py # Dashboard optimizations
├── enhanced_parser.py # Advanced log parsing utilities
├── test_connection.py # Basic connection testing
├── test_enhanced_features.py # Comprehensive feature testing
├── requirements.txt # Enhanced dependencies (Flask, SocketIO)
├── setup.sh # Automated setup script
├── start.sh # Multi-service startup script
├── templates/
│ └── dashboard.html # Interactive dashboard UI
├── logs/ # Log files (created at runtime)
│ ├── voice_bot_echo.log # Enhanced server logs
│ └── calls.log # Call session data
└── venv/ # Virtual environment
Choose between immediate echo (traditional) or conversational AI mode:
# In simple_server.py - Line ~153
IMMEDIATE_ECHO_MODE = True # Traditional immediate echo for testing
IMMEDIATE_ECHO_MODE = False # Conversational AI with silence detectionclass VoiceSession:
def __init__(self, connection_id, websocket):
# Customize these parameters
self.silence_threshold = 2.0 # Seconds before responding
self.response_delay = 0.1 # Delay between audio chunksEdit dashboard.py for custom analytics:
# Modify latency calculations
live_stats = {
'custom_metric': your_calculation,
'threshold_alerts': custom_thresholds
}# Set custom ports via environment variables
export ECHO_PORT=8080
export DASHBOARD_PORT=8081
# Or edit the files directly# Check server status
curl -f http://localhost:5000 || echo "Server not responding"
# Monitor conversation flow
grep -E "(LISTENING|SPEAKING)" logs/voice_bot_echo.log | tail -10
# Check session cleanup
grep "Connection ended" logs/voice_bot_echo.log | tail -5# Verify dashboard
curl -f http://localhost:5001 || echo "Dashboard not accessible"
# Check log parsing
grep "Error parsing" logs/*
# Monitor WebSocket connections
grep "connected\|disconnected" logs/voice_bot_echo.log- High Inter-event Latency: Check network connection and server load
- Poor First Media: Verify Exotel connection establishment
- Long End-to-End: Review call flow and timeout configurations
async def start_response(self):
"""Enhanced response with custom processing"""
for i, media_data in enumerate(self.audio_buffer):
# Your custom audio processing
processed_audio = your_audio_processor(media_data)
# Send enhanced response
echo_response = {
'event': 'media',
'stream_sid': self.stream_sid,
'media': processed_audio
}
await self.websocket.send(json.dumps(echo_response))# Add custom analytics
def calculate_custom_metrics(events):
return {
'speech_to_silence_ratio': calculate_ratio(events),
'interruption_frequency': count_clears(events),
'conversation_turns': count_turns(events)
}FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000 5001
# Start both services
CMD ["bash", "-c", "python3 simple_server.py & python3 dashboard.py & wait"]# On your cloud server
git clone https://github.com/exotel/Agent-Stream-echobot.git
cd Agent-Stream-echobot
./setup.sh
# Use reverse proxy for HTTPS
nginx -t && systemctl reload nginx# Production configuration
export LOG_LEVEL=INFO
export ECHO_PORT=5000
export DASHBOARD_PORT=5001
export SILENCE_THRESHOLD=1.5
export ENABLE_DASHBOARD=true- Inter-event Latency: < 50ms (excellent), < 100ms (good)
- First Media Latency: < 200ms (excellent), < 500ms (good)
- End-to-End Latency: Depends on call duration
- Silence Detection: 2s threshold (configurable)
- Concurrent Calls: 100+ (single instance)
- Memory Usage: ~50MB base + ~1MB per active call
- CPU Usage: < 5% (idle), < 20% (active calls)
- Normal Flow: Speak → Wait → Hear response
- Interruption: Speak → Send CLEAR → Verify stop
- Multiple Turns: Alternate speaking/listening
- DTMF Integration: Test keypress during conversation
# Simulate multiple concurrent calls
for i in {1..10}; do
python3 test_enhanced_features.py &
done- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
# Development mode with hot reload
export FLASK_ENV=development
python3 dashboard.py
# Test with verbose logging
export LOG_LEVEL=DEBUG
python3 simple_server.pyThis project is licensed under the MIT License - see the LICENSE file for details.
- 🐛 Issues: GitHub Issues
- 📚 Exotel Docs: Voice Streaming Guide
- 🔧 WebSockets: Python websockets library
- 📊 Flask-SocketIO: Real-time documentation
- 🧪 Testing: Validate Exotel voice streaming with realistic conversation flow
- 🔍 Debugging: Analyze audio latency and protocol behavior
- 🎓 Learning: Study conversational AI and WebSocket telephony
- 🚀 Foundation: Starting point for building production voice bots
- 📊 Monitoring: Real-time analytics for voice streaming performance
- 🤖 AI Development: Test natural conversation patterns and interruption handling
- 🧠 AI Integration: Real conversational AI responses
- 📊 Advanced Analytics: Call quality metrics and insights
- 🌍 Multi-language: Support for different audio formats
- ☁️ Cloud Integration: Direct cloud deployment templates
- 📱 Mobile Dashboard: Responsive mobile monitoring interface
🚀 Ready to experience natural voice conversations with Exotel? This enhanced echo server brings AI-like behavior to voice testing!
Made with ❤️ for the Exotel developer community | Enhanced with Conversational AI & Real-time Analytics