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

Function extractTranscript

packages/studio/src/captions/parser.ts:107–126  ·  view source on GitHub ↗
(source: string)

Source from the content-addressed store, hash-verified

105 * Returns an empty array if no transcript is found or if parsing fails.
106 */
107export function extractTranscript(source: string): TranscriptWord[] {
108 // Match: (const|let|var) (TRANSCRIPT|script) = [...]
109 // The array may span multiple lines and contain trailing commas.
110 // The lazy [\s\S]*? anchors on the first `];` — assumes transcript word
111 // text never contains a literal `];` string (safe for speech transcripts).
112 const varPattern = /(?:const|let|var)\s+(?:TRANSCRIPT|script)\s*=\s*(\[[\s\S]*?\]);/;
113 const match = source.match(varPattern);
114
115 if (!match) {
116 return [];
117 }
118
119 const arrayLiteral = match[1];
120
121 try {
122 return parseTranscriptArray(arrayLiteral);
123 } catch {
124 return [];
125 }
126}
127
128/**
129 * Parses a caption composition from a live iframe DOM, extracting the transcript

Callers 2

parser.test.tsFile · 0.90
parseCaptionCompositionFunction · 0.85

Calls 1

parseTranscriptArrayFunction · 0.85

Tested by

no test coverage detected