> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mavera.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Podcast Analysis Pipeline

> Transcribe podcast episodes with topic detection and paragraph segmentation, then feed structured transcripts to Mavera for content strategy — topic heatmaps, resonance signals, and editorial calendars.

## Scenario

Transcribe podcast episodes with topic detection, paragraph segmentation, and utterance timing. Feed structured transcripts to Mavera for content strategy — which topics resonate, derivative content to create, and editorial calendar gaps.

**Flow:** Deepgram `POST /v1/listen?model=nova-3&detect_topics=true&paragraphs=true&utterances=true&diarize=true` → topic-tagged transcript → Mavera `POST /mave/chat` → Content strategy

## Code

<CodeGroup>
  ```python Python theme={"dark"}
  import os, requests, time

  DG = os.environ["DEEPGRAM_API_KEY"]
  MV = os.environ["MAVERA_API_KEY"]
  MV_BASE = "https://app.mavera.io/api/v1"
  MV_H = {"Authorization": f"Bearer {MV}", "Content-Type": "application/json"}

  EPISODES = [{"file": "ep-47-ai-marketing.mp3", "title": "EP47: AI in Marketing"},
      {"file": "ep-48-brand-strategy.mp3", "title": "EP48: Brand Strategy 2026"},
      {"file": "ep-49-content-ops.mp3", "title": "EP49: Content Ops at Scale"}]
  params = {"model": "nova-3", "smart_format": "true", "punctuate": "true",
      "detect_topics": "true", "paragraphs": "true", "utterances": "true",
      "diarize": "true", "language": "en"}

  all_eps = []
  for ep in EPISODES:
      with open(ep["file"], "rb") as f:
          resp = requests.post("https://api.deepgram.com/v1/listen", params=params,
              headers={"Authorization": f"Token {DG}", "Content-Type": "audio/mpeg"},
              data=f, timeout=180)
      resp.raise_for_status()
      r = resp.json()
      alt = r["results"]["channels"][0]["alternatives"][0]
      topics = [t["topic"] for s in r["results"].get("topics",{}).get("segments",[])
                for t in s.get("topics",[])]
      paragraphs = alt.get("paragraphs",{}).get("paragraphs",[])
      moments = [{"time": f"{int(p['start']//60)}:{int(p['start']%60):02d}",
          "text": " ".join(s.get("text","") for s in p.get("sentences",[]))[:200]}
          for p in paragraphs[:10]]
      dur = r.get("metadata",{}).get("duration",0)
      all_eps.append({"title": ep["title"], "min": round(dur/60,1),
          "words": len(alt["transcript"].split()), "topics": topics[:8], "moments": moments})
      print(f"{ep['title']} — {round(dur/60,1)}min | {len(alt['transcript'].split())} words | {len(topics)} topics")
      time.sleep(2)

  corpus = ""
  for e in all_eps:
      corpus += f"\n### {e['title']} ({e['min']}min, {e['words']} words)\n"
      corpus += f"Topics: {', '.join(e['topics'][:5])}\n"
      for m in e["moments"][:5]:
          corpus += f"  [{m['time']}] {m['text'][:150]}\n"

  time.sleep(1)
  strategy = requests.post(f"{MV_BASE}/mave/chat", headers=MV_H, json={
      "message": f"Podcast content strategist. {len(all_eps)} episodes:\n\n{corpus[:10000]}\n\n"
          "Produce:\n1. **TOPIC HEATMAP** — Topics across episodes\n"
          "2. **RESONANCE SIGNALS** — Longest discussion topics\n"
          "3. **CONTENT DERIVATIVES** — 10 blogs, 5 social threads, 3 video clips\n"
          "4. **GUEST INSIGHTS** — Key quotes to repurpose\n"
          "5. **EDITORIAL CALENDAR** — Next 4 episode topics\n"
  }).json()
  print(strategy.get("content", "")[:4000])
  ```

  ```javascript JavaScript theme={"dark"}
  import fs from "fs";
  const DG = process.env.DEEPGRAM_API_KEY, MV = process.env.MAVERA_API_KEY;
  const MV_BASE = "https://app.mavera.io/api/v1";
  const MV_H = { Authorization: `Bearer ${MV}`, "Content-Type": "application/json" };

  const EPISODES = [
    { file: "ep-47-ai-marketing.mp3", title: "EP47: AI in Marketing" },
    { file: "ep-48-brand-strategy.mp3", title: "EP48: Brand Strategy 2026" },
    { file: "ep-49-content-ops.mp3", title: "EP49: Content Ops at Scale" }];
  const params = new URLSearchParams({ model: "nova-3", smart_format: "true", punctuate: "true",
    detect_topics: "true", paragraphs: "true", utterances: "true", diarize: "true", language: "en" });

  const allEps = [];
  for (const ep of EPISODES) {
    const r = await fetch(`https://api.deepgram.com/v1/listen?${params}`, { method: "POST",
      headers: { Authorization: `Token ${DG}`, "Content-Type": "audio/mpeg" },
      body: fs.readFileSync(ep.file) }).then(r => r.json());
    const alt = r.results.channels[0].alternatives[0];
    const topics = (r.results.topics?.segments||[]).flatMap(s => (s.topics||[]).map(t => t.topic));
    const moments = (alt.paragraphs?.paragraphs||[]).slice(0,10).map(p => ({
      time: `${Math.floor(p.start/60)}:${String(Math.floor(p.start%60)).padStart(2,"0")}`,
      text: (p.sentences||[]).map(s => s.text).join(" ").slice(0,200) }));
    allEps.push({ title: ep.title, min: Math.round((r.metadata?.duration||0)/60*10)/10,
      words: alt.transcript.split(/\s+/).length, topics: topics.slice(0,8), moments });
    await new Promise(r => setTimeout(r, 2000));
  }

  let corpus = allEps.map(e => `### ${e.title} (${e.min}min)\nTopics: ${e.topics.slice(0,5).join(", ")}\n`
    + e.moments.slice(0,5).map(m => `  [${m.time}] ${m.text.slice(0,150)}`).join("\n")).join("\n\n");
  const strategy = await fetch(`${MV_BASE}/mave/chat`, { method: "POST", headers: MV_H,
    body: JSON.stringify({ message: `Podcast strategist. ${allEps.length} episodes:\n\n${corpus.slice(0,10000)}\n\n`
      + "Produce: TOPIC HEATMAP, RESONANCE SIGNALS, CONTENT DERIVATIVES, GUEST INSIGHTS, EDITORIAL CALENDAR" }),
  }).then(r => r.json());
  console.log(strategy.content || "");
  ```
</CodeGroup>

## Example Output

```text theme={"dark"}
EP47 — 42.3min | 6,847 words | 6 topics
EP48 — 38.7min | 5,921 words | 5 topics
EP49 — 51.2min | 8,334 words | 7 topics

TOPIC HEATMAP
  "AI content generation" — 3/3 episodes (14 min total)
  "brand consistency"     — 2/3 episodes (9 min)

CONTENT DERIVATIVES
  Blog: "Why AI Won't Replace Copywriters (But Will Replace Bad Ones)"
  Clip: EP47 [6:12–8:30] — Hot take on AI content quality

EDITORIAL CALENDAR
  EP50: Content Measurement (gap: only 4 min coverage)
  EP51: AI + Brand Voice (connect EP47 + EP48 themes)
```

## Error Handling

<AccordionGroup>
  <Accordion title="Long podcast episodes">Deepgram handles files up to 2 GB. Set `timeout=180` for episodes over 60 minutes. Process batches sequentially with 2-second delays.</Accordion>
  <Accordion title="Topic detection returns few results">Topic detection needs 5+ minutes of diverse content. Monologue-heavy episodes may return 1-2 topics. Supplement with Mavera analysis of the raw transcript.</Accordion>
  <Accordion title="Diarization accuracy">For interviews with clear turn-taking, accuracy is 95%+. For panels with crosstalk, process each microphone track separately.</Accordion>
</AccordionGroup>
