Turn an SRT subtitle file into a Word transcript with a 40-line Python script
SRT2WordAn .srt file is plain text, which is why it feels like it should be easy to read in Word. It is not. Open one with File → Open and you get cue numbers, 00:00:04,200 --> 00:00:07,500 lines, and sentences chopped every few words to fit a video frame. If you need a reading copy for a client, a reviewer, or your own notes, you want paragraphs.
This post shows the script I would write if I had to do it by hand, plus the three decisions that matter: what to do with timestamps, what to do with line breaks inside a cue, and what to do with speaker dashes. The script was run against a small sample before publishing, and the output is shown below.
What an SRT cue actually is
Every cue is a block separated by a blank line: an index, a time range with a comma before the milliseconds, then one or more lines of text.
1 00:00:01,200 --> 00:00:04,000 Welcome to the product sync, thanks for joining. 2 00:00:04,200 --> 00:00:07,500 Today we will convert this transcript into Word.
Two details trip people up. First, the comma in the time (some tools write a period, so accept both). Second, a cue can have two or three text lines, and those lines belong to one sentence, so join them with a space instead of keeping the break.
The script
Install the one dependency with pip install python-docx, then save this as srt2docx.py:
import re, sys
from docx import Document
TIME = re.compile(r"(\d+):(\d+):(\d+)[,.](\d+)\s*-->\s*(\d+):(\d+):(\d+)[,.](\d+)")
def parse(text):
cues = []
for block in re.split(r"\n\s*\n", text.replace("\r\n", "\n").strip()):
lines = [l for l in block.split("\n") if l.strip()]
for i, l in enumerate(lines):
m = TIME.search(l)
if m:
h, mi, s = (int(x) for x in m.group(1, 2, 3))
body = " ".join(x.strip() for x in lines[i + 1:])
cues.append((h * 3600 + mi * 60 + s, body))
break
return cues
def stamp(sec):
return f"{sec // 3600:d}:{sec % 3600 // 60:02d}:{sec % 60:02d}"
def convert(src, dst, timestamps=True):
doc = Document()
for sec, body in parse(open(src, encoding="utf-8-sig").read()):
p = doc.add_paragraph()
if timestamps:
p.add_run(f"[{stamp(sec)}] ").bold = True
p.add_run(body)
doc.save(dst)
if __name__ == "__main__":
convert(sys.argv[1], sys.argv[2], timestamps="--no-time" not in sys.argv)Run python srt2docx.py episode.srt episode.docx to keep a bold start time at the front of each paragraph, or add --no-time for a clean reading copy.
On the sample above the output paragraphs are: [0:00:01] Welcome to the product sync, thanks for joining. and [0:00:04] Today we will convert this transcript into Word. With --no-time the bracketed time disappears and nothing else changes.
Three choices worth making on purpose
Keep timestamps when someone has to find the line in the video again. Translators, QA reviewers, and lawyers all do this. The start time is enough; the end time is rarely needed in a document.
Drop them for anything that should read like prose. Meeting minutes, a blog draft, or a word-count quote read better without a clock on every line.
Decide about the leading dash. Many subtitle files mark a change of speaker with - at the start of a line. The script above leaves it in, because deleting it would silently merge two people into one sentence. If you want speaker labels, add them after you know who is who.
Where a script stops being worth it
This is fine for one file you own. It gets tedious when you need merged speakers, a font and margin choice, a header on every page, a batch of fifty episodes, or when the file is WebVTT or ASS rather than SRT, since those have their own headers and styling tags. For that, a browser tool is quicker. SRT2Word does the same job without code: paste or drop the file, toggle timestamps, merge consecutive cues from the same speaker, and download a .docx; its step-by-step guide covers the workflow, and the VTT version covers voice tags. Conversion runs in the browser, so the transcript is not uploaded.
If you would rather stay on the command line, the script above is all you need.
More notes in this series: SRT to Word: with timestamps, without, and why you should not delete the arrows · Zoom transcript to a Word document without re-transcribing the meeting · SRT, VTT, or ASS: which caption file to download before you make a Word transcript