Join speech intervals to screen frames
Implement align_segments(frames, segments, max_gap), returning a list of frame IDs or None in segment order using an offline nearest-midpoint rule.
Your task
- Frames are dictionaries with time and id; segments have start and end. Timestamp units are shared.
- Choose nearest frame to each midpoint, breaking ties by earlier frame time then lexicographic ID.
- Return None when no frame exists or the nearest gap exceeds max_gap.
- Reject negative max_gap and any segment whose end precedes start; do not modify inputs.
Examples
EXAMPLE 1
InputFrames a@100, b@300; segment [180,220]; max_gap=100
Output['a']
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor