A sophisticated real-time conversational AI platform with multi-provider support, emotional intelligence, and advanced conversation features.
- Multi-Provider AI Integration: OpenAI, Ollama, XAI, and Anthropic support with automatic failover
- Advanced TTS System: Multiple TTS providers (OpenAI, ElevenLabs, XTTS, Kokoro) with emotional voice modulation
- Character Management: Dynamic character system with mood-based prompt adaptation
- Real-time Communication: WebSocket support with heartbeat monitoring and state synchronization
- Sentiment Analysis: Intelligent mood detection and character response adaptation
- Enhanced Conversations: Personality adaptation, topic tracking, and conversation analytics
- Emotional Intelligence: Sentiment analysis with mood tracking and adaptive responses
- Dynamic Personality: Real-time personality adaptation based on conversation context
- Emotional TTS: Voice modulation based on detected emotions and conversation mood
- Topic Tracking: Intelligent conversation flow analysis and topic management
- State Management: Comprehensive state synchronization across sessions
- Configuration Management: Flexible, multi-source configuration system
- Python 3.11 or higher
- Node.js 16+ (for frontend components)
- Redis (optional, for enhanced caching)
- PostgreSQL or SQLite (for data persistence)
- Clone the Repository
git clone https://github.com/your-org/voice-chat-ai.git
cd voice-chat-ai- Install Dependencies
pip install -r requirements.txt- Environment Configuration
cp .env.example .env
# Edit .env with your API keys and configuration- Initialize Database
python -m app.db.init- Run the Application
python -m app.main_newdocker-compose up -d# OpenAI Configuration
OPENAI_API_KEY=your_openai_api_key
OPENAI_MODEL=gpt-4o-mini
OPENAI_BASE_URL=https://api.openai.com/v1
# Anthropic Configuration
ANTHROPIC_API_KEY=your_anthropic_api_key
ANTHROPIC_MODEL=claude-3-sonnet-20240229
# XAI Configuration
XAI_API_KEY=your_xai_api_key
XAI_MODEL=grok-beta
# Primary Provider
MODEL_PROVIDER=openai# ElevenLabs Configuration
ELEVENLABS_API_KEY=your_elevenlabs_api_key
# TTS Provider Selection
TTS_PROVIDER=openaiHOST=0.0.0.0
PORT=8000
DEBUG=false
ENVIRONMENT=productionDATABASE_URL=postgresql://user:password@localhost:5432/voicechat
REDIS_URL=redis://localhost:6379SECRET_KEY=your-secret-key-min-32-charactersCreate config.yaml for advanced configuration:
ai_providers:
primary_provider: "openai"
fallback_providers: ["ollama", "xai", "anthropic"]
openai_model: "gpt-4o-mini"
openai_temperature: 0.8
tts_providers:
primary_provider: "openai"
fallback_providers: ["elevenlabs"]
openai_voice: "alloy"
features:
sentiment_analysis: true
enhanced_conversations: true
emotional_tts: true
personality_adaptation: true
topic_tracking: true
websocket_support: true
analytics: true
server:
host: "0.0.0.0"
port: 8000
workers: 4
log_level: "info"
security:
rate_limit_requests_per_minute: 60
rate_limit_requests_per_hour: 1000
cors_origins: ["*"]βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Frontend β β WebSocket β β API Gateway β
β (React/Vue) βββββΊβ Manager βββββΊβ (FastAPI) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β β β
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β AI Provider β β TTS Providerβ β Character β
β Service β β Service β β Service β
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β β β
βββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββ
β OpenAI β Ollama β XAI β ... β β OpenAI β ElevenLabs β ... β β Sentiment β Enhanced β ... β
βββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββ
- AIProviderService: Multi-provider AI integration with failover
- TTSProviderService: Text-to-speech with emotional modulation
- CharacterService: Character management and prompt adaptation
- SentimentAnalysisService: Mood detection and emotional intelligence
- EnhancedConversationService: Advanced conversation features
- StateManager: Distributed state management
- ConfigurationManager: Multi-source configuration management
- Character Management: CRUD operations for characters
- Conversation API: Enhanced conversation endpoints
- Provider Management: AI and TTS provider configuration
- Sentiment Analysis: Mood detection and adaptation endpoints
- Configuration API: Runtime configuration management
- WebSocket API: Real-time communication
- Character Models: Character definitions and metadata
- Conversation Models: Message history and context
- Sentiment Models: Emotion and mood tracking
- Audio Models: TTS and STT configurations
- State Models: Application state management
Characters are defined in JSON files with the following structure:
{
"name": "assistant",
"display_name": "AI Assistant",
"description": "A helpful AI assistant",
"personality": "Friendly and knowledgeable",
"background": "Professional AI assistant",
"speaking_style": "Clear and helpful",
"system_prompt": "You are a helpful AI assistant...",
"example_messages": [
{
"role": "user",
"content": "Hello!"
},
{
"role": "assistant",
"content": "Hello! How can I help you today?"
}
],
"voice_config": {
"provider": "openai",
"voice_id": "alloy",
"speed": 1.0,
"pitch": 1.0
},
"mood_prompts": {
"happy": "Respond with enthusiasm and joy",
"sad": "Respond with empathy and comfort",
"excited": "Match their excitement level",
"calm": "Maintain a peaceful, centered tone"
}
}- Create Character File
cp app/characters/assistant.json app/characters/my_character.json- Edit Character Properties
{
"name": "my_character",
"display_name": "My Custom Character",
"system_prompt": "You are my custom character with unique traits...",
"voice_config": {
"provider": "elevenlabs",
"voice_id": "custom_voice"
}
}- Load Character via API
curl -X POST "http://localhost:8000/characters/" \
-H "Content-Type: application/json" \
-d @app/characters/my_character.jsontts_config = {
"provider": "openai",
"voice_id": "alloy", # alloy, echo, fable, onyx, nova, shimmer
"model": "tts-1-hd",
"speed": 1.0
}tts_config = {
"provider": "elevenlabs",
"voice_id": "your_voice_id",
"stability": 0.5,
"similarity_boost": 0.5
}emotional_config = {
"base_voice": "alloy",
"emotional_intensity": "moderate",
"voice_style": "empathetic",
"speed_adjustment": 1.0,
"pitch_adjustment": 1.0
}The system automatically detects:
- Primary Emotions: Happy, sad, angry, fearful, surprised, neutral
- Mood States: Excited, calm, melancholy, anxious, confident, playful
- Sentiment Scores: Positive, negative, neutral, compound
Characters automatically adapt responses based on:
- User's detected emotional state
- Conversation history and patterns
- Character personality configuration
- Contextual conversation flow
# Analyze sentiment
response = await sentiment_analyzer.analyze_sentiment("I'm feeling great today!")
# Adapt character response
adapted_prompt = await mood_adaptation_service.adapt_character_response(
character=character,
user_message="I'm feeling great today!",
sentiment_analysis=response,
conversation_id="conv_123",
user_id="user_456"
)# Build image
docker build -t voice-chat-ai .
# Run container
docker run -d \
--name voice-chat-ai \
-p 8000:8000 \
-e OPENAI_API_KEY=your_key \
-e DATABASE_URL=your_db_url \
voice-chat-aiversion: '3.8'
services:
app:
build: .
ports:
- "8000:8000"
environment:
- OPENAI_API_KEY=${OPENAI_API_KEY}
- DATABASE_URL=postgresql://user:pass@db:5432/voicechat
depends_on:
- db
- redis
db:
image: postgres:15
environment:
POSTGRES_DB: voicechat
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
volumes:
- postgres_data:/var/lib/postgresql/data
redis:
image: redis:7-alpine
volumes:
- redis_data:/data
volumes:
postgres_data:
redis_data:# Install dependencies
pip install -r requirements.txt
# Set environment variables
export OPENAI_API_KEY=your_key
export DATABASE_URL=your_db_url
export ENVIRONMENT=production
# Run with Gunicorn
gunicorn app.main_new:app -w 4 -k uvicorn.workers.UvicornWorker- Use load balancer (nginx, HAProxy)
- Redis for session storage
- PostgreSQL with read replicas
- Container orchestration (Kubernetes, Docker Swarm)
- Enable Redis caching
- Use CDN for static assets
- Configure database connection pooling
- Implement response caching
- Use async/await patterns
/health- Application health/config/health- Configuration system health/sentiment/health- Sentiment analysis health/enhanced/health- Enhanced features health
- Request/response times
- Provider response times
- Error rates by endpoint
- WebSocket connection counts
- Sentiment analysis accuracy
- Character usage statistics
logging:
level: "INFO"
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
file_path: "/var/log/voice-chat-ai.log"
max_file_size: 10485760 # 10MB
backup_count: 5# Install development dependencies
pip install -r requirements-dev.txt
# Run in development mode
python -m app.main_new --reload
# Run tests
pytest
# Code formatting
black app/
isort app/
# Type checking
mypy app/- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
# Run all tests
pytest
# Run specific test categories
pytest -m unit
pytest -m integration
# Run with coverage
pytest --cov=app --cov-report=html- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
- Follow PEP 8
- Use type hints
- Write comprehensive docstrings
- Add unit tests for new features
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: Full Documentation
- Issues: GitHub Issues
- Discussions: GitHub Discussions