MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / parseVtt

Function parseVtt

packages/cli/src/whisper/normalize.ts:217–246  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

215}
216
217function parseVtt(content: string): Word[] {
218 // Strip the WEBVTT header and any metadata blocks
219 const body = content.replace(/^WEBVTT[^\n]*\n/, "").replace(/^[A-Z-]+:.*\n/gm, "");
220 // VTT is structurally similar to SRT (without numeric indices)
221 const blocks = body.trim().split(/\n\n+/);
222 const words: Word[] = [];
223
224 for (const block of blocks) {
225 const lines = block.trim().split("\n");
226 const timeLine = lines.find((l) => l.includes("-->"));
227 if (!timeLine) continue;
228
229 const [startStr, endStr] = timeLine.split("-->").map((s) => s.trim());
230 if (!startStr || !endStr) continue;
231
232 const text = lines
233 .slice(lines.indexOf(timeLine) + 1)
234 .join(" ")
235 .replace(/<[^>]+>/g, "") // strip HTML tags
236 .trim();
237 if (!text) continue;
238
239 words.push({
240 text,
241 start: parseVttTimestamp(startStr),
242 end: parseVttTimestamp(endStr),
243 });
244 }
245 return words;
246}
247
248// ---------------------------------------------------------------------------
249// Timestamp helpers

Callers 1

loadTranscriptFunction · 0.85

Calls 2

parseVttTimestampFunction · 0.85
findMethod · 0.65

Tested by

no test coverage detected