Back to blog

Transcripts · Language learning · API

YouTube Transcripts for a Shadowing or Read-Along App: What the API Gives You and What You Fix Yourself

We fetched the captions of a BBC Learning English episode and two Spanish learner videos, turned them into one sentence per line, and replayed single sentences in YouTube's player. The problems in raw captions, the code that fixes them, and how five transcript APIs compare for this use.

· 7 min read · YTAPI

A shadowing or read-along app needs four things from a YouTube transcript API: caption lines with start and end times, a choice of caption language, one sentence per line, and a plan for videos that have no captions. None of the APIs we looked at, ours included, documents a one-sentence-per-line output for YouTube captions. They return YouTube's caption lines, so you join them yourself. The code for that is below, about 40 lines. If many of your videos have no captions at all, pick a service that can make a transcript from the audio, such as Supadata or YouTubeTranscript.dev. YTAPI and TranscriptAPI return only the captions YouTube already has.

We make YTAPI, so read the comparison with that in mind. We ran YTAPI ourselves. For the other services we used their own pricing and documentation pages, read on November 19, 2026 and checked again on November 22, and did not create accounts.

What we tested

On November 19, 2026 we fetched three videos that a language learner might pick, using the YTAPI API with format=segments:

VideoCaptionsCaption linesLines that overlap the nextSentences after our fix
Is our health being affected by microplastics?, BBC Learning English, 6:29English (en-GB), uploaded by the creator107063
Beginner Spanish Story: "The Chocolate Cake", Dreaming Spanish, 8:19Spanish, auto-generated14413767
Why Do Spanish Speakers Call Americans "GRINGOS"?, Dreaming Spanish, 8:57Spanish, auto-generated, no punctuation129123126 (no sentences to join)

Each video has only one caption track, which the free basic-info call showed before we spent anything. Each transcript call returned HTTP 200 in 2.7 to 4.6 seconds from our test machine. The whole test, with two searches to pick the videos and some repeat calls in other formats, used 13 credits.

Three problems in raw captions

1. Creator captions are cut for the screen, not by sentence. BBC's captions are clean and punctuated, but a line holds what fits on screen. 78 of the 107 lines contain a line break, and sentences run across lines:

{ "text": "It's cheap,\neasy to shape and long lasting,", "start": 15.92, "end": 19.32 },
{ "text": "but that's not always a good thing.", "start": 19.32, "end": 21.8 }

For shadowing, the learner should hear and repeat the whole sentence, so these two lines become one.

2. Auto-generated captions overlap. YouTube shows auto-captions as a rolling display: each line stays on screen while the next one appears. In the API data that means each line's end time is later than the next line's start. In the chocolate cake story, 137 of 144 lines overlap:

{ "text": "Hola.", "start": 7.16, "end": 10.599 },
{ "text": "Hola.", "start": 8.679, "end": 13.24 },
{ "text": "¿Qué quieres?", "start": 10.599, "end": 18.08 }

If you highlight "the line that contains the current time", two or three lines light up at once. For read-along, a line should end where the next one starts.

3. Some auto-captions have no punctuation. The second Dreaming Spanish video came back with none at all: mm seguro que esa es, gringa Hola a todos Yo soy shell y. Note also that the word "gringa" at the start of a line belongs to the sentence before it. You can't find sentence ends in text like this, so for such a track the best you can do is keep YouTube's own lines. That video also has [Música] lines, which a read-along list should drop.

Auto-captions also carry word timings. With word_level=true, 119 of the 144 lines in the chocolate cake story had a start and end time for each word, which is what you need to highlight word by word. The words don't show pauses, though: each word ends when the next one starts, and the last word of a line runs to the end of the line. Creator captions, like BBC's, have no word timings.

The fix: one sentence per line, no overlaps

This function takes the API response and returns read-along lines. It drops sound tags, cuts each line off where the next one starts, and joins lines until a sentence ends. A long pause or 25 words also ends a line, so a missing full stop can't swallow a whole paragraph. If the track has no sentence punctuation at all, it keeps YouTube's lines as they are.

// lines.mjs: turn a YTAPI transcript (format=segments) into read-along lines.
const SENTENCE_END = /[.?!…。?!]["”’')\]]*$/;

export function toLines(transcript, { maxWords = 25, maxGap = 1.5 } = {}) {
  const segs = transcript.segments
    .map((s) => ({ ...s, text: s.text.replace(/\s+/g, " ").trim() }))
    .filter((s) => s.text && !/^\[[^\]]*\]$/.test(s.text)) // drop [Music], [Applause]
    .sort((a, b) => a.start - b.start);

  // Auto-captions roll: each one stays on screen until the one after next appears.
  // For read-along, a caption ends when the next one starts.
  segs.forEach((s, i) => {
    const next = segs[i + 1];
    if (next && s.end > next.start) s.end = Math.max(next.start, s.start);
  });

  // Captions without any end punctuation can't be joined into sentences.
  const punctuated = segs.some((s) => SENTENCE_END.test(s.text));

  const lines = [];
  let cur = null;
  segs.forEach((s, i) => {
    const next = segs[i + 1];
    cur ??= { start: s.start, end: s.end, text: "", words: [] };
    cur.text = cur.text ? `${cur.text} ${s.text}` : s.text;
    cur.end = s.end;
    cur.words.push(...(s.words ?? []).map((w) => ({ ...w, end: Math.min(w.end, s.end) })));
    const done =
      !next ||
      !punctuated ||
      SENTENCE_END.test(s.text) ||
      next.start - s.end > maxGap ||
      cur.text.split(" ").length >= maxWords;
    if (done) {
      lines.push(cur);
      cur = null;
    }
  });
  return lines;
}

On our three videos it gave the counts in the table above, with no overlapping lines left. The BBC episode went from 107 caption lines to 63 lines, and 61 of those end with a full stop, question mark or exclamation mark. The other two ran past 25 words and were cut at the end of a caption line, after a comma. The start of the result:

0.12–0.90   Hi Becca.
0.90–1.68   Hi Phil.
1.68–4.00   Becca, I've got a question for you.
4.00–7.08   What's the last plastic thing you had in your hands?
7.08–11.76  Well, I just did my makeup, so probably a makeup brush.
11.76–15.92 Many of us own lots of things made of plastic.
15.92–21.80 It's cheap, easy to shape and long lasting, but that's not always a good thing.

The chocolate cake story went from 144 overlapping lines to 67 lines, starting Hola., Hola., ¿Qué quieres?, with the word timings kept in words for each line. The function does not correct the words themselves, so any mistake in the auto-captions stays in the line.

Playing one sentence at a time

The page below shows the lines next to YouTube's embedded player, highlights the current line, and plays a single sentence when the learner clicks it, then pauses so they can repeat it. It uses the YouTube IFrame Player API. Fetch the transcript from your own backend, so your API key never reaches the browser.

<style>
  li { cursor: pointer; }
  li.on { background: #fff3b0; font-weight: 600; }
</style>
<div id="player"></div>
<ol id="lines"></ol>
<script type="module">
import { toLines } from "./lines.mjs";

const VIDEO_ID = "oHxs1dCUXlI";
// Your backend calls GET https://api.ytapi.dev/v1/transcripts?video_id=...&format=segments
const transcript = await (await fetch(`/api/transcript?video_id=${VIDEO_ID}`)).json();
const lines = toLines(transcript);

const list = document.getElementById("lines");
lines.forEach((line, i) => {
  const li = document.createElement("li");
  li.textContent = line.text;
  li.onclick = () => playLine(i);
  list.append(li);
});

let player;
let current = -1;
let stopAt = null;
let pinned = null; // the line being repeated stays highlighted

function playLine(i) {
  stopAt = lines[i].end; // play one sentence, then pause for the learner to repeat it
  pinned = i;
  player.seekTo(lines[i].start, true);
  player.playVideo();
}

function tick() {
  const t = player.getCurrentTime();
  if (stopAt !== null && t >= stopAt) {
    player.pauseVideo();
    stopAt = null;
  }
  const i = pinned ?? lines.findIndex((l) => t >= l.start && t < l.end);
  if (i !== current) {
    list.children[current]?.classList.remove("on");
    list.children[i]?.classList.add("on");
    current = i;
  }
  requestAnimationFrame(tick);
}

window.onYouTubeIframeAPIReady = () => {
  player = new YT.Player("player", {
    videoId: VIDEO_ID,
    events: {
      onReady: tick,
      // The learner pressed play on the video itself: follow the video again.
      onStateChange: (e) => {
        if (e.data === YT.PlayerState.PLAYING && stopAt === null) pinned = null;
      },
    },
  });
};
const api = document.createElement("script");
api.src = "https://www.youtube.com/iframe_api";
document.head.append(api);
</script>

We ran this page in a browser with the BBC episode, loading the transcript from a saved file instead of a backend. Clicking the line "It's cheap, easy to shape and long lasting, but that's not always a good thing." started the video at 15.92 seconds and paused it at 21.81 seconds, against a line end of 21.80. The caption YouTube showed in the player at that moment was the end of the same sentence. Our first version highlighted the next line once it paused, because the pause lands a few hundredths of a second past the line end. That is why the code keeps the replayed line highlighted.

Choosing a transcript API for this

What each service says it returns, from its own pages on November 19, 2026 (prices checked again on November 22). We ran only YTAPI.

ServiceWhat you get per lineVideos without captionsFree to startPaid entry point
YTAPItext, start, end in seconds; word times on auto-captions with word_level=true; which track (creator or auto)No transcript; the call returns 404 and costs nothing200 credits on sign-up$9 for 2,000 credits, no expiry
Supadatatext, offset and duration in milliseconds; a chunkSize option that sets the maximum characters per chunkmode=auto or generate makes one with AI, 2 credits per minute100 credits a monthBasic $5/month billed annually (300 credits); Pro $17/month (3,000)
TranscriptAPItext, start, durationWe found no speech-to-text option on its home or pricing page100 credits, no card$5/month for 1,000 credits, or $54/year
YouTubeTranscript.devSegments with start and end in milliseconds; paragraphs; word times on its own AI transcriptsmode=auto falls back to AI speech-to-text, 1 credit per 2 minutesFree sign-up$9/month for 1,200 credits, or $99 once for 9,900 that don't expire
youtube-transcript-api (open-source Python library)text, start, durationNoFree, MIT licenceNone; its README says YouTube blocks most cloud server IPs and suggests rotating residential proxies

Whichever you pick, the three problems above come from YouTube's captions, not from the API, so expect to need something like toLines with any of them. What differs is what's around it:

  • Many videos without captions (vlogs, short clips, smaller channels): an AI fallback saves you building your own speech-to-text. Supadata and YouTubeTranscript.dev both offer one, at a per-minute price.
  • Mostly captioned learning content (BBC Learning English, TED, most teaching channels): any of the hosted APIs will do. Compare price per thousand videos and whether credits expire.
  • A prototype on your own computer: youtube-transcript-api is free and works until YouTube blocks the IP you run it from.

Things to know before you build

  • Pick the language explicitly. YTAPI's languages=en matched the BBC's en-GB track. With track_policy=exact_only, en did not match it and the call returned 404 with no charge. Each response says which language and which kind of track you got (track_kind: manual or asr), so you can label auto-captions in your app.
  • Auto-caption mistakes are learning mistakes. A learner who shadows a misheard word repeats it. Prefer videos with creator captions where you can, and mark auto-captions as such.
  • Cache transcripts on your side. Captions for a published video rarely change, and YTAPI charges a credit for every call, including repeat calls for the same video. Fetch once per video and store the result.
  • Play the video through YouTube's player. The captions belong to the people who made the videos. Show them alongside the embedded video, as above, and ask the creator before republishing a transcript somewhere else.

FAQ

Does a YouTube transcript API return sentences?

None of the services we looked at documents that for YouTube captions. They return YouTube's caption lines, which follow what fits on screen. Join them on sentence punctuation yourself, as in the code above. That works only when the captions are punctuated.

Why do auto-generated caption times overlap?

YouTube shows auto-captions as a rolling display, so each line is timed to stay on screen while the next one appears. Use the next line's start as the end of the current one.

Can I get word-by-word timing for karaoke-style highlighting?

On auto-generated captions, yes: YTAPI returns word times with word_level=true, and YouTubeTranscript.dev returns them on its own AI transcripts. Creator-uploaded captions usually have line timings only.

What does it cost to run this for a learning app?

With YTAPI, one credit per video if you cache the result, so the $9 pack covers 2,000 videos. Videos without captions are free and return no transcript. See the table above for the other services' prices.