Ask for timed segments when you transcribe the recording. Each segment gives a subtitle cue its start time, end time, and text. You can then export an SRT for an editor and a WebVTT for a web player from the same transcript.
Get segment timings from OpenRouter
Set AUDIO to the path of a short recording, OPENROUTER_API_KEY to your API key, and TRANSCRIPT_JSON to a new output path. This request uses the hosted Whisper model. OpenRouter documents JSON and verbose JSON as response formats. Requesting SRT or VTT directly returns HTTP 400. OpenRouter transcription documentation
curl --fail-with-body --silent --show-error \
'https://openrouter.ai/api/v1/audio/transcriptions' \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-F "file=@$AUDIO" -F model=openai/whisper-1 \
-F response_format=verbose_json \
-F 'timestamp_granularities[]=segment' \
-o "$TRANSCRIPT_JSON"
Write both files from one response
Choose separate, unused output paths in SRT_OUT and VTT_OUT. This Python 3 example keeps one cue per nonempty segment. It rounds the entire timestamp to milliseconds before splitting it into hours, minutes, and seconds, so a cue near a minute boundary rolls over correctly.
python3 - "$TRANSCRIPT_JSON" "$SRT_OUT" "$VTT_OUT" <<'PY'
import json, sys
from html import escape
from pathlib import Path
source, srt_out, vtt_out = map(Path, sys.argv[1:])
segments = json.loads(source.read_text(encoding="utf-8")).get("segments")
if not segments:
raise SystemExit("No timed segments in this response.")
def stamp(ms, decimal):
seconds, ms = divmod(ms, 1000)
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
return f"{hours:02}:{minutes:02}:{seconds:02}{decimal}{ms:03}"
srt, vtt = [], ["WEBVTT"]
previous_start = -1
for segment in segments:
text = " ".join(segment["text"].split())
if not text:
continue
start = round(segment["start"] * 1000)
end = round(segment["end"] * 1000)
if start < 0 or start < previous_start or end <= start:
raise SystemExit("Review an out-of-order or empty cue.")
previous_start = start
for blocks, decimal in ((srt, ","), (vtt, ".")):
timing = f"{stamp(start, decimal)} --> {stamp(end, decimal)}"
if decimal == ",":
blocks.append(f"{len(srt) + 1}\n{timing}\n{text}")
else:
blocks.append(f"{timing}\n{escape(text, quote=False)}")
if not srt:
raise SystemExit("No subtitle text in the segments.")
for path, blocks in ((srt_out, srt), (vtt_out, vtt)):
path.write_text("\n\n".join(blocks) + "\n", encoding="utf-8")
PY
Check the first cue and a late cue
Open both files as UTF-8 text. The SRT starts with cue number 1 and uses a comma before milliseconds. The VTT begins with WEBVTT and uses a period. Play a cue near the end as well as the opening line. A late cue that starts early after a file split often means its timestamps still measure from the start of that chunk. Add the chunk’s start position on the original timeline before exporting. WebVTT timing specification
Speech recognition segments can be longer than a reader can follow. Split a long line at a phrase boundary, then listen for the new cue’s start time. If you already use Deepgram’s CLI, dg listen "$AUDIO" --srt --save-to "$SRT_OUT" requests an SRT directly. Select --webvtt for WebVTT. Deepgram CLI documentation
Local check. We ran the converter on a hand-written segment beginning at 59.9996 seconds. Both exports rounded its start to exactly one minute. The OpenRouter request above follows the linked API documentation.