DEV Community

Anlin
Anlin

Posted on AI-assisted

A Python check for voice-over overlap in AI video recaps

A first automatic cut can keep the right frame and cover the line that makes it work. Consider a fictional basketball game. A team comes back to tie the score. The narrator calls the basket while a player shouts “Get back on defense!” The question is whether the overlap was intentional.

For clips with separate source and narration tracks, flag overlaps between time ranges the editor marked as important and the scheduled narration. Use timestamps relative to the same edit timeline. An original source timecode is not an edit timecode.

from itertools import pairwise


def covered_seconds(mark, narration):
    start, end = mark
    cuts = sorted({start, end} | {
        point
        for left, right in narration
        for point in (left, right)
        if start < point < end
    })
    return sum(
        b - a
        for a, b in pairwise(cuts)
        if any(left < b and a < right for left, right in narration)
    )


court_call = (8.0, 9.2)
cut_a = [(6.1, 10.4)]
cut_b = [(6.1, 7.9), (9.3, 10.4)]

for label, spans in (("A", cut_a), ("B", cut_b)):
    print(f"{label}: {covered_seconds(court_call, spans):.2f}s")
Enter fullscreen mode Exit fullscreen mode

On Python 3.10 or later, this prints A: 1.20s and B: 0.00s for the synthetic timing above. Using the union of intervals avoids counting a span twice when two narration clips overlap each other.

A timing check only identifies where to listen. It cannot tell if the shout is audible in the rendered mix. Compare both edits with the picture unchanged and play each export from one line before the basket. Ask a viewer what made them expect the next possession. If the shout stays, time the caption to the actual line.

The basketball scenario and timecodes are fictional. AI generated this draft and the teaching diagram.

Teaching diagram comparing narration overlap with the original on-court shout

Top comments (0)