RAG over Audio and Video

Transcribe recordings with timestamps and retrieve the exact moment that answers a question.

Last Updated:

Module 15 · Lesson 4 of 5 · Advanced

RAG over Audio and Video

Transcribe recordings with timestamps and retrieve the exact moment that answers a question.

Meetings, webinars, training videos, podcasts and customer calls contain knowledge that never makes it into documents. RAG over audio and video turns recordings into searchable text and, crucially, keeps timestamps, so an answer can point to the exact moment in the recording: "the CFO explains this at 14:32".

The pipeline

  1. Transcribe speech to text with timestamps per segment.
  2. Optionally identify speakers (diarisation).
  3. Chunk by time, keeping the start and end times of each chunk.
  4. Index the chunks with recording metadata (title, date, URL).
  5. Answer with timestamp citations that link to the right moment.

Step 1: Transcribe with timestamps

faster-whisper runs OpenAI's open-source Whisper speech recognition models efficiently on CPU or GPU and returns timestamped segments. Video files work too, because the audio track is decoded automatically.

pip install faster-whisper
transcribe.py
from faster_whisper import WhisperModel

model = WhisperModel("small", device="cpu", compute_type="int8")   # "medium"/"large-v3" for accuracy

def transcribe(path: str) -> list[dict]:
    segments, info = model.transcribe(path, vad_filter=True)       # VAD skips long silences
    print(f"Detected language: {info.language}")
    return [{"start": s.start, "end": s.end, "text": s.text.strip()} for s in segments]

segments = transcribe("all-hands-2026-09.mp4")
print(segments[:3])

Hosted speech-to-text APIs are an alternative when you do not want to run models yourself; most return similar timestamped segments, and many include speaker labels.

Step 2: Chunk by time windows

Whisper segments are short (a few seconds). Group them into windows of about 45 to 90 seconds with some overlap. Each chunk keeps its start and end time.

def time_chunks(segments: list[dict], window: float = 60.0, overlap: float = 10.0) -> list[dict]:
    chunks, start_idx = [], 0
    while start_idx < len(segments):
        t0 = segments[start_idx]["start"]
        group = [s for s in segments[start_idx:] if s["start"] < t0 + window]
        chunks.append({"start": group[0]["start"], "end": group[-1]["end"],
                       "text": " ".join(s["text"] for s in group)})
        next_idx = next((i for i in range(start_idx, len(segments))
                         if segments[i]["start"] >= t0 + window - overlap), len(segments))
        start_idx = max(next_idx, start_idx + 1)
    return chunks

def ts(seconds: float) -> str:
    m, s = divmod(int(seconds), 60)
    h, m = divmod(m, 60)
    return f"{h}:{m:02d}:{s:02d}" if h else f"{m}:{s:02d}"

Step 3: Index with recording metadata

recording = {"title": "All-hands meeting, September 2026", "date": "2026-09-18",
             "url": "https://videos.example.com/all-hands-2026-09"}

records = [{
    "id": f"allhands-2026-09@{int(c['start'])}",
    "text": f"[{recording['title']}, {ts(c['start'])}-{ts(c['end'])}] {c['text']}",
    "metadata": {**recording, "start": c["start"], "end": c["end"]},
} for c in time_chunks(segments)]

Contextual headers (the recording title and time range) help both retrieval and the LLM, exactly as for text documents.

Step 4: Answer with clickable timestamps

from rag_helpers import ask

def answer_from_recordings(question: str, hits) -> str:
    sources = "\n".join(
        f'<clip id="{i}" link="{h.metadata["url"]}?t={int(h.metadata["start"])}" '
        f'time="{ts(h.metadata["start"])}">\n{h.text}\n</clip>'
        for i, h in enumerate(hits, start=1))
    return ask(f"<clips>\n{sources}\n</clips>\n\nThese are transcript excerpts from recordings. "
               "Answer the question from them. After each fact, cite the clip as "
               "(time, clip id). Transcripts can contain recognition errors; if a key word looks "
               f"garbled, say so.\n\nQuestion: {question}")

Most video platforms accept a start-time parameter in the URL (for example ?t=872), so each citation can open the recording at the right moment.

Practical tips

  • Custom vocabulary: transcription often mangles product names and jargon. Whisper accepts an initial_prompt with expected terms ("Zentrix, X200, Core Billing"), which noticeably improves accuracy.
  • Speakers: for meetings and calls, diarisation (for example with pyannote.audio) lets you index "who said what" and filter by speaker.
  • Visual content: for screen recordings and slide-based talks, extract a frame every few seconds when the picture changes and describe it with a vision model (see RAG over Images), aligned to the same timestamps.
  • Summaries: generate a summary and chapter list per recording and index them too; they answer "what was this meeting about?" questions.
  • Consent and privacy: recordings of people are personal data. Check consent, retention rules and access rights before indexing them.

Key takeaways

  • Transcribe recordings with timestamps, then chunk by time windows with overlap.
  • Add recording title and time range to each chunk and keep times in metadata.
  • Cite answers with timestamps that link to the exact moment.
  • Improve accuracy with vocabulary prompts, speaker labels and frame descriptions.