Skip to main content

Generate synchronized word-by-word captions for videos using WhisperX timestamps

Project description

Word-By-Word Captions (wbw-captions)

A Python tool to generate synchronized one-word captions for videos using word-level timestamps from WhisperX.

Overview

WBW takes WhisperX's word-level timestamp JSON output and creates visually appealing videos with synchronized one-word captions.

The JSON file generated by WhisperX with the high-precision word-level timestamps is required as input.

Installation

pip install word-by-word-captions

Dependencies

  • ffmpeg (for video processing)

Usage

1. Generate Word-level Timestamps

First, use WhisperX to generate word-level timestamps for your audio/video:

# Install WhisperX
pip install git+https://github.com/m-bain/whisperX.git

# Generate word-level timestamps
whisperx <audio.wav> --hf_token <your-token> --vad_method silero --language <lang> --model <model> --align_model <align_model>

This will create a JSON file with precise word timings.

2. Create Captioned Video

# Add captions to an existing video
wbw-captions -v input_video.mp4 -j whisperx_output.json -o output.mp4

Options:

  • -v, --video: Input video file (optional)
  • -j, --json: WhisperX JSON output file (required)
  • -o, --output: Output video file path (required)
  • --max_lines: Maximum number of lines per subtitle (default: 1)
  • --max_line_chars: Maximum characters per line (default: 40)

Example Output

The tool creates videos where:

  • Each word is highlighted in yellow as it's spoken
  • Words are synchronized with precise timing from WhisperX
  • Text is easily readable with proper contrast and outlines
  • Captions are positioned at the bottom with proper margins

Development

To set up the development environment:

  1. Clone the repository
  2. Install development dependencies:
    pip install -e ".[dev]"
    
  3. Run tests:
    pytest
    

License

MIT License

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

word_by_word_captions-1.0.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

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

word_by_word_captions-1.0.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file word_by_word_captions-1.0.0.tar.gz.

File metadata

  • Download URL: word_by_word_captions-1.0.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for word_by_word_captions-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fccc0c3027d963e2e0654588be32f5b8ac0b02449396cfc3f2aa7a834cf151dd
MD5 192c5665a43a49a59a0300e43639bde8
BLAKE2b-256 2458ea3f2cf57a654406dcb643bdfc5729e843700ff9a5141f3c2e99311b5af1

See more details on using hashes here.

File details

Details for the file word_by_word_captions-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for word_by_word_captions-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c69a9b7627042d0128126611e2e2f0fba4c7bb75545cd7cfd40ecdd1c819e1d4
MD5 84268bcb6e9c67ae29dd2dd4d68a6c65
BLAKE2b-256 27b2f83fc0bdb1fe2c7017879ba78b6eb6e3918f6febbd9836ff2fd04b5850c9

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