AI-Powered Subtitle Generation with Translation
Project description
AI Sub: AI-Powered Subtitle Generation with Translation
Table of Contents
- Overview
- Showcase
- How It Works
- Installation
- Usage
- Configuration
- Release Notes
- Known Limitations
- Advanced: Re-processing Segments
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 dual-language subtitles (Original + English translation) by analyzing both audio and visual cues.
Showcase
Please visit ai-sub-showcase.
How It Works
- Segmentation: Splits the input video into manageable 5-minute segments.
- Re-encoding (Optional): Compresses segments (e.g., 1fps, 360p) to significantly reduce bandwidth usage and upload times without sacrificing AI analysis accuracy.
- Upload (Optional): Uploads segments to the Gemini Files API for cloud-based processing. This bypasses local processing constraints and leverages the API's multimodal capabilities.
- Lyrics Search and Scene Detection (Optional): Detects scenes and performs a web search for official lyrics to improve transcription accuracy for songs.
- Generation: Generates synchronized subtitles and translations by using the audio as the ground truth for timing and visuals for context.
- Assembly: Stitches the generated subtitles back together into a final SRT file.
Installation
Prerequisites: Python 3.10 or higher.
-
Set up a Python virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate.bat`
-
Install AI Sub:
pip install --upgrade ai-sub
Usage
You can use AI Sub a Google AI Studio API Key and an optional langsearch API key for song lyrics web search.
Option 1 (Recommended): Google API Key + Langsearch API Key
This option provides the best quality for the free tier.
- As of 3 June 2026:
- Gemini API provides 20 free requests/day for gemini-3.5-flash
- Gemini API provides 500 free requests/day for gemini-3.1-flash-lite
- Langsearch provides 1000 free request/day for web searches
The limiting factor is the daily free quota for gemini-3.5-flash. You should be able to create subtitles for between 1 hour to 1 hour 40 mins of videos per day.
-
Obtain your API Keys:
-
Sign in to Google AI Studio.
-
Click "Create API Key".
-
Sign in to Langsearch.
-
API Keys -> Create API Key
-
Copy and securely store your keys. Never disclose your API key publicly.
-
-
Run the application:
Linux:
GOOGLE_KEY="YOUR_GOOGLE_API_KEY" LANGSEARCH_KEY="YOUR_LANGSEARCH_API_KEY" FILE_NAME="path/to/your/video.mp4" ai-sub \ --ai.model-lyrics=google-gla:gemini-3.1-flash-lite \ --ai.model-subtitles=google-gla:gemini-3.5-flash \ --ai.search.web-search-tool=langsearch \ --ai.google.key="${GOOGLE_KEY}" \ --ai.search.key="${LANGSEARCH_KEY}" \ "${FILE_NAME}"
Windows:
SET "GOOGLE_KEY=YOUR_GOOGLE_API_KEY" SET "LANGSEARCH_KEY=YOUR_LANGSEARCH_API_KEY" SET "FILE_NAME=path/to/your/video.mp4" ai-sub ^ --ai.model-lyrics=google-gla:gemini-3.1-flash-lite ^ --ai.model-subtitles=google-gla:gemini-3.5-flash ^ --ai.search.web-search-tool=langsearch ^ --ai.google.key="%GOOGLE_KEY%" ^ --ai.search.key="%LANGSEARCH_KEY%" ^ "%FILE_NAME%"
Option 2: Using Google API Key Only
This is the easiest option if you don't want to bother with creating a Langsearch API key. We can use duckduckgo to try to lookup lyrics, but it is not as reliable.
-
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.
-
Run the application:
GOOGLE_KEY="YOUR_GOOGLE_API_KEY" FILE_NAME="path/to/your/video.mp4" ai-sub \ --ai.model-lyrics=google-gla:gemini-3.1-flash-lite \ --ai.model-subtitles=google-gla:gemini-3.5-flash \ --ai.search.web-search-tool=duckduckgo \ --ai.google.key="${GOOGLE_KEY}" \ "${FILE_NAME}"
Windows:
SET "GOOGLE_KEY=YOUR_GOOGLE_API_KEY" SET "FILE_NAME=path/to/your/video.mp4" ai-sub ^ --ai.model-lyrics=google-gla:gemini-3.1-flash-lite ^ --ai.model-subtitles=google-gla:gemini-3.5-flash ^ --ai.search.web-search-tool=duckduckgo ^ --ai.google.key="%GOOGLE_KEY%" ^ "%FILE_NAME%"
Configuration
For a detailed list of all configuration options, including AI models, re-encoding settings, and concurrency controls, please refer to CONFIGURATION.md.
All settings can be configured via command-line arguments (e.g., --ai.model=google-gla:gemini-3.0-flash-preview) or environment variables with the AISUB_ prefix (e.g., AISUB_AI_MODEL=gemini-cli:gemini-3.0-flash-preview).
Release Notes
For the latest updates and bug fixes, please refer to RELEASE_NOTES.md.
Known Limitations
- Timestamp Accuracy: Subtitle timestamps may occasionally be inaccurate due to limitations of the Gemini AI model. Shorter video segments generally yield better accuracy. Experiment with the
--split.max-secondssetting. - 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 and job states are stored in a temporary directory (default: tmp_<input_file_name>). You can customize this location using the --dir.tmp flag.
The application creates separate state files for each processing stage (e.g., lyrics detection, subtitle generation). To re-process a specific segment, you must delete the state file for the stage you want to re-run.
File naming format: part_XXX.<stage>.<model_name>.json
Example: To re-run subtitle generation for the third segment:
- Navigate to the temporary directory.
- Identify the model name used for subtitles (e.g.,
gemini-3-5-flash). - Delete the corresponding state file (e.g.,
part_002.subtitles.gemini-3-5-flash.json). - Re-run the script. It will detect the missing subtitle job state and re-process only that segment, using any existing lyrics data.
To re-run the entire pipeline for that segment (including lyrics search), delete both the lyrics and subtitles JSON files for that part.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_sub-2.10.0b1.tar.gz.
File metadata
- Download URL: ai_sub-2.10.0b1.tar.gz
- Upload date:
- Size: 42.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae05ec4d956fe9b3f78c55ac467294ad8e4faa2b257fb130b3b5b6ccde5f6946
|
|
| MD5 |
6a23ee75a055df1754878419d60d842b
|
|
| BLAKE2b-256 |
874eb0a2c8bea556179ba67144a070d89a7fca60815de50de2323232e81d7adf
|
Provenance
The following attestation bundles were made for ai_sub-2.10.0b1.tar.gz:
Publisher:
publish.yml on FlippFuzz/ai-sub
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_sub-2.10.0b1.tar.gz -
Subject digest:
ae05ec4d956fe9b3f78c55ac467294ad8e4faa2b257fb130b3b5b6ccde5f6946 - Sigstore transparency entry: 1799825008
- Sigstore integration time:
-
Permalink:
FlippFuzz/ai-sub@f32505968e43d9ce75280838e8f302039e935159 -
Branch / Tag:
refs/tags/v2.10.0b1 - Owner: https://github.com/FlippFuzz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f32505968e43d9ce75280838e8f302039e935159 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ai_sub-2.10.0b1-py3-none-any.whl.
File metadata
- Download URL: ai_sub-2.10.0b1-py3-none-any.whl
- Upload date:
- Size: 45.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
268c0f8f3e3a78fe3b14b657250eeb8f8586806bf3df6588e260cf833896c8fe
|
|
| MD5 |
d56da74cc92d92a73f12ff1d952b9c4e
|
|
| BLAKE2b-256 |
509f8bf53cfc5d3a6d256cc3c83adf8af7405207408ca21d2dbb0ff7c0f60be1
|
Provenance
The following attestation bundles were made for ai_sub-2.10.0b1-py3-none-any.whl:
Publisher:
publish.yml on FlippFuzz/ai-sub
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_sub-2.10.0b1-py3-none-any.whl -
Subject digest:
268c0f8f3e3a78fe3b14b657250eeb8f8586806bf3df6588e260cf833896c8fe - Sigstore transparency entry: 1799825277
- Sigstore integration time:
-
Permalink:
FlippFuzz/ai-sub@f32505968e43d9ce75280838e8f302039e935159 -
Branch / Tag:
refs/tags/v2.10.0b1 - Owner: https://github.com/FlippFuzz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f32505968e43d9ce75280838e8f302039e935159 -
Trigger Event:
release
-
Statement type: