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