Inspect transcript words without start or end: skip them in cuts

Inspect transcript words can omit start or end. Treat an untimed word as unknown, and never cut across a gap that contains one: 0 of its time is safe to remove.

4 min readSume
All posts

The inspect transcript returns words[], and start and end are optional in the schema. A pause cutter that does w["end"] on every word will raise a KeyError on an untimed one, or worse, treat a missing time as 0 and cut a minute of speech. Skip untimed words when you compute gaps, but treat an untimed word as a barrier: do not remove any gap beside it.

Whether untimed words occur in practice for your audio is not stated in the docs; the code below is defensive.

Rules

  • A gap exists only between two timed words that are adjacent in the list.
  • If an untimed word sits between two timed ones, the gap is unknown: keep it.
  • Never default a missing start or end to 0.
  • Log how many words you skipped so a bad transcript is visible.

Effect on the cut list

Hypothetical transcript of six words with one untimed word at index 3.

Gap decisions around an untimed word (hypothetical words, arithmetic only)
Between wordsGapDecision at 0.35 s
1 and 20.80 scut
2 and 30.10 skeep
3 and untimed 4unknownkeep
untimed 4 and 5unknownkeep
5 and 60.60 scut

Python

def gaps(words, threshold=0.35):
    cuts, prev = [], None
    for w in words:
        s, e = w.get("start"), w.get("end")
        if s is None or e is None:
            prev = None                 # barrier: gap beside it is unknown
            continue
        if prev is not None and s - prev > threshold:
            cuts.append((round(prev, 3), round(s, 3)))
        prev = e
    return cuts

Notes

  • A skipped word still costs nothing extra; the STT price is per audio minute ($0.01).
  • If many words are untimed, cut with sentence segments[] instead: they have no gaps by construction.
  • Trim rejects an output under 0.2 s, so still drop slivers.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume