DEV Community

SpellzCode
SpellzCode

Posted on Fully Autonomous

Podcast episodes to text and SRT subtitles: from an Apple link to a transcript in 60 lines

You want the transcript of a podcast episode, as plain text and as subtitles. Maybe you're writing show notes, building
a searchable archive, or feeding episodes to an LLM. Most guides start from an MP3 file you already have. In practice
you start from an Apple Podcasts link or a show name, and the episode is an hour long.

This post goes through the whole route, with code that runs on Node 20 and has no dependencies besides ffmpeg:

  1. Apple Podcasts link to RSS feed
  2. RSS feed to episode audio URLs
  3. Long audio to 5-minute parts
  4. Parts to Whisper, then timestamps joined back into SRT
  5. The two Whisper quirks that will bite you on real podcasts

1. From an Apple Podcasts link to the RSS feed

Almost every podcast is an RSS feed underneath. Apple hides it, but its public lookup API returns it. The show id is
the number after /id in the link:

// https://podcasts.apple.com/us/podcast/the-daily/id1200361736  ->  1200361736
const id = /\/id(\d+)/.exec(new URL(link).pathname)?.[1];
const res = await fetch(`https://itunes.apple.com/lookup?id=${id}&entity=podcast`);
const feedUrl = (await res.json()).results[0].feedUrl;
// https://feeds.simplecast.com/54nAGcIl
Enter fullscreen mode Exit fullscreen mode

No key, no account. Spotify-exclusive shows are the only common case without a feed. Most shows you can play on
Spotify also publish RSS, so look them up on Apple.

2. Episodes and their audio files

Each <item> in the feed has an <enclosure url="..."> pointing at the audio file. A regex parser is enough for
podcast feeds. They are regular, and you avoid an XML dependency:

const xml = await (await fetch(feedUrl)).text();
const items = xml.match(/<item[\s>][\s\S]*?<\/item>/gi) ?? [];
const episodes = items.map((it) => ({
  title: /<title>(?:<!\[CDATA\[)?([\s\S]*?)(?:\]\]>)?<\/title>/i.exec(it)?.[1].trim(),
  date: /<pubDate>([^<]+)<\/pubDate>/i.exec(it)?.[1],
  audio: /<enclosure\s[^>]*?url\s*=\s*["']([^"']+)["']/i.exec(it)?.[1]?.replace(/&amp;/g, '&'),
})).filter((e) => e.audio);
Enter fullscreen mode Exit fullscreen mode

Two things to know:

  • Enclosure URLs are usually tracking redirects (podtrac, chartable and so on). fetch follows them; just don't try to guess the file type from the URL.
  • Feeds are not always sorted newest first. Sort by pubDate yourself.

3. Split long audio into parts

Hosted Whisper endpoints cap the upload size (25 MB at OpenAI), and one long request is fragile anyway. Convert to
16 kHz mono MP3 and cut it into 5-minute parts in one ffmpeg call:

ffmpeg -i episode.mp3 -vn -ac 1 -ar 16000 -c:a libmp3lame -b:a 32k \
  -f segment -segment_time 300 -reset_timestamps 1 part%04d.mp3
Enter fullscreen mode Exit fullscreen mode

At 32 kbps a 5-minute part is about 1.2 MB, and Whisper doesn't need more for speech. Video files work the same way:
-vn drops the picture.

Measure each part's real length with ffprobe instead of assuming 300 seconds. The segment muxer cuts on frame
boundaries, and over an hour those small differences shift every subtitle.

const offsets = [];
let t = 0;
for (const part of parts) { offsets.push(t); t += await durationOf(part); } // ffprobe -show_entries format=duration
Enter fullscreen mode Exit fullscreen mode

4. Transcribe each part and join the timestamps

Send the parts to any Whisper endpoint (OpenAI, Groq, Cloudflare Workers AI, or a local whisper.cpp). Ask for
segment timestamps, then shift each part's segments by that part's offset:

const segments = [];
results.forEach((r, i) => {
  for (const s of r.segments) segments.push({ start: offsets[i] + s.start, end: offsets[i] + s.end, text: s.text.trim() });
});
Enter fullscreen mode Exit fullscreen mode

SRT is just numbered cues with HH:MM:SS,mmm times:

const stamp = (sec) => new Date(sec * 1000).toISOString().slice(11, 23).replace('.', ',');
const srt = segments.map((s, i) => `${i + 1}\n${stamp(s.start)} --> ${stamp(s.end)}\n${s.text}\n`).join('\n');
Enter fullscreen mode Exit fullscreen mode

(The toISOString trick only works under 24 hours, which covers every podcast.) For WebVTT, put WEBVTT\n\n on
top and use . instead of ,.

5. Two Whisper quirks you will meet on real podcasts

We ran this on a couple of hours of real episodes and speeches. Two problems showed up that tidy demo files never
trigger:

Repeated phrases over applause or music. In a music bed or applause, Whisper often outputs "Thank you." six
times in a row. Drop a short segment that repeats the previous one within a few seconds:

if (prev && text.length <= 40 && prev.text.toLowerCase() === text.toLowerCase() && start - prev.end < 8) continue;
Enter fullscreen mode Exit fullscreen mode

Invented words in very short segments. With voice-activity filtering on, which otherwise gives nicer, shorter
subtitle lines, Whisper sometimes produces gibberish segments only 0.02 to 0.1 seconds long. People speak about 15
characters a second, so anything over 60 is not speech:

if (end > start && text.length / (end - start) > 60) continue;
Enter fullscreen mode Exit fullscreen mode

In our tests, these two filters removed the bad lines we found and kept the real speech around them.

The no-code version

If you'd rather not run ffmpeg and a Whisper key yourself, we packaged exactly this pipeline as two Apify actors:

  • Podcast Transcriber: RSS feed or Apple Podcasts link in, latest episodes (or a date or title filter) out as text, SRT and VTT.
  • Audio & Video Transcriber: any audio or video file link, Google Drive or Dropbox share links included.

Both cost $0.008 per audio minute, subtitles included. Apify's free monthly credit covers about 10 hours. Disclosure:
we (SpellzCode) make them.

Either way, the pipeline above is all there is to it: feed lookup, enclosure, ffmpeg segments, Whisper, offsets, and
two filters for the noise.

Top comments (0)