This comprehensive session management system tracks and automatically cleans up resources associated with user sessions, preventing resource exhaustion and disk space issues. Key features: - Automatic tracking of all session resources (audio files, temp files, streams) - Per-session resource limits (100 files max, 100MB storage max) - Automatic cleanup of idle sessions (15 minutes) and expired sessions (1 hour) - Background cleanup thread runs every minute - Real-time monitoring via admin endpoints - CLI commands for manual management - Integration with Flask request lifecycle Implementation details: - SessionManager class manages lifecycle of UserSession objects - Each session tracks resources with metadata (type, size, creation time) - Automatic resource eviction when limits are reached (LRU policy) - Orphaned file detection and cleanup - Thread-safe operations with proper locking - Comprehensive metrics and statistics export - Admin API endpoints for monitoring and control Security considerations: - Sessions tied to IP address and user agent - Admin endpoints require authentication - Secure file path handling - Resource limits prevent DoS attacks This addresses the critical issue of temporary file accumulation that could lead to disk exhaustion in production environments. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> |
||
---|---|---|
static | ||
templates | ||
venv | ||
.env.example | ||
.gitignore | ||
app.py | ||
config.py | ||
CONNECTION_RETRY.md | ||
CORS_CONFIG.md | ||
GPU_SUPPORT.md | ||
health-monitor.py | ||
maintenance.sh | ||
manage_secrets.py | ||
package-lock.json | ||
package.json | ||
rate_limiter.py | ||
RATE_LIMITING.md | ||
README_TYPESCRIPT.md | ||
README.md | ||
requirements.txt | ||
SECRETS_MANAGEMENT.md | ||
secrets_manager.py | ||
SECURITY.md | ||
SESSION_MANAGEMENT.md | ||
session_manager.py | ||
setup-script.sh | ||
test_session_manager.py | ||
test-cors.html | ||
tsconfig.json | ||
tts_test_output.mp3 | ||
tts-debug-script.py | ||
validators.py | ||
whisper_config.py |
Voice Language Translator
A mobile-friendly web application that translates spoken language between multiple languages using:
- Gemma 3 open-source LLM via Ollama for translation
- OpenAI Whisper for speech-to-text
- OpenAI Edge TTS for text-to-speech
Supported Languages
- Arabic
- Armenian
- Azerbaijani
- English
- French
- Georgian
- Kazakh
- Mandarin
- Farsi
- Portuguese
- Russian
- Spanish
- Turkish
- Uzbek
Setup Instructions
-
Install the required Python packages:
pip install -r requirements.txt
-
Configure secrets and environment:
# Initialize secure secrets management python manage_secrets.py init # Set required secrets python manage_secrets.py set TTS_API_KEY # Or use traditional .env file cp .env.example .env nano .env
⚠️ Security Note: Talk2Me includes encrypted secrets management. See SECURITY.md and SECRETS_MANAGEMENT.md for details.
-
Make sure you have Ollama installed and the Gemma 3 model loaded:
ollama pull gemma3
-
Ensure your OpenAI Edge TTS server is running on port 5050.
-
Run the application:
python app.py
-
Open your browser and navigate to:
http://localhost:8000
Usage
- Select your source language from the dropdown menu
- Press the microphone button and speak
- Press the button again to stop recording
- Wait for the transcription to complete
- Select your target language
- Press the "Translate" button
- Use the play buttons to hear the original or translated text
Technical Details
- The app uses Flask for the web server
- Audio is processed client-side using the MediaRecorder API
- Whisper for speech recognition with language hints
- Ollama provides access to the Gemma 3 model for translation
- OpenAI Edge TTS delivers natural-sounding speech output
CORS Configuration
The application supports Cross-Origin Resource Sharing (CORS) for secure cross-origin usage. See CORS_CONFIG.md for detailed configuration instructions.
Quick setup:
# Development (allow all origins)
export CORS_ORIGINS="*"
# Production (restrict to specific domains)
export CORS_ORIGINS="https://yourdomain.com,https://app.yourdomain.com"
export ADMIN_CORS_ORIGINS="https://admin.yourdomain.com"
Connection Retry & Offline Support
Talk2Me handles network interruptions gracefully with automatic retry logic:
- Automatic request queuing during connection loss
- Exponential backoff retry with configurable parameters
- Visual connection status indicators
- Priority-based request processing
See CONNECTION_RETRY.md for detailed documentation.
Rate Limiting
Comprehensive rate limiting protects against DoS attacks and resource exhaustion:
- Token bucket algorithm with sliding window
- Per-endpoint configurable limits
- Automatic IP blocking for abusive clients
- Global request limits and concurrent request throttling
- Request size validation
See RATE_LIMITING.md for detailed documentation.
Session Management
Advanced session management prevents resource leaks from abandoned sessions:
- Automatic tracking of all session resources (audio files, temp files)
- Per-session resource limits (100 files, 100MB)
- Automatic cleanup of idle sessions (15 minutes) and expired sessions (1 hour)
- Real-time monitoring and metrics
- Manual cleanup capabilities for administrators
See SESSION_MANAGEMENT.md for detailed documentation.
Mobile Support
The interface is fully responsive and designed to work well on mobile devices.