MCPcopy Create free account
hub / github.com/debpalash/VoiceStudio / scriptStats

Function scriptStats

frontend/src/utils/audiobookScript.js:59–69  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

57 * and an estimated runtime in seconds at {@link AUDIOBOOK_WPM}.
58 */
59export function scriptStats(text) {
60 const norm = (text || '').replace(/\r\n?/g, '\n');
61 const headings = norm.match(new RegExp(HEADING_RE.source, HEADING_RE.flags)) || [];
62 // Spoken words only: drop `# heading` lines (titles aren't narrated as body,
63 // mirroring the parser) AND bracket markup, then whitespace-split.
64 const spoken = stripMarkup(norm.replace(new RegExp(HEADING_RE.source, HEADING_RE.flags), ' '));
65 const words = spoken.split(/\s+/).filter(Boolean).length;
66 const chapters = Math.max(1, headings.length);
67 const runtimeSec = words > 0 ? (words / AUDIOBOOK_WPM) * 60 : 0;
68 return { chapters, words, runtimeSec };
69}
70
71/** Format seconds as a clock string: `H:MM` (≥1h) or `M:SS` (<1h). Pure. */
72export function formatRuntimeClock(sec) {

Callers 2

StatsBarFunction · 0.90

Calls 3

stripMarkupFunction · 0.85
replaceMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected