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):

    # macOS (recommended — also adds the binary to your PATH)
    brew install whisper-cpp
    
    # Linux — build from source
    git clone https://github.com/ggml-org/whisper.cpp
    cd whisper.cpp && cmake -B build && cmake --build build --config Release
    export SUBTITLE_WHISPER_BINARY="$(pwd)/build/bin/whisper-cli"
    
    # Windows — download a prebuilt release
    # https://github.com/ggml-org/whisper.cpp/releases
    # then add the folder containing whisper-cli.exe to PATH
    

    The CLI auto-discovers the binary in this order:

    1. --whisper-binary /path/to/whisper-cli
    2. SUBTITLE_WHISPER_BINARY environment variable
    3. whisper-cli / whisper-cpp / main on your PATH
    4. ./binary/whisper-cli relative to the current directory (legacy)

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.2.tar.gz (40.6 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.2-py3-none-any.whl (41.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: subtitle_generator-3.0.2.tar.gz
  • Upload date:
  • Size: 40.6 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.2.tar.gz
Algorithm Hash digest
SHA256 a4a55fd6675353a637e5b80ba97f5b81e2bc29331017b9c85b4fdaf1a8bc21e8
MD5 2d7ebd30814e8b2930da231cfd928297
BLAKE2b-256 e089f117d1f8f9eda0b023e6c9f84a9cdbe3d32f909f63b616c65f7c4f90d545

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for subtitle_generator-3.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f42203d61b7a3abc7d405ff407c727d23c48dc19c3edfa5ea5800658a32791cd
MD5 ed014c662d9b284fe0acd849d1769101
BLAKE2b-256 c22777b68cdb5285e7e068dc7da52d9ab25191c4a5288769dc99f601ed4d3fe6

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