Skip to main content

AI-Powered Subtitle Generation with Translation

Project description

AI Sub: AI-Powered Subtitle Generation with Translation

PyPI version Downloads


Overview

AI Sub is a command-line tool that leverages Google's Gemini models to generate high-quality, audio-synchronized subtitles. It is designed to produce precise English and Japanese subtitles by analyzing both audio and visual cues.

Key Features:

  • Multimodal Understanding: Utilizes video frames for context (e.g., identifying speakers, reading on-screen text) and audio for precise timing.
  • Dual-Language Support: Generates verbatim transcriptions and translations for English and Japanese.
  • Automatic Segmentation: Automatically splits long videos into smaller segments for efficient processing.

Showcase

Here's an example of subtitles generated by AI Sub:

Video Screenshot

For more examples, please visit ai-sub-showcase.


How It Works

  1. Preprocessing: The input video is segmented into smaller chunks to fit within API context windows and file size limits.
  2. AI Processing: Each segment is sent to Google Gemini. The AI analyzes the audio for speech and the video for context, following strict prompting rules to generate subtitles.
  3. Compilation: Generated subtitles from all segments are merged into a final, chronologically sorted SRT file.

Installation

Prerequisites: Python 3.10 or higher.

  1. Set up a Python virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows, use `venv\Scripts\activate.bat`
    
  2. Install AI Sub:

    pip install --upgrade ai-sub
    

Usage

You can use AI Sub with either a Google AI Studio API Key or the Gemini CLI.

Option 1: Using Google AI Studio API Key

  1. Obtain your API Key:

    • Sign in to Google AI Studio.
    • Click "Create API Key".
    • Copy and securely store your key. Never disclose your API key publicly.
  2. Run the application:

    ai-sub --ai.google.key YOUR_API_KEY --ai.model=google-gla:gemini-3-flash-preview "path/to/your/video.mp4"
    

    Note: Replace YOUR_API_KEY with your actual key and "path/to/your/video.mp4" with the video file path.

Option 2: Using Gemini CLI

  1. Install and Authenticate Gemini CLI:

    • Install: npm install -g @google/gemini-cli
    • Authenticate: Follow instructions at gemini-cli.
  2. Run the application:

    ai-sub --ai.model=gemini-cli:gemini-3-pro-preview --split.re-encode.enabled=True --thread.subtitles=1 "path/to/your/video.mp4"
    

    Important Notes for CLI Mode:

    • No API key is required; the tool uses your authenticated Gemini CLI instance.
    • Additional arguments are required to split and re-encode the video because the Gemini CLI has a 20MB upload limit per chunk.
    • Re-encoding is resource-intensive and will increase processing time.

Known Limitations

  1. Timestamp Accuracy: Subtitle timestamps may occasionally be inaccurate. This is an inherent characteristic of the Gemini AI model. Shorter video segments generally yield better accuracy.
  2. AI Hallucinations: Like all LLMs, Gemini may occasionally produce "hallucinations" or inaccurate information.

If you encounter issues, consider re-processing specific video segments as detailed below.


Advanced: Re-processing Segments

Intermediate files are stored in a temporary directory (default: tmp_<input_file_name>). You can customize this location using the --dir.tmp flag.

To re-process a specific segment:

  1. Navigate to the temporary directory.
  2. Locate and delete the corresponding part_XXX.json file.
  3. Re-run the script. It will automatically detect missing files and re-process only those segments.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_sub-1.10.0.tar.gz (27.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_sub-1.10.0-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file ai_sub-1.10.0.tar.gz.

File metadata

  • Download URL: ai_sub-1.10.0.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ai_sub-1.10.0.tar.gz
Algorithm Hash digest
SHA256 2b32d4a1b95ea50762f5c947ba67462832b05f3d3c2cf81b07d9643c953e615c
MD5 f351b42f4c3a88443dc2e18ba94c1c93
BLAKE2b-256 299f82bfaeb6e38f4e38b0e491b8cfe208a54b836431c747278ff42b1a2dea9f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_sub-1.10.0.tar.gz:

Publisher: publish.yml on FlippFuzz/ai-sub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ai_sub-1.10.0-py3-none-any.whl.

File metadata

  • Download URL: ai_sub-1.10.0-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ai_sub-1.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e3cf9d40d908474eed6024449eb0bc556c365a0d3b82e67c97c1d3669f879e4d
MD5 45315aba17d9379e4bb9b05f8baf4ce5
BLAKE2b-256 771a5866f0145be673d2db1c60720ac85fe4d021a5660e6f0960444f79be995f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_sub-1.10.0-py3-none-any.whl:

Publisher: publish.yml on FlippFuzz/ai-sub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page