Skip to content

A simple application that translates from English, Italian, Japanese, Russian, Spanish and German video files to Italian, Spanish, Russian, or English

License

Notifications You must be signed in to change notification settings

ruslanmv/Video-Translator

Repository files navigation

๐ŸŽฌ Video Translator

Python 3.9+ License: Apache 2.0 Code style: black

A production-ready, AI-powered video translation application that automatically translates video content across multiple languages using advanced speech recognition, machine translation, and natural text-to-speech synthesis.

Video Translator Interface

๐ŸŒŸ Features

  • ๐ŸŽฏ Multi-Language Support: Translate videos between 7 languages (English, Spanish, Italian, Japanese, Russian, German, Portuguese)
  • ๐Ÿค– AI-Powered Pipeline: Leverages Google Speech Recognition, Deep Translator, and gTTS for high-quality translations
  • ๐ŸŽจ Modern Web Interface: Beautiful, responsive Gradio-based UI for easy interaction
  • ๐Ÿ—๏ธ Production-Ready: Enterprise-grade code with comprehensive error handling, logging, and type hints
  • ๐Ÿ“ฆ Modular Architecture: Clean, maintainable codebase following industry best practices
  • โœ… Type-Safe: Full type hinting throughout the codebase
  • ๐Ÿ“Š Progress Tracking: Real-time progress updates during translation
  • ๐Ÿงช Well-Tested: Comprehensive test suite with pytest

๐Ÿ“‹ Table of Contents

๐Ÿ“– About

Video Translator is a sophisticated application that transforms video content across language barriers. It uses a multi-stage AI pipeline to:

  1. Extract audio from video files
  2. Recognize speech using Google's Speech Recognition API
  3. Translate text using advanced neural translation models
  4. Synthesize natural-sounding speech in the target language
  5. Compose a new video with the translated audio track

Built with modern Python practices, this application is designed for both ease of use and production deployment.

๐Ÿš€ Installation

Prerequisites

  • Python: 3.9 or higher
  • uv: Fast Python package installer (astral-sh/uv)
  • FFmpeg: Required by moviepy for video processing

Install FFmpeg

Ubuntu/Debian:

sudo apt update
sudo apt install ffmpeg

macOS:

brew install ffmpeg

Windows: Download from ffmpeg.org and add to PATH.

Install Video Translator

Option 1: Using uv (Recommended)

# Clone the repository
git clone https://github.com/ruslanmv/Video-Translator.git
cd Video-Translator

# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install dependencies
make install

# For development (includes testing tools)
make install-dev

Option 2: Using pip

# Clone the repository
git clone https://github.com/ruslanmv/Video-Translator.git
cd Video-Translator

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in editable mode
pip install -e .

๐Ÿ’ป Usage

Web Interface (Gradio)

Launch the interactive web interface:

# Using make
make run

# Or directly
video-translator

# Or using Python
python -m video_translator.main

Then open your browser to http://localhost:7860

Command Line Interface

from video_translator import VideoTranslator

# Initialize translator
translator = VideoTranslator()

# Translate a single video
output = translator.translate_video(
    video_path="my_video.mp4",
    source_language="English",
    target_language="Spanish"
)
print(f"Translation complete: {output}")

# Batch translate to multiple languages
results = translator.batch_translate(
    video_path="my_video.mp4",
    source_language="English",
    target_languages=["Spanish", "French", "German"]
)

for language, output_path in results.items():
    print(f"{language}: {output_path}")

Python API

from video_translator.config import Config
from video_translator.translator import VideoTranslator

# Custom configuration
config = Config(
    temp_dir="./temp",
    output_dir="./output",
    max_file_size_mb=1000
)

# Initialize with custom config
translator = VideoTranslator(config)

# Translate
output = translator.translate_video(
    "video.mp4",
    "English",
    "Japanese"
)

๐Ÿ—๏ธ Architecture

Project Structure

Video-Translator/
โ”œโ”€โ”€ video_translator/           # Main package
โ”‚   โ”œโ”€โ”€ __init__.py            # Package initialization
โ”‚   โ”œโ”€โ”€ main.py                # Gradio web interface
โ”‚   โ”œโ”€โ”€ translator.py          # Main translation orchestrator
โ”‚   โ”œโ”€โ”€ video.py               # Video processing module
โ”‚   โ”œโ”€โ”€ audio.py               # Audio processing module
โ”‚   โ”œโ”€โ”€ config.py              # Configuration and constants
โ”‚   โ”œโ”€โ”€ exceptions.py          # Custom exceptions
โ”‚   โ”œโ”€โ”€ logger.py              # Logging configuration
โ”‚   โ””โ”€โ”€ utils.py               # Utility functions
โ”œโ”€โ”€ tests/                      # Test suite
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ test_translator.py
โ”‚   โ”œโ”€โ”€ test_video.py
โ”‚   โ”œโ”€โ”€ test_audio.py
โ”‚   โ””โ”€โ”€ test_utils.py
โ”œโ”€โ”€ pyproject.toml             # Project metadata and dependencies
โ”œโ”€โ”€ Makefile                   # Automation commands
โ”œโ”€โ”€ README.md                  # This file
โ”œโ”€โ”€ LICENSE                    # Apache 2.0 license
โ””โ”€โ”€ .gitignore                # Git ignore patterns

Translation Pipeline

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Upload Video   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Extract Audio   โ”‚  (moviepy)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Speech-to-Text  โ”‚  (Google Speech Recognition)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Translation   โ”‚  (Deep Translator)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Text-to-Speech  โ”‚  (gTTS)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Replace Audio  โ”‚  (moviepy)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Translated Videoโ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ› ๏ธ Development

Setup Development Environment

# Install with development dependencies
make install-dev

# Or using uv directly
uv pip install -e ".[dev]"

Code Quality

# Format code
make format

# Run linters
make lint

# Type checking
make type-check

# Run all checks
make check

Testing

# Run tests
make test

# Run tests with coverage
make test-cov

# View coverage report
open htmlcov/index.html

Available Make Commands

make help              # Show all available commands
make install           # Install production dependencies
make install-dev       # Install all dependencies (including dev tools)
make clean             # Remove build artifacts and cache
make lint              # Run code linting
make format            # Format code with black and isort
make type-check        # Run mypy type checking
make test              # Run tests
make test-cov          # Run tests with coverage report
make run               # Run the application
make build             # Build distribution packages
make ci                # Run all CI checks

๐Ÿ“š API Reference

VideoTranslator

Main class for video translation operations.

class VideoTranslator:
    def __init__(self, config: Optional[Config] = None)

    def translate_video(
        self,
        video_path: str,
        source_language: str,
        target_language: str,
        output_path: Optional[str] = None
    ) -> str

    def batch_translate(
        self,
        video_path: str,
        source_language: str,
        target_languages: list
    ) -> dict

Supported Languages

  • ๐Ÿ‡ฌ๐Ÿ‡ง English (en-US)
  • ๐Ÿ‡ฎ๐Ÿ‡น Italian (it-IT)
  • ๐Ÿ‡ฏ๐Ÿ‡ต Japanese (ja-JP)
  • ๐Ÿ‡ท๐Ÿ‡บ Russian (ru-RU)
  • ๐Ÿ‡ช๐Ÿ‡ธ Spanish (es-MX)
  • ๐Ÿ‡ฉ๐Ÿ‡ช German (de-DE)
  • ๐Ÿ‡ง๐Ÿ‡ท Portuguese (pt-BR)

Exceptions

VideoTranslatorError          # Base exception
VideoProcessingError          # Video processing failures
AudioExtractionError          # Audio extraction failures
SpeechRecognitionError        # Speech recognition failures
TranslationError              # Translation failures
TextToSpeechError            # Text-to-speech failures
InvalidInputError            # Invalid input parameters

๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Contribution Guidelines

  • Follow PEP 8 style guidelines
  • Add type hints to all functions
  • Write comprehensive docstrings
  • Include unit tests for new features
  • Update documentation as needed
  • Run make ci before submitting PR

๐Ÿ“„ License

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

Copyright 2024 Ruslan Magana

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

๐Ÿ‘ค Author

Ruslan Magana

๐Ÿ™ Acknowledgments

๐Ÿ“Š Project Status

This project is actively maintained and production-ready. For issues, feature requests, or questions, please open an issue on GitHub.


Made with โค๏ธ by Ruslan Magana

About

A simple application that translates from English, Italian, Japanese, Russian, Spanish and German video files to Italian, Spanish, Russian, or English

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published