Advanced subtitle translator with AI support for converting SRT to bilingual ASS files using OpenAI, Gemini, or DeepSeek APIs
Project description
Bazarr LLM Translate
Advanced subtitle translator with LLM support and web API. Converts SRT subtitle files to styled ASS format with bilingual or monolingual translations using OpenAI, Google Gemini, or DeepSeek APIs.
Features
- Web API: FastAPI-based REST API for subtitle translation
- CLI Tool: Command-line interface for batch processing
- Multiple AI Providers: OpenAI, Google Gemini, DeepSeek support
- Bilingual Mode: Displays original text on top and translated text below
- Monolingual Mode: Replaces original text with translation
- Smart Translation: Full text or selective difficulty translation modes
- Resumable: Automatically saves progress and can resume if interrupted
- Batch Processing: Processes subtitles in batches for efficient API usage
- Containerized: Docker support with multi-platform builds
Quick Start
Using Docker (Recommended)
-
Pull the image:
docker pull ghcr.io/yanp/llm-subtitle-translator:latest
-
Run the container:
docker run -d \ -p 8080:8080 \ -e DEEPSEEK_API_KEY=your_api_key_here \ ghcr.io/yanp/llm-subtitle-translator:latest
-
Access the API:
- Web interface: http://localhost:8080/docs
- Health check: http://localhost:8080/health
Using Docker Compose
-
Clone the repository:
git clone https://github.com/yanp/llm-subtitle-translator.git cd llm-subtitle-translator
-
Set up environment variables:
cp .env.example .env # Edit .env with your API keys
-
Start the service:
docker-compose up -d
Local Development
-
Install uv:
curl -LsSf https://astral.sh/uv/install.sh | sh
-
Install dependencies:
uv venv uv pip install -e .
-
Set environment variables:
export DEEPSEEK_API_KEY=your_api_key_here
-
Run the API:
uv run fastapi dev src/llm_subtitle_translator/app.py
-
Or use the CLI:
uv run translate-subtitles input.srt --translation-mode bilingual
API Usage
Translate Subtitle File
POST /translate
Supports two modes: file upload or file path processing.
Mode 1: File Upload (Web Interface)
Upload an SRT file and get back a translated ASS file.
Parameters:
file: SRT subtitle file to uploadprovider: AI provider (openai,gemini,deepseek) - default:deepseekmodel: Specific model name (optional)translation_mode:bilingualormonolingual- default:bilingualprompt_template:full_textorselective_difficulty- default:selective_difficultybatch_size: Number of lines per API call - default:50
Example:
curl -X POST "http://localhost:8080/translate" \
-F "file=@subtitle.srt" \
-F "provider=deepseek" \
-F "translation_mode=bilingual" \
-F "prompt_template=selective_difficulty" \
-o translated_subtitle.ass
Mode 2: File Path (Bazarr Hook)
Process files on the server filesystem (ideal for Bazarr hooks).
Parameters:
input_path: Path to SRT subtitle file on serveroutput_path: Output path for translated file (optional, defaults to same directory with .en-zh.ass extension)provider: AI provider (openai,gemini,deepseek) - default:deepseekmodel: Specific model name (optional)translation_mode:bilingualormonolingual- default:bilingualprompt_template:full_textorselective_difficulty- default:selective_difficultybatch_size: Number of lines per API call - default:50
Example:
curl -X POST "http://localhost:8080/translate" \
-F "input_path=/media/subtitles/movie.srt" \
-F "output_path=/media/subtitles/movie.en-zh.ass" \
-F "provider=deepseek" \
-F "translation_mode=bilingual"
Get Available Providers
GET /providers
Returns available AI providers and their configuration status.
CLI Usage
uv run translate-subtitles input.srt [options]
Options:
-o, --output: Output file path--translation-mode:bilingualormonolingual--prompt-template:full_textorselective_difficulty-p, --provider: AI provider (openai,gemini,deepseek)-m, --model: Specific model name--batch-size: Batch size for API calls
Example:
uv run translate-subtitles movie.srt \
--translation-mode bilingual \
--prompt-template selective_difficulty \
--provider deepseek \
--batch-size 50
Configuration
Environment Variables
| Variable | Description | Required |
|---|---|---|
OPENAI_API_KEY |
OpenAI API key | For OpenAI provider |
GEMINI_API_KEY |
Google Gemini API key | For Gemini provider |
DEEPSEEK_API_KEY |
DeepSeek API key | For DeepSeek provider |
Translation Modes
- Bilingual: Shows original text on top, translation below
- Monolingual: Replaces original text with translation
Prompt Templates
- Full Text: Translates every subtitle line
- Selective Difficulty: Only translates complex phrases, slang, or cultural references
Development
Setup
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dependencies
uv venv
uv pip install -e ".[dev]"
# Activate virtual environment
source .venv/bin/activate
Code Quality
# Format code
black .
# Lint code
ruff check .
# Type checking
mypy .
Testing
# Run tests
pytest
# Run with coverage
pytest --cov=.
Docker
Build locally
docker build -t llm-subtitle-translator .
Multi-platform build
docker buildx build --platform linux/amd64,linux/arm64 -t llm-subtitle-translator .
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Support
- Open an issue on GitHub
- Check the API documentation at
/docswhen running the server - Review the example files in the repository
Project details
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_subtitle_translator-0.1.0.tar.gz.
File metadata
- Download URL: ai_subtitle_translator-0.1.0.tar.gz
- Upload date:
- Size: 73.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e7ce1218d895e9a84cd1d7eb8a4b7131a1f14f8a93252e2b476d4b686e9934b
|
|
| MD5 |
126a5c29245955ebe6a3f06d9d0ad389
|
|
| BLAKE2b-256 |
4ce4aac30b351afa26b81e4e18e3118a6a4fb4874f9c3b528ae97b45b837170a
|
File details
Details for the file ai_subtitle_translator-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ai_subtitle_translator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 23.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a49e214d4258920c4fd71be4e5043344b1d899000099ec2a65199e0acd9e47d
|
|
| MD5 |
c28f749bd3fb8c199552dbc714a7c611
|
|
| BLAKE2b-256 |
0788b9e32211c70d046d86daf0905fc2f26b8f2863eacca762b071b1561bd68c
|