Skip to main content

AI-powered subtitle generation from video/audio using Whisper.

Project description

Subtitle Generator

AI-powered subtitle generation using Whisper for accurate speech-to-text transcription.

PyPI version License: MIT Python 3.9+

Features

  • 🎯 Multi-format output - VTT, SRT, TXT, JSON, LRC, ASS, TTML
  • 🚀 Fast processing - Powered by whisper.cpp for high-performance inference
  • 📦 Batch processing - Process multiple videos at once
  • 🔄 Video embedding - Embed subtitles directly into videos
  • 🌍 Multilingual - Support for multiple languages

Installation

pip install subtitle-generator

Prerequisites

This package shells out to the whisper.cpp whisper-cli binary. It is not bundled in the wheel (whisper.cpp is per-OS native code), so you need to provide it once.

  • FFmpeg is required for video/audio processing:

    # macOS
    brew install ffmpeg
    
    # Ubuntu/Debian
    sudo apt install ffmpeg
    
    # Windows (via chocolatey)
    choco install ffmpeg
    
  • whisper-cli (the whisper.cpp transcription binary). The recommended setup is one command, run once after pip install:

    subtitle setup-whisper
    

    This clones the project's compatible whisper.cpp fork into your user data directory (e.g. ~/Library/Application Support/subtitle-generator/ on macOS) and builds it with CMake. Every subsequent subtitle <video> invocation auto-discovers the binary — no env vars, no PATH editing.

    Build prerequisites for setup-whisper:

    # macOS
    xcode-select --install     # provides clang++ + make
    brew install cmake ffmpeg
    
    # Linux (Debian/Ubuntu)
    sudo apt-get install -y build-essential cmake git ffmpeg
    
    # Windows
    # Install Visual Studio Build Tools, CMake, Git for Windows.
    

    The CLI auto-discovers the binary in this order:

    1. --whisper-binary /path/to/whisper-cli
    2. SUBTITLE_WHISPER_BINARY environment variable
    3. The binary installed by subtitle setup-whisper (preferred over PATH)
    4. whisper-cli / whisper-cpp / main on your PATH
    5. ./binary/whisper-cli relative to the current directory (legacy)

    Note: Homebrew's whisper-cpp formula (currently 1.8.4) dropped the -vi flag and only accepts pre-extracted audio (flac/mp3/ogg/wav), so it is not sufficient for this package's "pass a video, get subtitles" UX. Use subtitle setup-whisper to build a compatible binary instead.

Quick Start

# Generate subtitles (VTT format)
subtitle video.mp4

# Generate SRT format
subtitle video.mp4 --format srt

# Embed subtitles into video
subtitle video.mp4 --merge

# Use a larger model for better accuracy
subtitle video.mp4 --model large

CLI Commands

Command Description
subtitle <video> Generate subtitles for a video
subtitle models --list List available Whisper models
subtitle models --download <model> Download a specific model
subtitle batch --input-dir <dir> Batch process multiple videos
subtitle formats Show supported output formats

Options

Option Description
--model, -m Model to use: tiny, base, small, medium, large
--format, -f Output format: vtt, srt, txt, json, lrc, ass, ttml
--merge Embed subtitles into the video file
--threads, -t Number of processing threads
--verbose, -v Enable verbose output

Python API

from subtitle_generator.core import SubtitleGenerator, WhisperCppTranscriber
from subtitle_generator.models import ModelManager

transcriber = WhisperCppTranscriber(binary_path="./binary/whisper-cli")
generator = SubtitleGenerator(transcriber=transcriber, model_manager=ModelManager())

result = generator.generate(
    input_path="video.mp4",
    model_name="base",
    output_format="srt",
    output_dir="data",
)
print(f"Subtitles saved to: {result.output_path}")

Models

Model Size Speed Accuracy
tiny ~75MB ⚡⚡⚡⚡ ⭐⭐
base ~140MB ⚡⚡⚡ ⭐⭐⭐
small ~460MB ⚡⚡ ⭐⭐⭐⭐
medium ~1.5GB ⭐⭐⭐⭐⭐
large ~3GB 🐢 ⭐⭐⭐⭐⭐

Tip: Use .en models (e.g., base.en) for English-only content for faster processing.

Links

License

MIT License - see LICENSE for details.

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

subtitle_generator-3.0.3.tar.gz (46.3 kB view details)

Uploaded Source

Built Distribution

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

subtitle_generator-3.0.3-py3-none-any.whl (48.2 kB view details)

Uploaded Python 3

File details

Details for the file subtitle_generator-3.0.3.tar.gz.

File metadata

  • Download URL: subtitle_generator-3.0.3.tar.gz
  • Upload date:
  • Size: 46.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for subtitle_generator-3.0.3.tar.gz
Algorithm Hash digest
SHA256 574b611b6cd9594656e236482cafb2abd3844e94da32e08c897aa92922d8ccef
MD5 df6308a31c95b30924a969dd3f682993
BLAKE2b-256 a882e5dd699b9ee336c3e20392aa89c0f7f709b2513dae7817828494403e34dc

See more details on using hashes here.

File details

Details for the file subtitle_generator-3.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for subtitle_generator-3.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bf23c08abd04d307de80e7e35dd3fd32d3e892ea8907e64c2e6ec4742acbc26b
MD5 72fb69b86609dce439438ec4fb48ef99
BLAKE2b-256 4ab229d7823118c1144be9d1b4ce20098ac2adf2f8943f9aa6a3c397e4a5697b

See more details on using hashes here.

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