Skip to content

fix: count array-shaped section content in slideshow duration estimate - #61

Closed
sx4im wants to merge 1 commit into
darkzOGx:masterfrom
sx4im:fix/slideshow-narration-truncation
Closed

sx4im wants to merge 1 commit into
darkzOGx:masterfrom
sx4im:fix/slideshow-narration-truncation

Conversation

@sx4im

@sx4im sx4im commented Sep 27, 2026 •

Copy link
Copy Markdown

What was broken (root cause)

With VIDEO_PROVIDER=slideshow, generateSlideshowVideo() sizes the video track from calculateScriptDuration(script) — a 150-wpm word-count estimate. calculateScriptDuration only counted section.content when it was a string, but the template-mode sections produced by generateExplanation / generateExamples / generateProblemSection in agents/script-writer-agent.js return content: [...] (array of strings). Those words were silently skipped, so the estimate could undershoot the real narration by a large margin (issue reports 42.5s estimated vs 143.5s of real TTS). addAudioToVideo muxes with ffmpeg -shortest, so the narration tail was dropped mid-sentence with no error or warning.

What changed

  • utils/ai-video-generator.js: added a countWords(value) helper that recurses into arrays (string counting behavior is byte-for-byte unchanged) and used it for section.content in calculateScriptDuration.
  • test.js: added a regression test to testOpenIssueRegressions asserting array-shaped content is counted (and string-shaped content behaves exactly as before).

Fixes #57

How it was tested

  • New regression test failed before the fix (calculateScriptDuration ignored array section content: got 30s, expected at least 41s) and passes after.
  • Full suite: npm test — 46 passed, 0 failed.
  • npm run lint — clean.

Sections from generateExplanation/generateExamples/generateProblemSection use
content: [...] (array of strings), which calculateScriptDuration silently
skipped. The rendered video track could then be far shorter than the real
narration, and ffmpeg -shortest truncated the audio mid-sentence with no
warning. Adds a countWords helper that recurses into arrays (string behavior
unchanged) and a regression test in testOpenIssueRegressions.

Fixes #57
@sx4im sx4im closed this Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slideshow video provider truncates narration mid-sentence when the word-count duration estimate undershoots the real audio

1 participant