nguyenquyen1910/Live-translator

HTML

0

42 commits

updated Jul 10, 2025

See the code

README

🌐 LiveTranslator - Real-Time Multilingual Speech Translation System

Python FastAPI WebSocket License

πŸš€ Overview

LiveTranslator is a cutting-edge real-time speech translation system that seamlessly converts spoken language into text, translates it to target languages, and synthesizes it back into speech. Built with modern web technologies, this system provides instant multilingual communication capabilities through an intuitive web interface.

✨ Key Features

  • πŸŽ™οΈ Real-time Speech Recognition (STT): Convert audio input to text with high accuracy
  • 🌍 Multi-language Translation: Support for multiple language pairs with advanced translation models
  • πŸ”Š Text-to-Speech Synthesis (TTS): Natural-sounding voice output in target languages
  • ⚑ WebSocket Communication: Ultra-low latency real-time data streaming
  • πŸ“± Responsive Web Interface: Modern, intuitive UI for seamless user experience
  • πŸ”§ Modular Architecture: Easy integration with various STT, translation, and TTS services
  • πŸ“Š RESTful API: Comprehensive API endpoints for integration with external systems
  • 🐳 Docker Support: Containerized deployment for easy scaling and management

πŸ—οΈ Architecture

The system is built with a microservices architecture, featuring:

  • Backend: FastAPI-based REST API with WebSocket support
  • Frontend: Modern web interface with real-time communication
  • Services: Modular design supporting multiple AI/ML providers
  • Database: Flexible data storage for translation history (optional)

πŸ“ Project Structure

LiveTranslator/
β”œβ”€β”€ backend/                          # FastAPI Backend Application
β”‚   β”œβ”€β”€ api/                         # API Routes & WebSocket Handlers
β”‚   β”‚   β”œβ”€β”€ rest_routes.py           # REST API endpoints
β”‚   β”‚   β”œβ”€β”€ ws_routes.py             # WebSocket communication
β”‚   β”‚   β”œβ”€β”€ feedback_routes.py       # User feedback endpoints
β”‚   β”‚   β”œβ”€β”€ file_routes.py           # File upload/download handlers
β”‚   β”‚   └── image_routers.py         # Image processing routes
β”‚   β”œβ”€β”€ services/                    # Core Business Logic
β”‚   β”‚   β”œβ”€β”€ stt_service.py           # Speech-to-Text processing
β”‚   β”‚   β”œβ”€β”€ translation_service.py   # Language translation engine
β”‚   β”‚   β”œβ”€β”€ tts_service.py           # Text-to-Speech synthesis
β”‚   β”‚   β”œβ”€β”€ websocket_service.py     # Real-time communication
β”‚   β”‚   β”œβ”€β”€ image_translation_service.py  # Image text translation
β”‚   β”‚   β”œβ”€β”€ file_translate_service.py     # Document translation
β”‚   β”‚   β”œβ”€β”€ draw_service.py          # Drawing/annotation services
β”‚   β”‚   └── punctuation.py           # Text punctuation enhancement
β”‚   β”œβ”€β”€ models/                      # Data Models & Schemas
β”‚   β”‚   β”œβ”€β”€ stt_model.py             # STT request/response models
β”‚   β”‚   β”œβ”€β”€ translation_model.py     # Translation data models
β”‚   β”‚   β”œβ”€β”€ tts_model.py             # TTS configuration models
β”‚   β”‚   └── feedback_model.py        # User feedback models
β”‚   β”œβ”€β”€ utils/                       # Utility Functions
β”‚   β”‚   β”œβ”€β”€ audio_utils.py           # Audio processing utilities
β”‚   β”‚   β”œβ”€β”€ error_handler.py         # Error handling middleware
β”‚   β”‚   └── logger.py                # Logging configuration
β”‚   β”œβ”€β”€ test/                        # Test Suite
β”‚   β”‚   β”œβ”€β”€ test_stt_service.py      # STT service tests
β”‚   β”‚   β”œβ”€β”€ test_translation_service.py  # Translation tests
β”‚   β”‚   β”œβ”€β”€ test_tts_service.py      # TTS service tests
β”‚   β”‚   └── test_websocket_service.py     # WebSocket tests
β”‚   β”œβ”€β”€ main.py                      # FastAPI application entry point
β”‚   β”œβ”€β”€ database.py                  # Database configuration
β”‚   β”œβ”€β”€ init_db.py                   # Database initialization
β”‚   └── requirements.txt             # Python dependencies
β”œβ”€β”€ frontend/                        # Web Frontend
β”‚   β”œβ”€β”€ templates/                   # HTML Templates
β”‚   β”‚   β”œβ”€β”€ index.html               # Main application page
β”‚   β”‚   β”œβ”€β”€ live_translator.html     # Real-time translation interface
β”‚   β”‚   β”œβ”€β”€ file_translator.html     # File translation interface
β”‚   β”‚   β”œβ”€β”€ live_camera.html         # Camera-based translation
β”‚   β”‚   β”œβ”€β”€ about.html               # About page
β”‚   β”‚   └── contact.html             # Contact page
β”‚   β”œβ”€β”€ static/                      # Static Assets
β”‚   β”‚   β”œβ”€β”€ css/
β”‚   β”‚   β”‚   └── style.css            # Main stylesheet
β”‚   β”‚   β”œβ”€β”€ js/
β”‚   β”‚   β”‚   └── ws-client.js         # WebSocket client
β”‚   β”‚   └── img/                     # Image assets
β”‚   β”œβ”€β”€ package.json                 # Frontend dependencies
β”‚   └── README.md                    # Frontend documentation
β”œβ”€β”€ docs/                            # Documentation
β”‚   β”œβ”€β”€ api.md                       # API documentation
β”‚   β”œβ”€β”€ setup.md                     # Setup guide
β”‚   └── deploy.md                    # Deployment guide
β”œβ”€β”€ scripts/                         # Development Scripts
β”‚   β”œβ”€β”€ setup.sh                     # Environment setup
β”‚   └── dev.sh                       # Development server
β”œβ”€β”€ data/                            # Data storage
β”œβ”€β”€ logs/                            # Application logs
β”œβ”€β”€ Dockerfile                       # Docker configuration
β”œβ”€β”€ docker-compose.yml               # Docker Compose setup
β”œβ”€β”€ render.yaml                      # Render deployment config
└── README.md                        # This file

πŸ› οΈ Technology Stack

Backend

  • Framework: FastAPI (Python 3.9+)
  • WebSocket: websockets library
  • Audio Processing: librosa, soundfile
  • AI/ML Services:
    • Speech Recognition: Whisper, Google Cloud Speech
    • Translation: MarianMT, OpenAI, Google Translate
    • Text-to-Speech: gTTS, OpenAI TTS
  • Data Validation: Pydantic
  • Testing: pytest

Frontend

  • Core: HTML5, CSS3, JavaScript (ES6+)
  • Real-time Communication: WebSocket API
  • Audio Processing: Web Audio API
  • UI Framework: Custom responsive design
  • Build Tools: Modern web standards

DevOps

  • Containerization: Docker & Docker Compose
  • Deployment: Render, Heroku, AWS compatible
  • Monitoring: Built-in logging and error tracking

πŸš€ Quick Start

Prerequisites

  • Python 3.9 or higher
  • Node.js 16+ (for frontend development)
  • Git

1. Clone the Repository

git clone https://github.com/yourusername/LiveTranslator.git
cd LiveTranslator

2. Set Up Python Environment

# Create virtual environment
python -m venv venv

# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate

# Install dependencies
pip install -r backend/requirements.txt

3. Configure Environment

# Copy environment template
cp .env.example .env

# Edit .env file with your configuration
# Add API keys for your chosen services

4. Start the Application

# Start backend server
uvicorn backend.main:app --reload --host 0.0.0.0 --port 8000

# Access the application
# Backend API: http://localhost:8000
# Frontend: http://localhost:8000
# API Documentation: http://localhost:8000/docs

5. Docker Deployment (Alternative)

# Build and run with Docker Compose
docker-compose up --build

# Access the application
# http://localhost:8000

πŸ“š API Documentation

REST API Endpoints

EndpointMethodDescription
/sttPOSTConvert audio to text
/translatePOSTTranslate text between languages
/ttsPOSTConvert text to speech
/feedbackPOSTSubmit user feedback
/uploadPOSTUpload files for translation

WebSocket Endpoints

EndpointDescription
/ws/audioReal-time audio streaming
/ws/translateReal-time translation streaming

Example Usage

import requests

# Speech-to-Text
with open('audio.wav', 'rb') as f:
    response = requests.post('http://localhost:8000/stt', files={'audio': f})
    text = response.json()['text']

# Translation
response = requests.post('http://localhost:8000/translate', json={
    'text': 'Hello world',
    'source_lang': 'en',
    'target_lang': 'vi'
})
translated = response.json()['translated_text']

πŸ”§ Configuration

Environment Variables

# API Keys
OPENAI_API_KEY=your_openai_key
GOOGLE_CLOUD_CREDENTIALS=path_to_credentials.json

# Service Configuration
STT_SERVICE=whisper  # whisper, google, openai
TRANSLATION_SERVICE=marianmt  # marianmt, openai, google
TTS_SERVICE=gtts  # gtts, openai

# Database
DATABASE_URL=sqlite:///./translator.db

# Logging
LOG_LEVEL=INFO

Supported Services

Speech-to-Text

  • Whisper: OpenAI's open-source speech recognition
  • Google Cloud Speech: Enterprise-grade STT
  • OpenAI Whisper API: Cloud-based Whisper

Translation

  • MarianMT: Open-source neural machine translation
  • OpenAI GPT: Advanced language model translation
  • Google Translate: Comprehensive translation service

Text-to-Speech

  • gTTS: Google Text-to-Speech
  • OpenAI TTS: High-quality voice synthesis
  • Azure Speech: Microsoft's TTS service

πŸ§ͺ Testing

# Run all tests
pytest backend/test/

# Run specific test file
pytest backend/test/test_stt_service.py

# Run with coverage
pytest --cov=backend backend/test/

πŸ“¦ Deployment

Production Deployment

  1. Environment Setup

    # Set production environment variables
    export ENVIRONMENT=production
    export LOG_LEVEL=WARNING
    
  2. Docker Deployment

    docker-compose -f docker-compose.prod.yml up -d
    
  3. Manual Deployment

    # Install production dependencies
    pip install -r backend/requirements.txt --no-dev
    
    # Start with production server
    gunicorn backend.main:app -w 4 -k uvicorn.workers.UvicornWorker
    

Cloud Platforms

  • Render: Use render.yaml for automatic deployment
  • Heroku: Compatible with Heroku's Python buildpack
  • AWS: Deploy using ECS or EC2
  • Google Cloud: Use Cloud Run or Compute Engine

🀝 Contributing

We welcome contributions from the community! Please follow these guidelines:

Development Workflow

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/amazing-feature
    
  3. Make your changes
  4. Add tests for new functionality
  5. Commit with clear messages
    git commit -m "feat: add new translation service"
    
  6. Push to your branch
    git push origin feature/amazing-feature
    
  7. Create a Pull Request

Code Standards

  • Follow PEP 8 for Python code
  • Use type hints for function parameters
  • Write comprehensive docstrings
  • Maintain test coverage above 80%
  • Follow conventional commit messages

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • OpenAI for Whisper and GPT models
  • Hugging Face for MarianMT and transformers
  • Google for gTTS and Cloud Speech services
  • FastAPI community for the excellent framework
  • All contributors and users of this project

πŸ“ž Support


Made with ❀️ by the LiveTranslator Team

GitHub stars GitHub forks GitHub issues

nguyenquyen1910/Live-translator

HTML

0

42 commits

updated Jul 10, 2025

See the code

README

🌐 LiveTranslator - Real-Time Multilingual Speech Translation System

Python FastAPI WebSocket License

πŸš€ Overview

LiveTranslator is a cutting-edge real-time speech translation system that seamlessly converts spoken language into text, translates it to target languages, and synthesizes it back into speech. Built with modern web technologies, this system provides instant multilingual communication capabilities through an intuitive web interface.

✨ Key Features

  • πŸŽ™οΈ Real-time Speech Recognition (STT): Convert audio input to text with high accuracy
  • 🌍 Multi-language Translation: Support for multiple language pairs with advanced translation models
  • πŸ”Š Text-to-Speech Synthesis (TTS): Natural-sounding voice output in target languages
  • ⚑ WebSocket Communication: Ultra-low latency real-time data streaming
  • πŸ“± Responsive Web Interface: Modern, intuitive UI for seamless user experience
  • πŸ”§ Modular Architecture: Easy integration with various STT, translation, and TTS services
  • πŸ“Š RESTful API: Comprehensive API endpoints for integration with external systems
  • 🐳 Docker Support: Containerized deployment for easy scaling and management

πŸ—οΈ Architecture

The system is built with a microservices architecture, featuring:

  • Backend: FastAPI-based REST API with WebSocket support
  • Frontend: Modern web interface with real-time communication
  • Services: Modular design supporting multiple AI/ML providers
  • Database: Flexible data storage for translation history (optional)

πŸ“ Project Structure

LiveTranslator/
β”œβ”€β”€ backend/                          # FastAPI Backend Application
β”‚   β”œβ”€β”€ api/                         # API Routes & WebSocket Handlers
β”‚   β”‚   β”œβ”€β”€ rest_routes.py           # REST API endpoints
β”‚   β”‚   β”œβ”€β”€ ws_routes.py             # WebSocket communication
β”‚   β”‚   β”œβ”€β”€ feedback_routes.py       # User feedback endpoints
β”‚   β”‚   β”œβ”€β”€ file_routes.py           # File upload/download handlers
β”‚   β”‚   └── image_routers.py         # Image processing routes
β”‚   β”œβ”€β”€ services/                    # Core Business Logic
β”‚   β”‚   β”œβ”€β”€ stt_service.py           # Speech-to-Text processing
β”‚   β”‚   β”œβ”€β”€ translation_service.py   # Language translation engine
β”‚   β”‚   β”œβ”€β”€ tts_service.py           # Text-to-Speech synthesis
β”‚   β”‚   β”œβ”€β”€ websocket_service.py     # Real-time communication
β”‚   β”‚   β”œβ”€β”€ image_translation_service.py  # Image text translation
β”‚   β”‚   β”œβ”€β”€ file_translate_service.py     # Document translation
β”‚   β”‚   β”œβ”€β”€ draw_service.py          # Drawing/annotation services
β”‚   β”‚   └── punctuation.py           # Text punctuation enhancement
β”‚   β”œβ”€β”€ models/                      # Data Models & Schemas
β”‚   β”‚   β”œβ”€β”€ stt_model.py             # STT request/response models
β”‚   β”‚   β”œβ”€β”€ translation_model.py     # Translation data models
β”‚   β”‚   β”œβ”€β”€ tts_model.py             # TTS configuration models
β”‚   β”‚   └── feedback_model.py        # User feedback models
β”‚   β”œβ”€β”€ utils/                       # Utility Functions
β”‚   β”‚   β”œβ”€β”€ audio_utils.py           # Audio processing utilities
β”‚   β”‚   β”œβ”€β”€ error_handler.py         # Error handling middleware
β”‚   β”‚   └── logger.py                # Logging configuration
β”‚   β”œβ”€β”€ test/                        # Test Suite
β”‚   β”‚   β”œβ”€β”€ test_stt_service.py      # STT service tests
β”‚   β”‚   β”œβ”€β”€ test_translation_service.py  # Translation tests
β”‚   β”‚   β”œβ”€β”€ test_tts_service.py      # TTS service tests
β”‚   β”‚   └── test_websocket_service.py     # WebSocket tests
β”‚   β”œβ”€β”€ main.py                      # FastAPI application entry point
β”‚   β”œβ”€β”€ database.py                  # Database configuration
β”‚   β”œβ”€β”€ init_db.py                   # Database initialization
β”‚   └── requirements.txt             # Python dependencies
β”œβ”€β”€ frontend/                        # Web Frontend
β”‚   β”œβ”€β”€ templates/                   # HTML Templates
β”‚   β”‚   β”œβ”€β”€ index.html               # Main application page
β”‚   β”‚   β”œβ”€β”€ live_translator.html     # Real-time translation interface
β”‚   β”‚   β”œβ”€β”€ file_translator.html     # File translation interface
β”‚   β”‚   β”œβ”€β”€ live_camera.html         # Camera-based translation
β”‚   β”‚   β”œβ”€β”€ about.html               # About page
β”‚   β”‚   └── contact.html             # Contact page
β”‚   β”œβ”€β”€ static/                      # Static Assets
β”‚   β”‚   β”œβ”€β”€ css/
β”‚   β”‚   β”‚   └── style.css            # Main stylesheet
β”‚   β”‚   β”œβ”€β”€ js/
β”‚   β”‚   β”‚   └── ws-client.js         # WebSocket client
β”‚   β”‚   └── img/                     # Image assets
β”‚   β”œβ”€β”€ package.json                 # Frontend dependencies
β”‚   └── README.md                    # Frontend documentation
β”œβ”€β”€ docs/                            # Documentation
β”‚   β”œβ”€β”€ api.md                       # API documentation
β”‚   β”œβ”€β”€ setup.md                     # Setup guide
β”‚   └── deploy.md                    # Deployment guide
β”œβ”€β”€ scripts/                         # Development Scripts
β”‚   β”œβ”€β”€ setup.sh                     # Environment setup
β”‚   └── dev.sh                       # Development server
β”œβ”€β”€ data/                            # Data storage
β”œβ”€β”€ logs/                            # Application logs
β”œβ”€β”€ Dockerfile                       # Docker configuration
β”œβ”€β”€ docker-compose.yml               # Docker Compose setup
β”œβ”€β”€ render.yaml                      # Render deployment config
└── README.md                        # This file

πŸ› οΈ Technology Stack

Backend

  • Framework: FastAPI (Python 3.9+)
  • WebSocket: websockets library
  • Audio Processing: librosa, soundfile
  • AI/ML Services:
    • Speech Recognition: Whisper, Google Cloud Speech
    • Translation: MarianMT, OpenAI, Google Translate
    • Text-to-Speech: gTTS, OpenAI TTS
  • Data Validation: Pydantic
  • Testing: pytest

Frontend

  • Core: HTML5, CSS3, JavaScript (ES6+)
  • Real-time Communication: WebSocket API
  • Audio Processing: Web Audio API
  • UI Framework: Custom responsive design
  • Build Tools: Modern web standards

DevOps

  • Containerization: Docker & Docker Compose
  • Deployment: Render, Heroku, AWS compatible
  • Monitoring: Built-in logging and error tracking

πŸš€ Quick Start

Prerequisites

  • Python 3.9 or higher
  • Node.js 16+ (for frontend development)
  • Git

1. Clone the Repository

git clone https://github.com/yourusername/LiveTranslator.git
cd LiveTranslator

2. Set Up Python Environment

# Create virtual environment
python -m venv venv

# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate

# Install dependencies
pip install -r backend/requirements.txt

3. Configure Environment

# Copy environment template
cp .env.example .env

# Edit .env file with your configuration
# Add API keys for your chosen services

4. Start the Application

# Start backend server
uvicorn backend.main:app --reload --host 0.0.0.0 --port 8000

# Access the application
# Backend API: http://localhost:8000
# Frontend: http://localhost:8000
# API Documentation: http://localhost:8000/docs

5. Docker Deployment (Alternative)

# Build and run with Docker Compose
docker-compose up --build

# Access the application
# http://localhost:8000

πŸ“š API Documentation

REST API Endpoints

EndpointMethodDescription
/sttPOSTConvert audio to text
/translatePOSTTranslate text between languages
/ttsPOSTConvert text to speech
/feedbackPOSTSubmit user feedback
/uploadPOSTUpload files for translation

WebSocket Endpoints

EndpointDescription
/ws/audioReal-time audio streaming
/ws/translateReal-time translation streaming

Example Usage

import requests

# Speech-to-Text
with open('audio.wav', 'rb') as f:
    response = requests.post('http://localhost:8000/stt', files={'audio': f})
    text = response.json()['text']

# Translation
response = requests.post('http://localhost:8000/translate', json={
    'text': 'Hello world',
    'source_lang': 'en',
    'target_lang': 'vi'
})
translated = response.json()['translated_text']

πŸ”§ Configuration

Environment Variables

# API Keys
OPENAI_API_KEY=your_openai_key
GOOGLE_CLOUD_CREDENTIALS=path_to_credentials.json

# Service Configuration
STT_SERVICE=whisper  # whisper, google, openai
TRANSLATION_SERVICE=marianmt  # marianmt, openai, google
TTS_SERVICE=gtts  # gtts, openai

# Database
DATABASE_URL=sqlite:///./translator.db

# Logging
LOG_LEVEL=INFO

Supported Services

Speech-to-Text

  • Whisper: OpenAI's open-source speech recognition
  • Google Cloud Speech: Enterprise-grade STT
  • OpenAI Whisper API: Cloud-based Whisper

Translation

  • MarianMT: Open-source neural machine translation
  • OpenAI GPT: Advanced language model translation
  • Google Translate: Comprehensive translation service

Text-to-Speech

  • gTTS: Google Text-to-Speech
  • OpenAI TTS: High-quality voice synthesis
  • Azure Speech: Microsoft's TTS service

πŸ§ͺ Testing

# Run all tests
pytest backend/test/

# Run specific test file
pytest backend/test/test_stt_service.py

# Run with coverage
pytest --cov=backend backend/test/

πŸ“¦ Deployment

Production Deployment

  1. Environment Setup

    # Set production environment variables
    export ENVIRONMENT=production
    export LOG_LEVEL=WARNING
    
  2. Docker Deployment

    docker-compose -f docker-compose.prod.yml up -d
    
  3. Manual Deployment

    # Install production dependencies
    pip install -r backend/requirements.txt --no-dev
    
    # Start with production server
    gunicorn backend.main:app -w 4 -k uvicorn.workers.UvicornWorker
    

Cloud Platforms

  • Render: Use render.yaml for automatic deployment
  • Heroku: Compatible with Heroku's Python buildpack
  • AWS: Deploy using ECS or EC2
  • Google Cloud: Use Cloud Run or Compute Engine

🀝 Contributing

We welcome contributions from the community! Please follow these guidelines:

Development Workflow

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/amazing-feature
    
  3. Make your changes
  4. Add tests for new functionality
  5. Commit with clear messages
    git commit -m "feat: add new translation service"
    
  6. Push to your branch
    git push origin feature/amazing-feature
    
  7. Create a Pull Request

Code Standards

  • Follow PEP 8 for Python code
  • Use type hints for function parameters
  • Write comprehensive docstrings
  • Maintain test coverage above 80%
  • Follow conventional commit messages

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • OpenAI for Whisper and GPT models
  • Hugging Face for MarianMT and transformers
  • Google for gTTS and Cloud Speech services
  • FastAPI community for the excellent framework
  • All contributors and users of this project

πŸ“ž Support


Made with ❀️ by the LiveTranslator Team

GitHub stars GitHub forks GitHub issues