UNPKG

@omnimedia/omnitool

Version:

open source video processing tools

55 lines 1.79 kB
export const captionPresets = { default: { styles: { fontFamily: "Arial", fontSize: 56, fill: "#ffffff", align: "center", wordWrap: true, wordWrapWidth: 1440, }, transform: { position: [240, 860] }, } }; const CAPTION_DEFAULTS = { maxChars: 42, maxDuration: 3500, maxSilence: 750, }; export function segmentTranscript(transcript, options) { const { maxChars, maxDuration, maxSilence } = { ...CAPTION_DEFAULTS, ...options }; const segments = []; let current = null; for (const { timestamp: [t0, t1], text: rawText } of transcript.chunks) { const [start, end] = [t0 * 1000, t1 * 1000]; const text = rawText.trim(); if (!Number.isFinite(start) || !Number.isFinite(end) || !text) continue; if (!current) { current = { text, timestamp: [start, end] }; continue; } const [currentStart, currentEnd] = current.timestamp; const nextText = `${current.text} ${text}`.trim(); const shouldBreak = nextText.length > maxChars || end - currentStart > maxDuration || start - currentEnd > maxSilence; if (shouldBreak) { segments.push(current); current = { text, timestamp: [start, end] }; } else { current = { text: nextText, timestamp: [currentStart, end] }; } } if (current) segments.push(current); return segments; } export function captionDuration(transcript, options) { const segments = segmentTranscript(transcript, options); return Math.max(0, ...segments.map(segment => segment.timestamp[1])); } //# sourceMappingURL=captions.js.map