Go to file
Adolfo Delorenzo 92b7c41f61 Implement proper error logging - Critical for debugging production issues
This comprehensive error logging system provides structured logging, automatic rotation, and detailed tracking for production debugging.

Key features:
- Structured JSON logging for easy parsing and analysis
- Multiple log streams: app, errors, access, security, performance
- Automatic log rotation to prevent disk space exhaustion
- Request tracing with unique IDs for debugging
- Performance metrics collection with slow request tracking
- Security event logging for suspicious activities
- Error deduplication and frequency tracking
- Full exception details with stack traces

Implementation details:
- StructuredFormatter outputs JSON-formatted logs
- ErrorLogger manages multiple specialized loggers
- Rotating file handlers prevent disk space issues
- Request context automatically included in logs
- Performance decorator tracks execution times
- Security events logged for audit trails
- Admin endpoints for log analysis

Admin endpoints:
- GET /admin/logs/errors - View recent errors and frequencies
- GET /admin/logs/performance - View performance metrics
- GET /admin/logs/security - View security events

Log types:
- talk2me.log - General application logs
- errors.log - Dedicated error logging with stack traces
- access.log - HTTP request/response logs
- security.log - Security events and suspicious activities
- performance.log - Performance metrics and timing

This provides production-grade observability critical for debugging issues, monitoring performance, and maintaining security in production environments.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-03 08:11:26 -06:00
static Add connection retry logic to handle network interruptions gracefully 2025-06-03 00:00:03 -06:00
templates Add multi-speaker support for group conversations 2025-06-02 23:39:15 -06:00
venv quasi-final 2025-04-05 11:50:31 -06:00
.env.example Remove hardcoded API key - CRITICAL SECURITY FIX 2025-06-03 00:06:18 -06:00
.gitignore Add comprehensive secrets management system for secure configuration 2025-06-03 00:24:03 -06:00
app.py Implement proper error logging - Critical for debugging production issues 2025-06-03 08:11:26 -06:00
config.py Add request size limits - Prevents memory exhaustion from large uploads 2025-06-03 00:58:14 -06:00
CONNECTION_RETRY.md Add connection retry logic to handle network interruptions gracefully 2025-06-03 00:00:03 -06:00
CORS_CONFIG.md Implement proper CORS configuration for secure cross-origin usage 2025-06-02 23:51:27 -06:00
error_logger.py Implement proper error logging - Critical for debugging production issues 2025-06-03 08:11:26 -06:00
ERROR_LOGGING.md Implement proper error logging - Critical for debugging production issues 2025-06-03 08:11:26 -06:00
GPU_SUPPORT.md Major improvements: TypeScript, animations, notifications, compression, GPU optimization 2025-06-02 21:18:16 -06:00
health-monitor.py Add health check endpoints and automatic language detection 2025-06-02 22:37:38 -06:00
maintenance.sh Fix temporary file accumulation to prevent disk space exhaustion 2025-06-02 23:27:59 -06:00
manage_secrets.py Add comprehensive secrets management system for secure configuration 2025-06-03 00:24:03 -06:00
package-lock.json Major improvements: TypeScript, animations, notifications, compression, GPU optimization 2025-06-02 21:18:16 -06:00
package.json Major improvements: TypeScript, animations, notifications, compression, GPU optimization 2025-06-02 21:18:16 -06:00
rate_limiter.py Implement comprehensive rate limiting to protect against DoS attacks 2025-06-03 00:14:05 -06:00
RATE_LIMITING.md Implement comprehensive rate limiting to protect against DoS attacks 2025-06-03 00:14:05 -06:00
README_TYPESCRIPT.md Major improvements: TypeScript, animations, notifications, compression, GPU optimization 2025-06-02 21:18:16 -06:00
README.md Implement proper error logging - Critical for debugging production issues 2025-06-03 08:11:26 -06:00
request_size_limiter.py Add request size limits - Prevents memory exhaustion from large uploads 2025-06-03 00:58:14 -06:00
REQUEST_SIZE_LIMITS.md Add request size limits - Prevents memory exhaustion from large uploads 2025-06-03 00:58:14 -06:00
requirements.txt Implement proper error logging - Critical for debugging production issues 2025-06-03 08:11:26 -06:00
SECRETS_MANAGEMENT.md Add comprehensive secrets management system for secure configuration 2025-06-03 00:24:03 -06:00
secrets_manager.py Add comprehensive secrets management system for secure configuration 2025-06-03 00:24:03 -06:00
SECURITY.md Add comprehensive secrets management system for secure configuration 2025-06-03 00:24:03 -06:00
SESSION_MANAGEMENT.md Implement session management - Prevents resource leaks from abandoned sessions 2025-06-03 00:47:46 -06:00
session_manager.py Implement session management - Prevents resource leaks from abandoned sessions 2025-06-03 00:47:46 -06:00
setup-script.sh quasi-final 2025-04-05 11:50:31 -06:00
test_error_logging.py Implement proper error logging - Critical for debugging production issues 2025-06-03 08:11:26 -06:00
test_session_manager.py Implement session management - Prevents resource leaks from abandoned sessions 2025-06-03 00:47:46 -06:00
test_size_limits.py Add request size limits - Prevents memory exhaustion from large uploads 2025-06-03 00:58:14 -06:00
test-cors.html Implement proper CORS configuration for secure cross-origin usage 2025-06-02 23:51:27 -06:00
tsconfig.json Major improvements: TypeScript, animations, notifications, compression, GPU optimization 2025-06-02 21:18:16 -06:00
tts_test_output.mp3 quasi-final 2025-04-05 11:50:31 -06:00
tts-debug-script.py quasi-final 2025-04-05 11:50:31 -06:00
validators.py Add comprehensive input validation and sanitization 2025-06-02 22:58:17 -06:00
whisper_config.py Major improvements: TypeScript, animations, notifications, compression, GPU optimization 2025-06-02 21:18:16 -06:00

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

  1. Install the required Python packages:

    pip install -r requirements.txt
    
  2. 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.

  3. Make sure you have Ollama installed and the Gemma 3 model loaded:

    ollama pull gemma3
    
  4. Ensure your OpenAI Edge TTS server is running on port 5050.

  5. Run the application:

    python app.py
    
  6. Open your browser and navigate to:

    http://localhost:8000
    

Usage

  1. Select your source language from the dropdown menu
  2. Press the microphone button and speak
  3. Press the button again to stop recording
  4. Wait for the transcription to complete
  5. Select your target language
  6. Press the "Translate" button
  7. 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.

Request Size Limits

Comprehensive request size limiting prevents memory exhaustion:

  • Global limit: 50MB for any request
  • Audio files: 25MB maximum
  • JSON payloads: 1MB maximum
  • File type detection and enforcement
  • Dynamic configuration via admin API

See REQUEST_SIZE_LIMITS.md for detailed documentation.

Error Logging

Production-ready error logging system for debugging and monitoring:

  • Structured JSON logs for easy parsing
  • Multiple log streams (app, errors, access, security, performance)
  • Automatic log rotation to prevent disk exhaustion
  • Request tracing with unique IDs
  • Performance metrics and slow request tracking
  • Admin endpoints for log analysis

See ERROR_LOGGING.md for detailed documentation.

Mobile Support

The interface is fully responsive and designed to work well on mobile devices.