Skip to main content

Synthesize a timestamp-synced speech track from a subtitle file and mux it into video

Project description

srt2speech

Turn a subtitle file into a timestamp-synced speech track and mux it into a video.

Give it a video + an .srt (or .vtt/.ass); it synthesizes audio where each subtitle is spoken at its timestamp, then optionally muxes the track back in with ffmpeg. Useful for restoring lost audio, rough translation dubs, narrating silent videos, or adding audio description by reading only the descriptive/SDH cues.

It does the SRT→audio part well and nothing else: no translation, no transcription — bring an already-final subtitle file.

Requirements

  • Python ≥ 3.11, uv
  • ffmpeg / ffprobe on PATH
  • A TTS backend:
    • piper — a local gopipertts server (free, default; set SRT2SPEECH_PIPER_URL if not on http://localhost:8080)
    • openaigpt-4o-mini-tts (set OPENAI_API_KEY)
    • elevenlabseleven_multilingual_v2 (set ELEVENLABS_API_KEY)

Install

Run it straight from PyPI with no install — uvx fetches it on first use:

uvx srt2speech --help

Or install it as a persistent tool (then just call srt2speech):

uv tool install srt2speech

Usage

# generate a synced track with the local piper backend, sized to the video
uvx srt2speech generate subs.srt --video clip.mp4 -o track.wav

# generate + mux into the video in one step
uvx srt2speech run clip.mp4 subs.srt -o dubbed.mp4

# paid backend with delivery guidance
OPENAI_API_KEY=... uvx srt2speech generate subs.srt \
    --backend openai --voice coral --instructions "calm documentary narration" -o track.wav

# audio description: only descriptive/SDH cues, mixed over the existing audio
uvx srt2speech run movie.mkv subs.srt --mode descriptive --mux-mode mix -o described.mkv

# mux an existing track yourself
uvx srt2speech mux clip.mp4 track.wav -o dubbed.mp4

# list a backend's voices
uvx srt2speech voices --backend openai

Docker Compose

Runs a local piper server plus an on-demand CLI; no host Python or ffmpeg needed. Put your video and subtitles in ./data (mounted at /data); pulled voices are cached in ./voices.

# 1. start the piper TTS server (preloads the default voice)
docker compose up -d gopipertts

# 2. run the CLI against files in ./data
docker compose run --rm srt2speech run /data/clip.mp4 /data/subs.srt -o /data/dubbed.mp4

# 3. tear down when done
docker compose down

For the OpenAI backend, put OPENAI_API_KEY=sk-... in a .env file (gitignored) — Compose loads it automatically and passes it through to the CLI container.

Sync strategies (--strategy)

Speech rarely fits a cue's window exactly. The fit engine offers:

  • hybrid (default) — fit into the cue window plus the silent gap before the next cue; only then speed up, capped by --max-speedup (default 1.15).
  • overflow — never speed up; let speech run into following silence (best quality, can drift).
  • precise — fit the exact cue window, speeding up to the cap.

Modes (--mode)

all (default) · descriptive (SDH/audio-description only) · dialogue (drop sound cues).

Development

From a clone of the repo:

uv sync
uv run srt2speech --help
uv run pytest
uv run ruff check

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

srt2speech-1.2.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

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

srt2speech-1.2.0-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file srt2speech-1.2.0.tar.gz.

File metadata

  • Download URL: srt2speech-1.2.0.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for srt2speech-1.2.0.tar.gz
Algorithm Hash digest
SHA256 0d69c2d74cb0c02e4df97efaad25ca37388ae75dc5385e0002c4b8f8d84cc0ea
MD5 a9e70fa290e7854d732eb117cf2bb1a6
BLAKE2b-256 c2fe75a95d1319030b1a7eb6e60ca04e4ea5c0beca3a4df205992b9bc4516573

See more details on using hashes here.

Provenance

The following attestation bundles were made for srt2speech-1.2.0.tar.gz:

Publisher: publish.yml on nbr23/srt2speech

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file srt2speech-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: srt2speech-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for srt2speech-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0dd62b272793db911e07210c8b6baa1240104ef71365e44e5a467e125cd3001
MD5 e162227bfa959422f3f1cf0a244c5414
BLAKE2b-256 dc883107fd21f8f9446a231bcf4b7b693860e20aa6c1ada6d46aed1e09af9017

See more details on using hashes here.

Provenance

The following attestation bundles were made for srt2speech-1.2.0-py3-none-any.whl:

Publisher: publish.yml on nbr23/srt2speech

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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