How to Check AI-Translated SRT Subtitles Before Uploading to YouTube
“Do not share the code” fits on one subtitle line. So does “Share the code.” Both can appear and disappear at exactly the right moment. If you ask AI to translate subtitles for a YouTube lesson, you have two separate editing jobs: check that the captions still land where you put them, then check what they tell the viewer to do.
Here is a two-caption English-to-Urdu example you can break on purpose. The Python checker below compares an original SRT subtitle file with a translation on your own computer. It does not need your video, an API key or a Python package. If your translator intentionally changed the timing to improve readability, use the differences as an edit list, not as instructions to undo good work.
Start with the captions for the final cut
Use the subtitle file that matches the version of the video you are uploading. Cutting half a second from the intro after exporting subtitles can put both languages out of sync. Comparing the files will not catch that: they still agree with each other.
Save this as lesson.en.srt in a plain-text editor, using UTF-8. Each numbered block is a cue. The comma marks milliseconds; the blank line separates one cue from the next. The Library of Congress description of SubRip shows the structure in more detail.
1
00:00:00,000 --> 00:00:02,400
Check the amount.
2
00:00:02,400 --> 00:00:05,000
Do not share the code.Make a copy called lesson.ur.srt. Replace “Check the amount.” with the first line below, and “Do not share the code.” with the second. Leave the numbers and timestamps alone.
رقم چیک کریں۔
کوڈ کسی کو نہ بتائیں۔
For a longer track, give the translator a clear boundary: “Translate only the caption text into Urdu. Keep each cue number and both timestamps unchanged. Keep meaningful sound cues and speaker labels. Return plain SRT. Flag disputed terms separately, outside the file.” Share only material you have permission to send. There is no reason to upload a private recording to run the check below.
Compare the two SRT files locally
Save the code below as check_srt.py in the same folder as your two subtitle files. From a terminal opened in that folder, run python check_srt.py lesson.en.srt lesson.ur.srt. If your Python 3 command is python3 or py, use that instead. The script reads both files without changing them.
Show the Python subtitle checker to copy
"""Compare two basic SRT tracks without reading media, uploading or rewriting files."""
import argparse
from pathlib import Path
import re
import sys
STAMP = r"[0-9]{2}:[0-5][0-9]:[0-5][0-9],[0-9]{3}"
TIMING = re.compile(rf"({STAMP})[ \t]+-->[ \t]+({STAMP})")
def parse(raw):
text = raw.decode("utf-8-sig").replace("\r\n", "\n").replace("\r", "\n")
if not text.strip() or "\x00" in text:
raise ValueError("empty track or NUL character")
windows = []
for n, block in enumerate(re.split(r"\n(?:[ \t]*\n)+", text.strip("\n")), 1):
lines = block.split("\n")
if len(lines) < 3 or lines[0].strip() != str(n):
raise ValueError(f"cue {n}: expected sequential number, timing and text")
match = TIMING.fullmatch(lines[1].strip())
if not match or match[1] >= match[2]:
# Fixed-width HH:MM:SS,mmm sorts in time order; equal means zero duration.
raise ValueError(f"cue {n}: invalid timestamp or non-positive duration")
body = lines[2:]
if not any(line.strip() for line in body):
raise ValueError(f"cue {n}: empty text")
if any(TIMING.fullmatch(line.strip()) or line.strip().startswith("```") for line in body):
raise ValueError(f"cue {n}: extra timing line or Markdown fence in caption")
windows.append(match.groups())
return windows
def differences(source, translation):
if len(source) != len(translation):
yield f"cue count: source {len(source)}, translation {len(translation)}"
for n, (old, new) in enumerate(zip(source, translation), 1):
if old != new:
yield f"cue {n}: expected {' --> '.join(old)}, got {' --> '.join(new)}"
def main(argv=None):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("source", type=Path)
parser.add_argument("translation", type=Path)
args = parser.parse_args(argv)
tracks = []
for label, path in (("source", args.source), ("translation", args.translation)):
try:
tracks.append(parse(path.read_bytes()))
except (OSError, ValueError) as error:
print(f"INPUT ERROR ({label}): {error}", file=sys.stderr)
return 2
mismatch = False
for message in differences(*tracks):
print(message, file=sys.stderr)
mismatch = True
if mismatch:
return 1
print(f"PASS: {len(tracks[0])} cue windows match. Translation not assessed.")
return 0
if __name__ == "__main__":
sys.exit(main())With the two example captions, the result is PASS: 2 cue windows match. Translation not assessed. Now change the end of cue 2 in the Urdu file from 00:00:05,000 to 00:00:05,400 and run it again. The checker shows the two windows side by side:
cue 2: expected 00:00:02,400 --> 00:00:05,000, got 00:00:02,400 --> 00:00:05,400Those extra 400 milliseconds might leave the old instruction on screen when the next shot starts. Play that cut to decide. If the count is wrong, look for a dropped or merged cue before chasing every later timestamp. A gap in the cue numbers produces an input error first.
For a batch of lessons, you can use the exit code: 0 means the ordered time windows match, 1 means they differ, and 2 means a file is unreadable or has an unexpected format. The checker expects cue numbers starting at 1, nonempty text and a positive duration. It does not test for overlaps between cues, reading speed or timing against the audio.
Listen for the word the checker cannot hear
Restore the example timestamp. Now remove نہ from the second Urdu cue. The checker passes again. A viewer who follows that line is now being told to share the code. A second reader who knows both languages can catch what an exact timestamp comparison cannot.
In a real lesson, listen while reading the target language at normal playback speed. Start with instructions that could cost a viewer something if misheard: do not, a dosage unit, a currency amount, or the name of the button that deletes a file. Then watch with sound off. Can you tell who spoke off camera? If a warning tone is the only signal that an action failed, is it captioned? W3C’s guidance on captions explains why relevant sounds and speaker identification belong in the text.
Check the uploaded track in the player
YouTube supports basic SRT in plain UTF-8. Do not depend on SRT styling to distinguish speakers. In YouTube Studio, select the video and the intended subtitle language, then upload the subtitle file with timing. Select that language in the player. Watch the first cue, an instruction at a scene change, and the final line through its disappearance. For Urdu, check the text alongside any English button labels on a phone: punctuation that looks fine in the editor can be confusing in the player.
If you find a mistranslation, edit the caption text. If both tracks lag the picture, go back to the cut and correct the timing. Those are different fixes. For the broader editing workflow, see the technical content creation and editing lesson.





