mergestory 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +48 -2
- package/assets/kokoro-plugin/package-lock.json +1139 -0
- package/dist/analyzer/analyze.d.ts +8 -0
- package/dist/analyzer/analyze.js +328 -0
- package/dist/analyzer/components.d.ts +18 -0
- package/dist/analyzer/components.js +266 -0
- package/dist/analyzer/dependencies.d.ts +13 -0
- package/dist/analyzer/dependencies.js +349 -0
- package/dist/analyzer/evidence.d.ts +15 -0
- package/dist/analyzer/evidence.js +73 -0
- package/dist/analyzer/hunks.d.ts +21 -0
- package/dist/analyzer/hunks.js +88 -0
- package/dist/analyzer/imports.d.ts +46 -0
- package/dist/analyzer/imports.js +87 -0
- package/dist/analyzer/index.d.ts +14 -0
- package/dist/analyzer/index.js +16 -0
- package/dist/analyzer/languages/go.d.ts +2 -0
- package/dist/analyzer/languages/go.js +76 -0
- package/dist/analyzer/languages/index.d.ts +18 -0
- package/dist/analyzer/languages/index.js +72 -0
- package/dist/analyzer/languages/javascript.d.ts +2 -0
- package/dist/analyzer/languages/javascript.js +336 -0
- package/dist/analyzer/languages/jvm.d.ts +2 -0
- package/dist/analyzer/languages/jvm.js +157 -0
- package/dist/analyzer/languages/others.d.ts +2 -0
- package/dist/analyzer/languages/others.js +40 -0
- package/dist/analyzer/languages/php.d.ts +2 -0
- package/dist/analyzer/languages/php.js +81 -0
- package/dist/analyzer/languages/python.d.ts +2 -0
- package/dist/analyzer/languages/python.js +180 -0
- package/dist/analyzer/languages/ruby.d.ts +2 -0
- package/dist/analyzer/languages/ruby.js +99 -0
- package/dist/analyzer/languages/rust.d.ts +2 -0
- package/dist/analyzer/languages/rust.js +164 -0
- package/dist/analyzer/languages/shared.d.ts +35 -0
- package/dist/analyzer/languages/shared.js +43 -0
- package/dist/analyzer/languages/types.d.ts +78 -0
- package/dist/analyzer/languages/types.js +2 -0
- package/dist/analyzer/pack-format.d.ts +27 -0
- package/dist/analyzer/pack-format.js +139 -0
- package/dist/analyzer/pack.d.ts +26 -0
- package/dist/analyzer/pack.js +498 -0
- package/dist/analyzer/relationships.d.ts +17 -0
- package/dist/analyzer/relationships.js +34 -0
- package/dist/analyzer/risk-rules.d.ts +287 -0
- package/dist/analyzer/risk-rules.js +373 -0
- package/dist/analyzer/risks.d.ts +36 -0
- package/dist/analyzer/risks.js +480 -0
- package/dist/analyzer/roles.d.ts +11 -0
- package/dist/analyzer/roles.js +280 -0
- package/dist/analyzer/scan.d.ts +26 -0
- package/dist/analyzer/scan.js +157 -0
- package/dist/analyzer/signals.d.ts +20 -0
- package/dist/analyzer/signals.js +51 -0
- package/dist/analyzer/symbol-changes.d.ts +11 -0
- package/dist/analyzer/symbol-changes.js +101 -0
- package/dist/analyzer/symbol-types.d.ts +17 -0
- package/dist/analyzer/symbol-types.js +9 -0
- package/dist/analyzer/symbols.d.ts +4 -0
- package/dist/analyzer/symbols.js +16 -0
- package/dist/analyzer/trivial.d.ts +13 -0
- package/dist/analyzer/trivial.js +137 -0
- package/dist/analyzer/util.d.ts +6 -0
- package/dist/analyzer/util.js +24 -0
- package/dist/cli/commands/authoring.d.ts +9 -0
- package/dist/cli/commands/authoring.js +98 -0
- package/dist/cli/commands/cache.d.ts +4 -0
- package/dist/cli/commands/cache.js +37 -0
- package/dist/cli/commands/doctor.d.ts +5 -0
- package/dist/cli/commands/doctor.js +37 -0
- package/dist/cli/commands/generate.d.ts +8 -0
- package/dist/cli/commands/generate.js +69 -0
- package/dist/cli/commands/jobs.d.ts +8 -0
- package/dist/cli/commands/jobs.js +70 -0
- package/dist/cli/commands/publish.d.ts +8 -0
- package/dist/cli/commands/publish.js +120 -0
- package/dist/cli/commands/serve.d.ts +4 -0
- package/dist/cli/commands/serve.js +69 -0
- package/dist/cli/commands/setup.d.ts +14 -0
- package/dist/cli/commands/setup.js +108 -0
- package/dist/cli/commands/shared.d.ts +18 -0
- package/dist/cli/commands/shared.js +24 -0
- package/dist/cli/files.d.ts +26 -0
- package/dist/cli/files.js +98 -0
- package/dist/cli/format.d.ts +55 -0
- package/dist/cli/format.js +295 -0
- package/dist/cli/inputs.d.ts +23 -0
- package/dist/cli/inputs.js +96 -0
- package/dist/cli/io.d.ts +19 -0
- package/dist/cli/io.js +31 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +15 -0
- package/dist/cli/options.d.ts +105 -0
- package/dist/cli/options.js +324 -0
- package/dist/cli/program.d.ts +12 -0
- package/dist/cli/program.js +146 -0
- package/dist/cli/runtime.d.ts +59 -0
- package/dist/cli/runtime.js +83 -0
- package/dist/cli/style.d.ts +13 -0
- package/dist/cli/style.js +27 -0
- package/dist/core/binaries.d.ts +7 -0
- package/dist/core/binaries.js +33 -0
- package/dist/core/binary-paths.d.ts +5 -0
- package/dist/core/binary-paths.js +92 -0
- package/dist/core/cache.d.ts +14 -0
- package/dist/core/cache.js +43 -0
- package/dist/core/child-env.d.ts +9 -0
- package/dist/core/child-env.js +61 -0
- package/dist/core/concurrency.d.ts +13 -0
- package/dist/core/concurrency.js +58 -0
- package/dist/core/config.d.ts +223 -0
- package/dist/core/config.js +454 -0
- package/dist/core/context.d.ts +39 -0
- package/dist/core/context.js +44 -0
- package/dist/core/cost.d.ts +46 -0
- package/dist/core/cost.js +108 -0
- package/dist/core/diagram-metrics.d.ts +57 -0
- package/dist/core/diagram-metrics.js +63 -0
- package/dist/core/diff-view.d.ts +44 -0
- package/dist/core/diff-view.js +136 -0
- package/dist/core/errors.d.ts +47 -0
- package/dist/core/errors.js +94 -0
- package/dist/core/ids.d.ts +11 -0
- package/dist/core/ids.js +36 -0
- package/dist/core/json.d.ts +8 -0
- package/dist/core/json.js +17 -0
- package/dist/core/languages.d.ts +19 -0
- package/dist/core/languages.js +292 -0
- package/dist/core/logger.d.ts +29 -0
- package/dist/core/logger.js +68 -0
- package/dist/core/net.d.ts +16 -0
- package/dist/core/net.js +80 -0
- package/dist/core/path-policy.d.ts +20 -0
- package/dist/core/path-policy.js +202 -0
- package/dist/core/paths.d.ts +18 -0
- package/dist/core/paths.js +53 -0
- package/dist/core/posix.d.ts +12 -0
- package/dist/core/posix.js +50 -0
- package/dist/core/process.d.ts +22 -0
- package/dist/core/process.js +117 -0
- package/dist/core/providers.d.ts +204 -0
- package/dist/core/providers.js +2 -0
- package/dist/core/redact.d.ts +11 -0
- package/dist/core/redact.js +70 -0
- package/dist/core/render-plan.d.ts +307 -0
- package/dist/core/render-plan.js +7 -0
- package/dist/core/retry.d.ts +54 -0
- package/dist/core/retry.js +116 -0
- package/dist/core/run-folder.d.ts +74 -0
- package/dist/core/run-folder.js +129 -0
- package/dist/core/secrets.d.ts +56 -0
- package/dist/core/secrets.js +301 -0
- package/dist/core/storyboard-facts.d.ts +22 -0
- package/dist/core/storyboard-facts.js +61 -0
- package/dist/core/storyboard-schema.d.ts +1279 -0
- package/dist/core/storyboard-schema.js +342 -0
- package/dist/core/text.d.ts +43 -0
- package/dist/core/text.js +94 -0
- package/dist/core/types.d.ts +459 -0
- package/dist/core/types.js +17 -0
- package/dist/doctor/check.d.ts +6 -0
- package/dist/doctor/check.js +18 -0
- package/dist/doctor/deps.d.ts +2 -0
- package/dist/doctor/deps.js +90 -0
- package/dist/doctor/format.d.ts +9 -0
- package/dist/doctor/format.js +19 -0
- package/dist/doctor/github.d.ts +2 -0
- package/dist/doctor/github.js +13 -0
- package/dist/doctor/home.d.ts +2 -0
- package/dist/doctor/home.js +26 -0
- package/dist/doctor/index.d.ts +18 -0
- package/dist/doctor/index.js +81 -0
- package/dist/doctor/llm.d.ts +2 -0
- package/dist/doctor/llm.js +32 -0
- package/dist/doctor/publish.d.ts +2 -0
- package/dist/doctor/publish.js +16 -0
- package/dist/doctor/s3.d.ts +2 -0
- package/dist/doctor/s3.js +125 -0
- package/dist/doctor/speech.d.ts +2 -0
- package/dist/doctor/speech.js +112 -0
- package/dist/doctor/tools.d.ts +5 -0
- package/dist/doctor/tools.js +58 -0
- package/dist/doctor/types.d.ts +92 -0
- package/dist/doctor/types.js +2 -0
- package/dist/doctor/youtube.d.ts +2 -0
- package/dist/doctor/youtube.js +73 -0
- package/dist/github/client.d.ts +108 -0
- package/dist/github/client.js +499 -0
- package/dist/github/errors.d.ts +37 -0
- package/dist/github/errors.js +155 -0
- package/dist/github/index.d.ts +13 -0
- package/dist/github/index.js +9 -0
- package/dist/github/linked-issues.d.ts +37 -0
- package/dist/github/linked-issues.js +131 -0
- package/dist/github/model.d.ts +81 -0
- package/dist/github/model.js +114 -0
- package/dist/github/notify.d.ts +27 -0
- package/dist/github/notify.js +118 -0
- package/dist/github/pr-url.d.ts +27 -0
- package/dist/github/pr-url.js +122 -0
- package/dist/github/token.d.ts +16 -0
- package/dist/github/token.js +69 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +19 -0
- package/dist/jobs/input-rules.d.ts +20 -0
- package/dist/jobs/input-rules.js +100 -0
- package/dist/jobs/model.d.ts +47 -0
- package/dist/jobs/model.js +18 -0
- package/dist/jobs/runner.d.ts +43 -0
- package/dist/jobs/runner.js +165 -0
- package/dist/jobs/store.d.ts +67 -0
- package/dist/jobs/store.js +314 -0
- package/dist/jobs/view.d.ts +48 -0
- package/dist/jobs/view.js +111 -0
- package/dist/jobs/worker.d.ts +24 -0
- package/dist/jobs/worker.js +47 -0
- package/dist/llm/anthropic.d.ts +11 -0
- package/dist/llm/anthropic.js +225 -0
- package/dist/llm/index.d.ts +10 -0
- package/dist/llm/index.js +27 -0
- package/dist/llm/openai-compatible.d.ts +33 -0
- package/dist/llm/openai-compatible.js +378 -0
- package/dist/llm/prices.d.ts +26 -0
- package/dist/llm/prices.js +41 -0
- package/dist/llm/shared.d.ts +30 -0
- package/dist/llm/shared.js +115 -0
- package/dist/narration/assemble.d.ts +36 -0
- package/dist/narration/assemble.js +282 -0
- package/dist/narration/audio.d.ts +61 -0
- package/dist/narration/audio.js +301 -0
- package/dist/narration/captions.d.ts +37 -0
- package/dist/narration/captions.js +195 -0
- package/dist/narration/chunking.d.ts +6 -0
- package/dist/narration/chunking.js +46 -0
- package/dist/narration/convert.d.ts +9 -0
- package/dist/narration/convert.js +90 -0
- package/dist/narration/elevenlabs.d.ts +5 -0
- package/dist/narration/elevenlabs.js +53 -0
- package/dist/narration/http-errors.d.ts +14 -0
- package/dist/narration/http-errors.js +74 -0
- package/dist/narration/index.d.ts +21 -0
- package/dist/narration/index.js +22 -0
- package/dist/narration/kokoro-install.d.ts +30 -0
- package/dist/narration/kokoro-install.js +284 -0
- package/dist/narration/kokoro-model.d.ts +54 -0
- package/dist/narration/kokoro-model.js +168 -0
- package/dist/narration/kokoro-plugin.d.ts +78 -0
- package/dist/narration/kokoro-plugin.js +245 -0
- package/dist/narration/kokoro.d.ts +22 -0
- package/dist/narration/kokoro.js +231 -0
- package/dist/narration/openai.d.ts +4 -0
- package/dist/narration/openai.js +54 -0
- package/dist/narration/pricing.d.ts +8 -0
- package/dist/narration/pricing.js +17 -0
- package/dist/narration/remote-speech.d.ts +53 -0
- package/dist/narration/remote-speech.js +100 -0
- package/dist/narration/say.d.ts +28 -0
- package/dist/narration/say.js +178 -0
- package/dist/narration/select.d.ts +27 -0
- package/dist/narration/select.js +80 -0
- package/dist/narration/silent.d.ts +2 -0
- package/dist/narration/silent.js +18 -0
- package/dist/narration/speakable.d.ts +20 -0
- package/dist/narration/speakable.js +398 -0
- package/dist/narration/synthesize.d.ts +25 -0
- package/dist/narration/synthesize.js +220 -0
- package/dist/narration/wav.d.ts +37 -0
- package/dist/narration/wav.js +170 -0
- package/dist/pipeline/authoring.d.ts +8 -0
- package/dist/pipeline/authoring.js +117 -0
- package/dist/pipeline/commands.d.ts +9 -0
- package/dist/pipeline/commands.js +21 -0
- package/dist/pipeline/fit-duration.d.ts +41 -0
- package/dist/pipeline/fit-duration.js +150 -0
- package/dist/pipeline/index.d.ts +9 -0
- package/dist/pipeline/index.js +9 -0
- package/dist/pipeline/inputs.d.ts +42 -0
- package/dist/pipeline/inputs.js +171 -0
- package/dist/pipeline/plan.d.ts +8 -0
- package/dist/pipeline/plan.js +85 -0
- package/dist/pipeline/planned-egress.d.ts +21 -0
- package/dist/pipeline/planned-egress.js +43 -0
- package/dist/pipeline/prepare.d.ts +26 -0
- package/dist/pipeline/prepare.js +84 -0
- package/dist/pipeline/presentation.d.ts +26 -0
- package/dist/pipeline/presentation.js +110 -0
- package/dist/pipeline/publish-run.d.ts +71 -0
- package/dist/pipeline/publish-run.js +295 -0
- package/dist/pipeline/run.d.ts +7 -0
- package/dist/pipeline/run.js +196 -0
- package/dist/pipeline/storyboard-choice.d.ts +34 -0
- package/dist/pipeline/storyboard-choice.js +129 -0
- package/dist/pipeline/types.d.ts +76 -0
- package/dist/pipeline/types.js +2 -0
- package/dist/publish/access-probe.d.ts +55 -0
- package/dist/publish/access-probe.js +249 -0
- package/dist/publish/bundle.d.ts +20 -0
- package/dist/publish/bundle.js +57 -0
- package/dist/publish/comment.d.ts +10 -0
- package/dist/publish/comment.js +184 -0
- package/dist/publish/content-types.d.ts +15 -0
- package/dist/publish/content-types.js +41 -0
- package/dist/publish/index.d.ts +18 -0
- package/dist/publish/index.js +30 -0
- package/dist/publish/keys.d.ts +10 -0
- package/dist/publish/keys.js +30 -0
- package/dist/publish/local.d.ts +33 -0
- package/dist/publish/local.js +143 -0
- package/dist/publish/privacy.d.ts +20 -0
- package/dist/publish/privacy.js +21 -0
- package/dist/publish/s3/bucket.d.ts +22 -0
- package/dist/publish/s3/bucket.js +82 -0
- package/dist/publish/s3/client.d.ts +33 -0
- package/dist/publish/s3/client.js +134 -0
- package/dist/publish/s3/failures.d.ts +22 -0
- package/dist/publish/s3/failures.js +110 -0
- package/dist/publish/s3/index.d.ts +5 -0
- package/dist/publish/s3/index.js +6 -0
- package/dist/publish/s3/links.d.ts +38 -0
- package/dist/publish/s3/links.js +60 -0
- package/dist/publish/s3/protected-links.d.ts +29 -0
- package/dist/publish/s3/protected-links.js +67 -0
- package/dist/publish/s3/publisher.d.ts +32 -0
- package/dist/publish/s3/publisher.js +123 -0
- package/dist/publish/s3/settings.d.ts +29 -0
- package/dist/publish/s3/settings.js +64 -0
- package/dist/publish/s3/upload.d.ts +29 -0
- package/dist/publish/s3/upload.js +145 -0
- package/dist/publish/severity.d.ts +9 -0
- package/dist/publish/severity.js +18 -0
- package/dist/publish/text.d.ts +23 -0
- package/dist/publish/text.js +94 -0
- package/dist/publish/types.d.ts +67 -0
- package/dist/publish/types.js +12 -0
- package/dist/publish/vtt.d.ts +9 -0
- package/dist/publish/vtt.js +43 -0
- package/dist/publish/watch-page.d.ts +4 -0
- package/dist/publish/watch-page.js +463 -0
- package/dist/publish/youtube/credentials.d.ts +33 -0
- package/dist/publish/youtube/credentials.js +162 -0
- package/dist/publish/youtube/description.d.ts +56 -0
- package/dist/publish/youtube/description.js +197 -0
- package/dist/publish/youtube/google-api.d.ts +95 -0
- package/dist/publish/youtube/google-api.js +339 -0
- package/dist/publish/youtube/index.d.ts +7 -0
- package/dist/publish/youtube/index.js +8 -0
- package/dist/publish/youtube/loopback.d.ts +13 -0
- package/dist/publish/youtube/loopback.js +144 -0
- package/dist/publish/youtube/oauth.d.ts +68 -0
- package/dist/publish/youtube/oauth.js +159 -0
- package/dist/publish/youtube/prompt.d.ts +27 -0
- package/dist/publish/youtube/prompt.js +94 -0
- package/dist/publish/youtube/publisher.d.ts +38 -0
- package/dist/publish/youtube/publisher.js +346 -0
- package/dist/publish/youtube/scopes.d.ts +32 -0
- package/dist/publish/youtube/scopes.js +55 -0
- package/dist/publish/youtube/sign-in.d.ts +37 -0
- package/dist/publish/youtube/sign-in.js +137 -0
- package/dist/publish/youtube/upload.d.ts +43 -0
- package/dist/publish/youtube/upload.js +210 -0
- package/dist/render/browser.d.ts +23 -0
- package/dist/render/browser.js +219 -0
- package/dist/render/chromium-renderer.d.ts +56 -0
- package/dist/render/chromium-renderer.js +519 -0
- package/dist/render/ffmpeg.d.ts +55 -0
- package/dist/render/ffmpeg.js +212 -0
- package/dist/render/fonts.d.ts +10 -0
- package/dist/render/fonts.js +42 -0
- package/dist/render/index.d.ts +9 -0
- package/dist/render/index.js +11 -0
- package/dist/render/page.d.ts +46 -0
- package/dist/render/page.js +123 -0
- package/dist/render/playwright.d.ts +3 -0
- package/dist/render/playwright.js +6 -0
- package/dist/render/runtime-bundle.d.ts +2 -0
- package/dist/render/runtime-bundle.js +72 -0
- package/dist/runtime/runtime.js +1626 -0
- package/dist/server/auth.d.ts +17 -0
- package/dist/server/auth.js +58 -0
- package/dist/server/http.d.ts +43 -0
- package/dist/server/http.js +119 -0
- package/dist/server/index.d.ts +46 -0
- package/dist/server/index.js +310 -0
- package/dist/server/queue.d.ts +30 -0
- package/dist/server/queue.js +76 -0
- package/dist/server/schema.d.ts +103 -0
- package/dist/server/schema.js +121 -0
- package/dist/server/source.d.ts +17 -0
- package/dist/server/source.js +100 -0
- package/dist/sources/assemble.d.ts +86 -0
- package/dist/sources/assemble.js +117 -0
- package/dist/sources/diff-parser.d.ts +14 -0
- package/dist/sources/diff-parser.js +84 -0
- package/dist/sources/git.d.ts +28 -0
- package/dist/sources/git.js +108 -0
- package/dist/sources/github.d.ts +20 -0
- package/dist/sources/github.js +192 -0
- package/dist/sources/hunk-selection.d.ts +25 -0
- package/dist/sources/hunk-selection.js +46 -0
- package/dist/sources/index.d.ts +23 -0
- package/dist/sources/index.js +62 -0
- package/dist/sources/limits.d.ts +27 -0
- package/dist/sources/limits.js +22 -0
- package/dist/sources/local.d.ts +34 -0
- package/dist/sources/local.js +555 -0
- package/dist/sources/reader.d.ts +13 -0
- package/dist/sources/reader.js +45 -0
- package/dist/sources/remote.d.ts +13 -0
- package/dist/sources/remote.js +41 -0
- package/dist/sources/repo-context.d.ts +34 -0
- package/dist/sources/repo-context.js +144 -0
- package/dist/sources/text.d.ts +25 -0
- package/dist/sources/text.js +71 -0
- package/dist/storyboard/authoring.d.ts +108 -0
- package/dist/storyboard/authoring.js +196 -0
- package/dist/storyboard/claims.d.ts +35 -0
- package/dist/storyboard/claims.js +318 -0
- package/dist/storyboard/coderef.d.ts +28 -0
- package/dist/storyboard/coderef.js +118 -0
- package/dist/storyboard/generate.d.ts +25 -0
- package/dist/storyboard/generate.js +194 -0
- package/dist/storyboard/heuristic-code.d.ts +91 -0
- package/dist/storyboard/heuristic-code.js +524 -0
- package/dist/storyboard/heuristic-context.d.ts +42 -0
- package/dist/storyboard/heuristic-context.js +102 -0
- package/dist/storyboard/heuristic-facts.d.ts +106 -0
- package/dist/storyboard/heuristic-facts.js +415 -0
- package/dist/storyboard/heuristic-overview.d.ts +4 -0
- package/dist/storyboard/heuristic-overview.js +151 -0
- package/dist/storyboard/heuristic-review.d.ts +10 -0
- package/dist/storyboard/heuristic-review.js +158 -0
- package/dist/storyboard/heuristic-scenes.d.ts +8 -0
- package/dist/storyboard/heuristic-scenes.js +357 -0
- package/dist/storyboard/heuristic-shared.d.ts +43 -0
- package/dist/storyboard/heuristic-shared.js +136 -0
- package/dist/storyboard/heuristic.d.ts +15 -0
- package/dist/storyboard/heuristic.js +324 -0
- package/dist/storyboard/identifiers.d.ts +51 -0
- package/dist/storyboard/identifiers.js +195 -0
- package/dist/storyboard/index.d.ts +10 -0
- package/dist/storyboard/index.js +10 -0
- package/dist/storyboard/prompts.d.ts +16 -0
- package/dist/storyboard/prompts.js +61 -0
- package/dist/storyboard/run.d.ts +82 -0
- package/dist/storyboard/run.js +332 -0
- package/dist/storyboard/text.d.ts +16 -0
- package/dist/storyboard/text.js +103 -0
- package/dist/storyboard/types.d.ts +47 -0
- package/dist/storyboard/types.js +2 -0
- package/dist/storyboard/urls.d.ts +15 -0
- package/dist/storyboard/urls.js +83 -0
- package/dist/storyboard/validate.d.ts +8 -0
- package/dist/storyboard/validate.js +525 -0
- package/dist/storyboard/visuals.d.ts +23 -0
- package/dist/storyboard/visuals.js +324 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +3 -0
- package/dist/visuals/code.d.ts +68 -0
- package/dist/visuals/code.js +385 -0
- package/dist/visuals/highlight.d.ts +17 -0
- package/dist/visuals/highlight.js +85 -0
- package/dist/visuals/image.d.ts +12 -0
- package/dist/visuals/image.js +96 -0
- package/dist/visuals/index.d.ts +10 -0
- package/dist/visuals/index.js +10 -0
- package/dist/visuals/layout.d.ts +89 -0
- package/dist/visuals/layout.js +506 -0
- package/dist/visuals/plan.d.ts +33 -0
- package/dist/visuals/plan.js +511 -0
- package/dist/visuals/timeline.d.ts +31 -0
- package/dist/visuals/timeline.js +96 -0
- package/package.json +74 -4
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The narration track: every clip placed at its beat start on one silent mono 48 kHz timeline,
|
|
3
|
+
* written as a single WAV. Optional background music is mixed in quietly and ducked while
|
|
4
|
+
* someone is speaking. The finished track is brought to a standard loudness (-16 LUFS with a true
|
|
5
|
+
* peak of at most -1.5 dBTP), which keeps the video as loud as other online video without
|
|
6
|
+
* clipping. Audio never leaves the machine.
|
|
7
|
+
*/
|
|
8
|
+
import { access, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
9
|
+
import { dirname, resolve } from 'node:path';
|
|
10
|
+
import { resolveFfmpeg } from '../core/binaries.js';
|
|
11
|
+
import { MergeStoryError } from '../core/errors.js';
|
|
12
|
+
import { runCommand } from '../core/process.js';
|
|
13
|
+
import { floatToInt16, resampleMono } from './audio.js';
|
|
14
|
+
import { CANONICAL_RATE, decodeWavToMono, encodeWavPcm16, readCanonicalWav } from './wav.js';
|
|
15
|
+
/** Extra silence after the end of the timeline, so the track is never shorter than the video. */
|
|
16
|
+
const TAIL_SEC = 0.5;
|
|
17
|
+
/** Music level relative to the music file itself. */
|
|
18
|
+
const MUSIC_GAIN_DB = -26;
|
|
19
|
+
const MUSIC_FADE_OUT_SEC = 2;
|
|
20
|
+
/** Integrated loudness the finished track is brought to, in LUFS. */
|
|
21
|
+
export const TARGET_LUFS = -16;
|
|
22
|
+
/** The true peak of the finished track stays at or below this, in dBTP. */
|
|
23
|
+
export const TRUE_PEAK_DB = -1.5;
|
|
24
|
+
/** Loudness range target for the normalizer; speech is far below it, so it never squeezes the track. */
|
|
25
|
+
const LOUDNESS_RANGE = 11;
|
|
26
|
+
/** A track already this close to the target (in LU) with a safe peak is left as it is. */
|
|
27
|
+
const LOUDNESS_TOLERANCE = 0.5;
|
|
28
|
+
/** Tracks shorter than this are too short for a loudness measurement and are left alone. */
|
|
29
|
+
const MIN_NORMALIZE_SEC = 1;
|
|
30
|
+
/** A track that needs more gain than this (in dB) is nearly silent, so it is left alone. */
|
|
31
|
+
const MAX_NORMALIZE_GAIN_DB = 30;
|
|
32
|
+
async function loadClipSamples(clip, ctx) {
|
|
33
|
+
const bytes = await readFile(clip.audioPath);
|
|
34
|
+
try {
|
|
35
|
+
return readCanonicalWav(bytes);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Not one of our own clips: convert it to the track format without changing its level.
|
|
39
|
+
ctx.logger.debug('Narration clip is not mono 48 kHz 16-bit; converting', {
|
|
40
|
+
scene: clip.sceneId,
|
|
41
|
+
beat: clip.beatIndex,
|
|
42
|
+
});
|
|
43
|
+
const mono = decodeWavToMono(bytes);
|
|
44
|
+
return floatToInt16(resampleMono(mono.samples, mono.sampleRate, CANONICAL_RATE));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Add a clip into the mix, clipping instead of wrapping if two clips ever overlap. */
|
|
48
|
+
function addClip(mix, clip, start) {
|
|
49
|
+
for (let i = 0; i < clip.length; i++) {
|
|
50
|
+
const at = start + i;
|
|
51
|
+
if (at < 0 || at >= mix.length)
|
|
52
|
+
continue;
|
|
53
|
+
const sum = (mix[at] ?? 0) + (clip[i] ?? 0);
|
|
54
|
+
mix[at] = Math.max(-32768, Math.min(32767, sum));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Render the music bed with FFmpeg: looped to the track length, quiet, faded out at the end and
|
|
59
|
+
* ducked by the narration. The result is mixed with the narration here, in plain arithmetic,
|
|
60
|
+
* so levels do not depend on how a particular FFmpeg version scales its mixer.
|
|
61
|
+
*/
|
|
62
|
+
async function renderMusicBed(voice, musicPath, ctx, run) {
|
|
63
|
+
const { ffmpeg } = await resolveFfmpeg(ctx.config);
|
|
64
|
+
const durationSec = voice.length / CANONICAL_RATE;
|
|
65
|
+
const fadeStart = Math.max(0, durationSec - MUSIC_FADE_OUT_SEC);
|
|
66
|
+
const graph = [
|
|
67
|
+
'[0:a]aformat=sample_fmts=fltp:channel_layouts=mono[sidechain]',
|
|
68
|
+
`[1:a]aresample=${CANONICAL_RATE},aformat=sample_fmts=fltp:channel_layouts=mono,volume=${MUSIC_GAIN_DB}dB,` +
|
|
69
|
+
`afade=t=out:st=${fadeStart.toFixed(3)}:d=${MUSIC_FADE_OUT_SEC}[music]`,
|
|
70
|
+
'[music][sidechain]sidechaincompress=threshold=0.03:ratio=5:attack=20:release=300[bed]',
|
|
71
|
+
].join(';');
|
|
72
|
+
const args = [
|
|
73
|
+
'-hide_banner',
|
|
74
|
+
'-loglevel',
|
|
75
|
+
'error',
|
|
76
|
+
'-i',
|
|
77
|
+
'pipe:0',
|
|
78
|
+
'-stream_loop',
|
|
79
|
+
'-1',
|
|
80
|
+
'-i',
|
|
81
|
+
musicPath,
|
|
82
|
+
'-filter_complex',
|
|
83
|
+
graph,
|
|
84
|
+
'-map',
|
|
85
|
+
'[bed]',
|
|
86
|
+
'-t',
|
|
87
|
+
durationSec.toFixed(3),
|
|
88
|
+
'-f',
|
|
89
|
+
's16le',
|
|
90
|
+
'-ac',
|
|
91
|
+
'1',
|
|
92
|
+
'-ar',
|
|
93
|
+
String(CANONICAL_RATE),
|
|
94
|
+
'pipe:1',
|
|
95
|
+
];
|
|
96
|
+
let output;
|
|
97
|
+
try {
|
|
98
|
+
output = (await run(ffmpeg, args, {
|
|
99
|
+
input: encodeWavPcm16(voice, CANONICAL_RATE),
|
|
100
|
+
signal: ctx.signal,
|
|
101
|
+
timeoutMs: 300_000,
|
|
102
|
+
})).stdoutBuffer;
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
if (ctx.signal.aborted)
|
|
106
|
+
throw err;
|
|
107
|
+
throw new MergeStoryError('CONFIG_INVALID', 'FFmpeg could not mix the background music into the narration.', {
|
|
108
|
+
hint: 'Check that render.musicPath points to a playable audio file (MP3, WAV, M4A, FLAC or OGG).',
|
|
109
|
+
cause: err,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const count = Math.floor(output.length / 2);
|
|
113
|
+
const bed = new Int16Array(count);
|
|
114
|
+
for (let i = 0; i < count; i++)
|
|
115
|
+
bed[i] = output.readInt16LE(i * 2);
|
|
116
|
+
return bed;
|
|
117
|
+
}
|
|
118
|
+
/** The numbers FFmpeg's loudnorm filter prints after its first pass, or null when there are none. */
|
|
119
|
+
export function parseLoudnorm(stderr) {
|
|
120
|
+
const block = /\{[^{}]*"input_i"[^{}]*\}/.exec(stderr)?.[0];
|
|
121
|
+
if (!block)
|
|
122
|
+
return null;
|
|
123
|
+
try {
|
|
124
|
+
const data = JSON.parse(block);
|
|
125
|
+
const stats = {
|
|
126
|
+
integrated: Number(data.input_i),
|
|
127
|
+
truePeak: Number(data.input_tp),
|
|
128
|
+
range: Number(data.input_lra),
|
|
129
|
+
threshold: Number(data.input_thresh),
|
|
130
|
+
offset: Number(data.target_offset),
|
|
131
|
+
};
|
|
132
|
+
return Object.values(stats).every(Number.isFinite) ? stats : null;
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Bring a track to TARGET_LUFS with a true peak of at most TRUE_PEAK_DB, in two passes of FFmpeg's
|
|
140
|
+
* loudnorm filter: the first measures, the second applies one steady gain (or, when that gain
|
|
141
|
+
* would push a peak over the ceiling, loudnorm's gentle dynamic mode). The track keeps its length
|
|
142
|
+
* and every sample stays where it was in time. Returns the track unchanged when it is too short or
|
|
143
|
+
* silent, is already on target, or FFmpeg is unavailable.
|
|
144
|
+
*/
|
|
145
|
+
export async function normalizeLoudness(track, ctx, run) {
|
|
146
|
+
if (track.length < MIN_NORMALIZE_SEC * CANONICAL_RATE || !track.some((v) => v !== 0))
|
|
147
|
+
return track;
|
|
148
|
+
let ffmpeg;
|
|
149
|
+
try {
|
|
150
|
+
ffmpeg = (await resolveFfmpeg(ctx.config)).ffmpeg;
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
if (ctx.signal.aborted)
|
|
154
|
+
throw err;
|
|
155
|
+
ctx.logger.debug('FFmpeg is not available; the narration level is left as it is');
|
|
156
|
+
return track;
|
|
157
|
+
}
|
|
158
|
+
const target = `I=${TARGET_LUFS}:TP=${TRUE_PEAK_DB}:LRA=${LOUDNESS_RANGE}`;
|
|
159
|
+
const input = encodeWavPcm16(track, CANONICAL_RATE);
|
|
160
|
+
try {
|
|
161
|
+
const first = await run(ffmpeg, [
|
|
162
|
+
'-hide_banner',
|
|
163
|
+
'-nostats',
|
|
164
|
+
'-i',
|
|
165
|
+
'pipe:0',
|
|
166
|
+
'-af',
|
|
167
|
+
`loudnorm=${target}:print_format=json`,
|
|
168
|
+
'-f',
|
|
169
|
+
'null',
|
|
170
|
+
'-',
|
|
171
|
+
], { input, signal: ctx.signal, timeoutMs: 300_000 });
|
|
172
|
+
const stats = parseLoudnorm(first.stderr);
|
|
173
|
+
if (!stats) {
|
|
174
|
+
ctx.logger.debug('The narration is too quiet to measure; its level is left as it is');
|
|
175
|
+
return track;
|
|
176
|
+
}
|
|
177
|
+
const gain = TARGET_LUFS - stats.integrated;
|
|
178
|
+
ctx.logger.debug('Narration loudness measured', { lufs: stats.integrated, truePeakDb: stats.truePeak });
|
|
179
|
+
if (Math.abs(gain) <= LOUDNESS_TOLERANCE && stats.truePeak <= TRUE_PEAK_DB)
|
|
180
|
+
return track;
|
|
181
|
+
if (gain > MAX_NORMALIZE_GAIN_DB)
|
|
182
|
+
return track;
|
|
183
|
+
const measured = `measured_I=${stats.integrated}:measured_LRA=${stats.range}:measured_TP=${stats.truePeak}` +
|
|
184
|
+
`:measured_thresh=${stats.threshold}:offset=${stats.offset}`;
|
|
185
|
+
const second = await run(ffmpeg, [
|
|
186
|
+
'-hide_banner',
|
|
187
|
+
'-loglevel',
|
|
188
|
+
'error',
|
|
189
|
+
'-i',
|
|
190
|
+
'pipe:0',
|
|
191
|
+
'-af',
|
|
192
|
+
`loudnorm=${target}:${measured}:linear=true,aresample=${CANONICAL_RATE},aformat=sample_fmts=s16:channel_layouts=mono`,
|
|
193
|
+
'-f',
|
|
194
|
+
's16le',
|
|
195
|
+
'-ac',
|
|
196
|
+
'1',
|
|
197
|
+
'-ar',
|
|
198
|
+
String(CANONICAL_RATE),
|
|
199
|
+
'pipe:1',
|
|
200
|
+
], { input, signal: ctx.signal, timeoutMs: 300_000 });
|
|
201
|
+
const count = Math.floor(second.stdoutBuffer.length / 2);
|
|
202
|
+
if (count === 0)
|
|
203
|
+
return track;
|
|
204
|
+
// Same length as before: anything past the end is cut and a short result is padded with silence.
|
|
205
|
+
const out = new Int16Array(track.length);
|
|
206
|
+
for (let i = 0; i < Math.min(count, out.length); i++)
|
|
207
|
+
out[i] = second.stdoutBuffer.readInt16LE(i * 2);
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
if (ctx.signal.aborted)
|
|
212
|
+
throw err;
|
|
213
|
+
ctx.progress({
|
|
214
|
+
stage: 'narrate',
|
|
215
|
+
status: 'warn',
|
|
216
|
+
message: 'The narration could not be brought to the standard loudness and keeps its own level',
|
|
217
|
+
});
|
|
218
|
+
ctx.logger.debug('Loudness normalization failed', {
|
|
219
|
+
error: err instanceof Error ? err.message : String(err),
|
|
220
|
+
});
|
|
221
|
+
return track;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Place every clip at its beat start time and write one mono 48 kHz WAV for the whole video, at
|
|
226
|
+
* the standard loudness (see normalizeLoudness). Beat start times are absolute (seconds from the
|
|
227
|
+
* start of the video). Returns null when there is no audio (silent provider and no music). Tests
|
|
228
|
+
* pass their own command runner as `run`.
|
|
229
|
+
*/
|
|
230
|
+
export async function assembleNarrationTrack(narration, timeline, outPath, ctx, options = {}, run = runCommand) {
|
|
231
|
+
const spoken = narration.clips.filter((clip) => clip.audioPath);
|
|
232
|
+
const musicPath = ctx.config.render.musicPath ? resolve(ctx.config.render.musicPath) : null;
|
|
233
|
+
if (spoken.length === 0 && !musicPath)
|
|
234
|
+
return null;
|
|
235
|
+
if (musicPath) {
|
|
236
|
+
try {
|
|
237
|
+
await access(musicPath);
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
throw new MergeStoryError('CONFIG_INVALID', 'The background music file was not found.', {
|
|
241
|
+
hint: 'Check render.musicPath in the config, or remove it to render without music.',
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const total = Math.ceil((timeline.durationSec + TAIL_SEC) * CANONICAL_RATE);
|
|
246
|
+
const voice = new Int16Array(total);
|
|
247
|
+
for (const clip of spoken) {
|
|
248
|
+
const beat = timeline.scenes
|
|
249
|
+
.find((s) => s.sceneId === clip.sceneId)
|
|
250
|
+
?.beats.find((b) => b.index === clip.beatIndex);
|
|
251
|
+
if (!beat) {
|
|
252
|
+
ctx.progress({
|
|
253
|
+
stage: 'narrate',
|
|
254
|
+
status: 'warn',
|
|
255
|
+
message: `Narration line ${clip.beatIndex + 1} of scene ${clip.sceneId} has no place on the timeline and was left out`,
|
|
256
|
+
});
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
const samples = await loadClipSamples(clip, ctx);
|
|
260
|
+
if (samples.length / CANONICAL_RATE > beat.durationSec + 0.05) {
|
|
261
|
+
ctx.progress({
|
|
262
|
+
stage: 'narrate',
|
|
263
|
+
status: 'warn',
|
|
264
|
+
message: `Narration line ${clip.beatIndex + 1} of scene ${clip.sceneId} is longer than its slot and may overlap the next line`,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
addClip(voice, samples, Math.round(beat.startSec * CANONICAL_RATE));
|
|
268
|
+
}
|
|
269
|
+
let track = voice;
|
|
270
|
+
if (musicPath) {
|
|
271
|
+
const bed = await renderMusicBed(voice, musicPath, ctx, run);
|
|
272
|
+
track = new Int16Array(voice.length);
|
|
273
|
+
addClip(track, voice, 0);
|
|
274
|
+
addClip(track, bed, 0);
|
|
275
|
+
}
|
|
276
|
+
if (options.loudness !== false)
|
|
277
|
+
track = await normalizeLoudness(track, ctx, run);
|
|
278
|
+
await mkdir(dirname(outPath), { recursive: true, mode: 0o700 });
|
|
279
|
+
await writeFile(outPath, encodeWavPcm16(track, CANONICAL_RATE), { mode: 0o600 });
|
|
280
|
+
return outPath;
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=assemble.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sample-level audio processing for narration clips: resampling, silence trimming,
|
|
3
|
+
* loudness matching and peak limiting. Everything works on mono floats in [-1, 1] and is
|
|
4
|
+
* deterministic, so a cached clip is identical on every machine.
|
|
5
|
+
*/
|
|
6
|
+
import { type MonoAudio } from './wav.ts';
|
|
7
|
+
/** Speech level every clip is matched to (RMS over the speaking parts, in dBFS). */
|
|
8
|
+
export declare const TARGET_SPEECH_RMS_DB = -18;
|
|
9
|
+
/** No sample of a finished clip is louder than this. */
|
|
10
|
+
export declare const PEAK_CEILING_DB = -1;
|
|
11
|
+
/** Audio below this level at the start and end of a clip counts as silence. */
|
|
12
|
+
export declare const SILENCE_THRESHOLD_DB = -45;
|
|
13
|
+
/** Silence kept before the first and after the last spoken sound. */
|
|
14
|
+
export declare const EDGE_PAD_SEC = 0.06;
|
|
15
|
+
export declare function dbToLinear(db: number): number;
|
|
16
|
+
/**
|
|
17
|
+
* Convert mono audio to another sample rate with a Kaiser-windowed sinc filter (polyphase).
|
|
18
|
+
* The cutoff follows the lower of the two rates, so downsampling does not alias.
|
|
19
|
+
*/
|
|
20
|
+
export declare function resampleMono(input: Float32Array, fromRate: number, toRate: number): Float32Array;
|
|
21
|
+
export interface TrimOptions {
|
|
22
|
+
thresholdDb?: number;
|
|
23
|
+
padSec?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Cut silence from both ends, leaving exactly `padSec` of quiet before the first and after the
|
|
27
|
+
* last sound (zeros are added when the clip had less). Returns null when nothing is above the
|
|
28
|
+
* threshold.
|
|
29
|
+
*/
|
|
30
|
+
export declare function trimSilence(samples: Float32Array, rate: number, options?: TrimOptions): Float32Array | null;
|
|
31
|
+
/**
|
|
32
|
+
* Join several pieces of speech with short pauses. Each piece is trimmed first, because some
|
|
33
|
+
* engines add a fraction of a second of silence to every call.
|
|
34
|
+
*/
|
|
35
|
+
export declare function joinWithGaps(parts: Float32Array[], rate: number, gapSec?: number, padSec?: number): Float32Array;
|
|
36
|
+
/**
|
|
37
|
+
* RMS level of the speaking parts of a clip in dBFS, or null for silence. Frames of 50 ms are
|
|
38
|
+
* ignored when they are very quiet or more than 10 dB below the average, so pauses between
|
|
39
|
+
* words do not make a clip look quiet.
|
|
40
|
+
*/
|
|
41
|
+
export declare function measureSpeechRmsDb(samples: Float32Array, rate: number): number | null;
|
|
42
|
+
/**
|
|
43
|
+
* Brick-wall peak limiter (in place). The gain dips smoothly around a loud peak instead of
|
|
44
|
+
* clipping it, and no sample ends up above `ceiling` (linear, 0..1).
|
|
45
|
+
*/
|
|
46
|
+
export declare function limitPeaks(samples: Float32Array, ceiling: number, rate: number): void;
|
|
47
|
+
/** Short fades at both ends so a clip never starts or stops with a click. */
|
|
48
|
+
export declare function fadeEdges(samples: Float32Array, rate: number, inSec?: number, outSec?: number): void;
|
|
49
|
+
export declare function floatToInt16(samples: Float32Array): Int16Array;
|
|
50
|
+
export interface ProcessedClip {
|
|
51
|
+
/** Mono 48 kHz 16-bit samples ready to store. */
|
|
52
|
+
pcm: Int16Array;
|
|
53
|
+
/** Gain that was applied to match the target level. */
|
|
54
|
+
gainDb: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Turn raw engine output into a finished clip: 48 kHz, silence trimmed (60 ms kept), level
|
|
58
|
+
* matched to the speech target, peaks limited, edges faded. Returns null when the audio holds no
|
|
59
|
+
* sound at all.
|
|
60
|
+
*/
|
|
61
|
+
export declare function processSpeechClip(audio: MonoAudio): ProcessedClip | null;
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sample-level audio processing for narration clips: resampling, silence trimming,
|
|
3
|
+
* loudness matching and peak limiting. Everything works on mono floats in [-1, 1] and is
|
|
4
|
+
* deterministic, so a cached clip is identical on every machine.
|
|
5
|
+
*/
|
|
6
|
+
import { CANONICAL_RATE } from './wav.js';
|
|
7
|
+
/** Speech level every clip is matched to (RMS over the speaking parts, in dBFS). */
|
|
8
|
+
export const TARGET_SPEECH_RMS_DB = -18;
|
|
9
|
+
/** No sample of a finished clip is louder than this. */
|
|
10
|
+
export const PEAK_CEILING_DB = -1;
|
|
11
|
+
/** Audio below this level at the start and end of a clip counts as silence. */
|
|
12
|
+
export const SILENCE_THRESHOLD_DB = -45;
|
|
13
|
+
/** Silence kept before the first and after the last spoken sound. */
|
|
14
|
+
export const EDGE_PAD_SEC = 0.06;
|
|
15
|
+
export function dbToLinear(db) {
|
|
16
|
+
return 10 ** (db / 20);
|
|
17
|
+
}
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
// Resampling
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
const KAISER_BETA = 8;
|
|
22
|
+
/** Zero crossings of the interpolation filter on each side (at the lower of the two rates). */
|
|
23
|
+
const FILTER_HALF_WIDTH = 16;
|
|
24
|
+
/** Above this many phases the filter is evaluated per output sample instead of from a table. */
|
|
25
|
+
const MAX_PHASE_TABLE = 2048;
|
|
26
|
+
function besselI0(x) {
|
|
27
|
+
let sum = 1;
|
|
28
|
+
let term = 1;
|
|
29
|
+
const q = (x * x) / 4;
|
|
30
|
+
for (let k = 1; k < 60; k++) {
|
|
31
|
+
term *= q / (k * k);
|
|
32
|
+
sum += term;
|
|
33
|
+
if (term < 1e-12 * sum)
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
return sum;
|
|
37
|
+
}
|
|
38
|
+
const KAISER_NORM = besselI0(KAISER_BETA);
|
|
39
|
+
function kaiser(t) {
|
|
40
|
+
if (t <= -1 || t >= 1)
|
|
41
|
+
return 0;
|
|
42
|
+
return besselI0(KAISER_BETA * Math.sqrt(1 - t * t)) / KAISER_NORM;
|
|
43
|
+
}
|
|
44
|
+
function gcd(a, b) {
|
|
45
|
+
return b === 0 ? a : gcd(b, a % b);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Convert mono audio to another sample rate with a Kaiser-windowed sinc filter (polyphase).
|
|
49
|
+
* The cutoff follows the lower of the two rates, so downsampling does not alias.
|
|
50
|
+
*/
|
|
51
|
+
export function resampleMono(input, fromRate, toRate) {
|
|
52
|
+
if (fromRate === toRate || input.length === 0)
|
|
53
|
+
return input;
|
|
54
|
+
const scale = Math.min(1, toRate / fromRate);
|
|
55
|
+
const half = Math.ceil(FILTER_HALF_WIDTH / scale);
|
|
56
|
+
const taps = half * 2;
|
|
57
|
+
const g = gcd(fromRate, toRate);
|
|
58
|
+
const phases = toRate / g;
|
|
59
|
+
const step = fromRate / g;
|
|
60
|
+
const outLength = Math.round((input.length * toRate) / fromRate);
|
|
61
|
+
const out = new Float32Array(outLength);
|
|
62
|
+
const compute = (frac, into) => {
|
|
63
|
+
let sum = 0;
|
|
64
|
+
for (let j = 0; j < taps; j++) {
|
|
65
|
+
const d = frac + (half - 1 - j);
|
|
66
|
+
const x = Math.PI * scale * d;
|
|
67
|
+
const sinc = d === 0 ? 1 : Math.sin(x) / x;
|
|
68
|
+
const w = scale * sinc * kaiser(d / half);
|
|
69
|
+
into[j] = w;
|
|
70
|
+
sum += w;
|
|
71
|
+
}
|
|
72
|
+
for (let j = 0; j < taps; j++)
|
|
73
|
+
into[j] = (into[j] ?? 0) / sum;
|
|
74
|
+
};
|
|
75
|
+
let table = null;
|
|
76
|
+
if (phases <= MAX_PHASE_TABLE) {
|
|
77
|
+
table = [];
|
|
78
|
+
for (let p = 0; p < phases; p++) {
|
|
79
|
+
const w = new Float64Array(taps);
|
|
80
|
+
compute(p / phases, w);
|
|
81
|
+
table.push(w);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const scratch = new Float64Array(taps);
|
|
85
|
+
for (let n = 0; n < outLength; n++) {
|
|
86
|
+
const numerator = n * step;
|
|
87
|
+
const i0 = Math.floor(numerator / phases);
|
|
88
|
+
const phase = numerator - i0 * phases;
|
|
89
|
+
let weights;
|
|
90
|
+
if (table) {
|
|
91
|
+
weights = table[phase];
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
compute(phase / phases, scratch);
|
|
95
|
+
weights = scratch;
|
|
96
|
+
}
|
|
97
|
+
const first = i0 - half + 1;
|
|
98
|
+
let acc = 0;
|
|
99
|
+
for (let j = 0; j < taps; j++) {
|
|
100
|
+
const idx = first + j;
|
|
101
|
+
if (idx >= 0 && idx < input.length)
|
|
102
|
+
acc += (input[idx] ?? 0) * (weights[j] ?? 0);
|
|
103
|
+
}
|
|
104
|
+
out[n] = acc;
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Cut silence from both ends, leaving exactly `padSec` of quiet before the first and after the
|
|
110
|
+
* last sound (zeros are added when the clip had less). Returns null when nothing is above the
|
|
111
|
+
* threshold.
|
|
112
|
+
*/
|
|
113
|
+
export function trimSilence(samples, rate, options = {}) {
|
|
114
|
+
const threshold = dbToLinear(options.thresholdDb ?? SILENCE_THRESHOLD_DB);
|
|
115
|
+
const pad = Math.round((options.padSec ?? EDGE_PAD_SEC) * rate);
|
|
116
|
+
let first = -1;
|
|
117
|
+
let last = -1;
|
|
118
|
+
for (let i = 0; i < samples.length; i++) {
|
|
119
|
+
if (Math.abs(samples[i] ?? 0) >= threshold) {
|
|
120
|
+
first = i;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (first < 0)
|
|
125
|
+
return null;
|
|
126
|
+
for (let i = samples.length - 1; i >= first; i--) {
|
|
127
|
+
if (Math.abs(samples[i] ?? 0) >= threshold) {
|
|
128
|
+
last = i;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const start = first - pad;
|
|
133
|
+
const end = last + 1 + pad;
|
|
134
|
+
const out = new Float32Array(end - start);
|
|
135
|
+
for (let i = 0; i < out.length; i++) {
|
|
136
|
+
const src = start + i;
|
|
137
|
+
if (src >= 0 && src < samples.length)
|
|
138
|
+
out[i] = samples[src] ?? 0;
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Join several pieces of speech with short pauses. Each piece is trimmed first, because some
|
|
144
|
+
* engines add a fraction of a second of silence to every call.
|
|
145
|
+
*/
|
|
146
|
+
export function joinWithGaps(parts, rate, gapSec = 0.16, padSec = 0.04) {
|
|
147
|
+
const trimmed = [];
|
|
148
|
+
for (const part of parts) {
|
|
149
|
+
const t = trimSilence(part, rate, { padSec });
|
|
150
|
+
if (t)
|
|
151
|
+
trimmed.push(t);
|
|
152
|
+
}
|
|
153
|
+
if (trimmed.length === 0)
|
|
154
|
+
return new Float32Array(0);
|
|
155
|
+
const gap = Math.round(gapSec * rate);
|
|
156
|
+
const total = trimmed.reduce((sum, p) => sum + p.length, 0) + gap * (trimmed.length - 1);
|
|
157
|
+
const out = new Float32Array(total);
|
|
158
|
+
let at = 0;
|
|
159
|
+
for (const piece of trimmed) {
|
|
160
|
+
out.set(piece, at);
|
|
161
|
+
at += piece.length + gap;
|
|
162
|
+
}
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
// ---------------------------------------------------------------------------
|
|
166
|
+
// Loudness
|
|
167
|
+
// ---------------------------------------------------------------------------
|
|
168
|
+
const GATE_FRAME_SEC = 0.05;
|
|
169
|
+
const ABSOLUTE_GATE_DB = -60;
|
|
170
|
+
const RELATIVE_GATE_DB = -10;
|
|
171
|
+
/**
|
|
172
|
+
* RMS level of the speaking parts of a clip in dBFS, or null for silence. Frames of 50 ms are
|
|
173
|
+
* ignored when they are very quiet or more than 10 dB below the average, so pauses between
|
|
174
|
+
* words do not make a clip look quiet.
|
|
175
|
+
*/
|
|
176
|
+
export function measureSpeechRmsDb(samples, rate) {
|
|
177
|
+
const frame = Math.max(1, Math.round(rate * GATE_FRAME_SEC));
|
|
178
|
+
const energies = [];
|
|
179
|
+
for (let start = 0; start < samples.length; start += frame) {
|
|
180
|
+
const end = Math.min(samples.length, start + frame);
|
|
181
|
+
let sum = 0;
|
|
182
|
+
for (let i = start; i < end; i++) {
|
|
183
|
+
const v = samples[i] ?? 0;
|
|
184
|
+
sum += v * v;
|
|
185
|
+
}
|
|
186
|
+
energies.push(sum / (end - start));
|
|
187
|
+
}
|
|
188
|
+
const absolute = dbToLinear(ABSOLUTE_GATE_DB) ** 2;
|
|
189
|
+
const loud = energies.filter((e) => e > absolute);
|
|
190
|
+
if (loud.length === 0)
|
|
191
|
+
return null;
|
|
192
|
+
const mean = loud.reduce((a, b) => a + b, 0) / loud.length;
|
|
193
|
+
const relative = mean * 10 ** (RELATIVE_GATE_DB / 10);
|
|
194
|
+
const kept = loud.filter((e) => e >= relative);
|
|
195
|
+
const level = kept.reduce((a, b) => a + b, 0) / kept.length;
|
|
196
|
+
return 10 * Math.log10(level);
|
|
197
|
+
}
|
|
198
|
+
function slidingMin(values, radius) {
|
|
199
|
+
const n = values.length;
|
|
200
|
+
const out = new Float32Array(n);
|
|
201
|
+
const deque = new Int32Array(n);
|
|
202
|
+
let head = 0;
|
|
203
|
+
let tail = 0;
|
|
204
|
+
let next = 0;
|
|
205
|
+
for (let i = 0; i < n; i++) {
|
|
206
|
+
const hi = Math.min(n - 1, i + radius);
|
|
207
|
+
while (next <= hi) {
|
|
208
|
+
while (tail > head && (values[deque[tail - 1]] ?? 0) >= (values[next] ?? 0))
|
|
209
|
+
tail--;
|
|
210
|
+
deque[tail++] = next++;
|
|
211
|
+
}
|
|
212
|
+
const lo = i - radius;
|
|
213
|
+
while (deque[head] < lo)
|
|
214
|
+
head++;
|
|
215
|
+
out[i] = values[deque[head]] ?? 1;
|
|
216
|
+
}
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Brick-wall peak limiter (in place). The gain dips smoothly around a loud peak instead of
|
|
221
|
+
* clipping it, and no sample ends up above `ceiling` (linear, 0..1).
|
|
222
|
+
*/
|
|
223
|
+
export function limitPeaks(samples, ceiling, rate) {
|
|
224
|
+
const n = samples.length;
|
|
225
|
+
let needed = false;
|
|
226
|
+
for (let i = 0; i < n; i++) {
|
|
227
|
+
if (Math.abs(samples[i] ?? 0) > ceiling) {
|
|
228
|
+
needed = true;
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (!needed)
|
|
233
|
+
return;
|
|
234
|
+
const radius = Math.max(1, Math.round(rate * 0.0025));
|
|
235
|
+
const required = new Float32Array(n);
|
|
236
|
+
for (let i = 0; i < n; i++) {
|
|
237
|
+
const a = Math.abs(samples[i] ?? 0);
|
|
238
|
+
required[i] = a > ceiling ? ceiling / a : 1;
|
|
239
|
+
}
|
|
240
|
+
// Taking the minimum over the window first, then averaging over the same window, keeps the
|
|
241
|
+
// smoothed gain at or below the gain every nearby peak needs.
|
|
242
|
+
const floorGain = slidingMin(required, radius);
|
|
243
|
+
const prefix = new Float64Array(n + 1);
|
|
244
|
+
for (let i = 0; i < n; i++)
|
|
245
|
+
prefix[i + 1] = (prefix[i] ?? 0) + (floorGain[i] ?? 1);
|
|
246
|
+
for (let i = 0; i < n; i++) {
|
|
247
|
+
const lo = Math.max(0, i - radius);
|
|
248
|
+
const hi = Math.min(n - 1, i + radius);
|
|
249
|
+
const gain = ((prefix[hi + 1] ?? 0) - (prefix[lo] ?? 0)) / (hi - lo + 1);
|
|
250
|
+
samples[i] = (samples[i] ?? 0) * gain;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/** Short fades at both ends so a clip never starts or stops with a click. */
|
|
254
|
+
export function fadeEdges(samples, rate, inSec = 0.005, outSec = 0.02) {
|
|
255
|
+
const n = samples.length;
|
|
256
|
+
const fadeIn = Math.min(Math.round(inSec * rate), n);
|
|
257
|
+
const fadeOut = Math.min(Math.round(outSec * rate), n);
|
|
258
|
+
for (let i = 0; i < fadeIn; i++)
|
|
259
|
+
samples[i] = (samples[i] ?? 0) * (i / fadeIn);
|
|
260
|
+
for (let i = 0; i < fadeOut; i++) {
|
|
261
|
+
const idx = n - 1 - i;
|
|
262
|
+
samples[idx] = (samples[idx] ?? 0) * (i / fadeOut);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
export function floatToInt16(samples) {
|
|
266
|
+
const out = new Int16Array(samples.length);
|
|
267
|
+
for (let i = 0; i < samples.length; i++) {
|
|
268
|
+
const v = Math.round((samples[i] ?? 0) * 32767);
|
|
269
|
+
out[i] = Math.max(-32768, Math.min(32767, v));
|
|
270
|
+
}
|
|
271
|
+
return out;
|
|
272
|
+
}
|
|
273
|
+
const MAX_GAIN_DB = 30;
|
|
274
|
+
/**
|
|
275
|
+
* Turn raw engine output into a finished clip: 48 kHz, silence trimmed (60 ms kept), level
|
|
276
|
+
* matched to the speech target, peaks limited, edges faded. Returns null when the audio holds no
|
|
277
|
+
* sound at all.
|
|
278
|
+
*/
|
|
279
|
+
export function processSpeechClip(audio) {
|
|
280
|
+
const clean = new Float32Array(audio.samples.length);
|
|
281
|
+
for (let i = 0; i < clean.length; i++) {
|
|
282
|
+
const v = audio.samples[i] ?? 0;
|
|
283
|
+
clean[i] = Number.isFinite(v) ? v : 0;
|
|
284
|
+
}
|
|
285
|
+
const resampled = resampleMono(clean, audio.sampleRate, CANONICAL_RATE);
|
|
286
|
+
const trimmed = trimSilence(resampled, CANONICAL_RATE);
|
|
287
|
+
if (!trimmed)
|
|
288
|
+
return null;
|
|
289
|
+
const level = measureSpeechRmsDb(trimmed, CANONICAL_RATE);
|
|
290
|
+
let gainDb = 0;
|
|
291
|
+
if (level !== null) {
|
|
292
|
+
gainDb = Math.max(-MAX_GAIN_DB, Math.min(MAX_GAIN_DB, TARGET_SPEECH_RMS_DB - level));
|
|
293
|
+
const gain = dbToLinear(gainDb);
|
|
294
|
+
for (let i = 0; i < trimmed.length; i++)
|
|
295
|
+
trimmed[i] = (trimmed[i] ?? 0) * gain;
|
|
296
|
+
}
|
|
297
|
+
limitPeaks(trimmed, dbToLinear(PEAK_CEILING_DB), CANONICAL_RATE);
|
|
298
|
+
fadeEdges(trimmed, CANONICAL_RATE);
|
|
299
|
+
return { pcm: floatToInt16(trimmed), gainDb };
|
|
300
|
+
}
|
|
301
|
+
//# sourceMappingURL=audio.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Storyboard } from '../core/storyboard-schema.ts';
|
|
2
|
+
import type { CaptionCue, Timeline } from '../core/types.ts';
|
|
3
|
+
/** Most words in one cue. */
|
|
4
|
+
export declare const CAPTION_MAX_WORDS = 12;
|
|
5
|
+
/** Longest line of a cue, in characters. A cue has at most two lines. */
|
|
6
|
+
export declare const CAPTION_LINE_CHARS = 42;
|
|
7
|
+
export interface CaptionOptions {
|
|
8
|
+
/** Mask e-mail addresses (default true, like the privacy setting). */
|
|
9
|
+
maskEmails?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Text as shown to viewers: whitespace collapsed, secrets (and e-mail addresses) masked.
|
|
13
|
+
* Narration lines are already checked upstream; this keeps captions safe on their own.
|
|
14
|
+
*/
|
|
15
|
+
export declare function captionText(text: string, options?: CaptionOptions): string;
|
|
16
|
+
interface CaptionChunk {
|
|
17
|
+
/** Cue text, with a line break when it needs two lines. */
|
|
18
|
+
text: string;
|
|
19
|
+
words: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Split one caption line into cues of at most 12 words and two lines of 42 characters.
|
|
23
|
+
* Cues follow sentence boundaries where they can: short sentences share a cue, long ones are
|
|
24
|
+
* cut at the most natural pause.
|
|
25
|
+
*/
|
|
26
|
+
export declare function splitCaptionText(text: string): CaptionChunk[];
|
|
27
|
+
/**
|
|
28
|
+
* One cue per narration line, split into chunks of at most 12 words and two lines of 42
|
|
29
|
+
* characters, timed in proportion to word counts across the beat. Beat times are absolute.
|
|
30
|
+
* E-mail addresses are masked unless `options.maskEmails` is false.
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildCaptionCues(storyboard: Storyboard, timeline: Timeline, options?: CaptionOptions): CaptionCue[];
|
|
33
|
+
/** WebVTT file: header, then one block per cue. Markup characters in the text are escaped. */
|
|
34
|
+
export declare function toWebVtt(cues: CaptionCue[]): string;
|
|
35
|
+
/** SubRip file: numbered cues with comma milliseconds. */
|
|
36
|
+
export declare function toSrt(cues: CaptionCue[]): string;
|
|
37
|
+
export {};
|