kasaframe 0.0.0-stage → 0.1.3
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 +21 -0
- package/NOTICE +148 -0
- package/README.md +92 -2
- package/app/package.json +12 -0
- package/app/server/engine.ts +533 -0
- package/app/server/main.ts +209 -0
- package/app/web/env.d.ts +2 -0
- package/app/web/icons.ts +31 -0
- package/app/web/index.html +21 -0
- package/app/web/main.ts +1195 -0
- package/app/web/style.css +463 -0
- package/bin/hooks.mjs +64 -0
- package/bin/kf.mjs +32 -0
- package/docs/AGENTS.md +286 -0
- package/music/README.md +37 -0
- package/package.json +44 -4
- package/packages/adapters/package.json +36 -0
- package/packages/adapters/src/css.ts +11 -0
- package/packages/adapters/src/gsap.ts +26 -0
- package/packages/adapters/src/index.ts +9 -0
- package/packages/adapters/src/lottie.ts +22 -0
- package/packages/adapters/src/media.ts +59 -0
- package/packages/adapters/src/page.ts +229 -0
- package/packages/adapters/src/project.ts +214 -0
- package/packages/adapters/src/react.ts +36 -0
- package/packages/adapters/src/svelte.ts +22 -0
- package/packages/adapters/src/three.ts +18 -0
- package/packages/adapters/src/vue.ts +27 -0
- package/packages/check/package.json +19 -0
- package/packages/check/src/check.ts +280 -0
- package/packages/check/src/cli.ts +70 -0
- package/packages/check/src/image.ts +146 -0
- package/packages/check/src/index.ts +9 -0
- package/packages/check/src/ocr.swift +37 -0
- package/packages/check/src/probe.ts +328 -0
- package/packages/check/src/report.ts +44 -0
- package/packages/check/src/rules/assets.ts +45 -0
- package/packages/check/src/rules/beats.ts +212 -0
- package/packages/check/src/rules/camera.ts +217 -0
- package/packages/check/src/rules/captions.ts +49 -0
- package/packages/check/src/rules/flash.ts +235 -0
- package/packages/check/src/rules/frames.ts +136 -0
- package/packages/check/src/rules/layout.ts +281 -0
- package/packages/check/src/rules/page.ts +87 -0
- package/packages/check/src/rules/runs.ts +20 -0
- package/packages/check/src/rules/text.ts +326 -0
- package/packages/check/src/scan.ts +240 -0
- package/packages/check/src/serve.ts +67 -0
- package/packages/check/src/types.ts +80 -0
- package/packages/check/src/video.ts +137 -0
- package/packages/cli/package.json +30 -0
- package/packages/cli/src/blur.ts +80 -0
- package/packages/cli/src/browser.ts +203 -0
- package/packages/cli/src/command.ts +44 -0
- package/packages/cli/src/commands/app.ts +25 -0
- package/packages/cli/src/commands/beats.ts +36 -0
- package/packages/cli/src/commands/bench.ts +123 -0
- package/packages/cli/src/commands/blender.ts +293 -0
- package/packages/cli/src/commands/check.ts +25 -0
- package/packages/cli/src/commands/direct.ts +210 -0
- package/packages/cli/src/commands/doctor.ts +30 -0
- package/packages/cli/src/commands/gen.ts +173 -0
- package/packages/cli/src/commands/look.ts +46 -0
- package/packages/cli/src/commands/lyrics.ts +157 -0
- package/packages/cli/src/commands/make.ts +1121 -0
- package/packages/cli/src/commands/music.ts +78 -0
- package/packages/cli/src/commands/narrate.ts +238 -0
- package/packages/cli/src/commands/new.ts +185 -0
- package/packages/cli/src/commands/preview.ts +43 -0
- package/packages/cli/src/commands/render.ts +250 -0
- package/packages/cli/src/commands/series.ts +110 -0
- package/packages/cli/src/commands/setup.ts +102 -0
- package/packages/cli/src/commands/sheet.ts +114 -0
- package/packages/cli/src/commands/skill.ts +43 -0
- package/packages/cli/src/commands/still.ts +40 -0
- package/packages/cli/src/commands/theme.ts +172 -0
- package/packages/cli/src/commands/transitions.ts +40 -0
- package/packages/cli/src/deps.ts +122 -0
- package/packages/cli/src/ffmpeg.ts +81 -0
- package/packages/cli/src/index.ts +8 -0
- package/packages/cli/src/kf.ts +64 -0
- package/packages/cli/src/lock.ts +72 -0
- package/packages/cli/src/mix.ts +131 -0
- package/packages/cli/src/out.ts +13 -0
- package/packages/cli/src/pool.ts +34 -0
- package/packages/cli/src/segments.ts +402 -0
- package/packages/cli/src/serve.ts +124 -0
- package/packages/clock/package.json +14 -0
- package/packages/clock/src/index.ts +25 -0
- package/packages/clock/src/install.ts +351 -0
- package/packages/clock/src/types.ts +45 -0
- package/packages/core/package.json +9 -0
- package/packages/core/src/beats.ts +283 -0
- package/packages/core/src/ease.ts +87 -0
- package/packages/core/src/frame.ts +99 -0
- package/packages/core/src/index.ts +27 -0
- package/packages/core/src/project.ts +157 -0
- package/packages/core/src/rand.ts +56 -0
- package/packages/core/src/spring.ts +52 -0
- package/packages/core/src/style.ts +100 -0
- package/packages/core/src/time.ts +88 -0
- package/packages/director/package.json +23 -0
- package/packages/director/src/assemble.ts +361 -0
- package/packages/director/src/brief.ts +122 -0
- package/packages/director/src/catalog.ts +49 -0
- package/packages/director/src/content.ts +343 -0
- package/packages/director/src/fallback.ts +58 -0
- package/packages/director/src/index.ts +13 -0
- package/packages/director/src/pattern.ts +90 -0
- package/packages/director/src/patterns/fill/cells.ts +115 -0
- package/packages/director/src/patterns/formula/stack.ts +93 -0
- package/packages/director/src/patterns/util.ts +58 -0
- package/packages/director/src/scene.ts +62 -0
- package/packages/director/src/select.ts +163 -0
- package/packages/director/src/transitions.ts +115 -0
- package/packages/gen/PROVIDERS.md +90 -0
- package/packages/gen/package.json +9 -0
- package/packages/gen/src/ask.ts +132 -0
- package/packages/gen/src/audio.ts +91 -0
- package/packages/gen/src/blender.ts +54 -0
- package/packages/gen/src/capabilities.ts +151 -0
- package/packages/gen/src/generate.ts +206 -0
- package/packages/gen/src/image/codex.ts +117 -0
- package/packages/gen/src/image/og.ts +133 -0
- package/packages/gen/src/index.ts +26 -0
- package/packages/gen/src/keys.ts +86 -0
- package/packages/gen/src/media.ts +150 -0
- package/packages/gen/src/music/elevenlabs.ts +41 -0
- package/packages/gen/src/music/index.ts +120 -0
- package/packages/gen/src/music/library.ts +73 -0
- package/packages/gen/src/music/lyria.ts +52 -0
- package/packages/gen/src/music/types.ts +28 -0
- package/packages/gen/src/plan.ts +106 -0
- package/packages/gen/src/registry.ts +54 -0
- package/packages/gen/src/seam.ts +103 -0
- package/packages/gen/src/tts/dashscope.ts +64 -0
- package/packages/gen/src/tts/elevenlabs.ts +84 -0
- package/packages/gen/src/tts/gemini.ts +73 -0
- package/packages/gen/src/tts/index.ts +241 -0
- package/packages/gen/src/tts/local.ts +42 -0
- package/packages/gen/src/tts/types.ts +44 -0
- package/packages/gen/src/types.ts +90 -0
- package/packages/gen/src/video/fal.ts +140 -0
- package/packages/gen/src/video/h3.ts +112 -0
- package/packages/gen/src/video/http.ts +44 -0
- package/packages/gen/src/video/ltx.ts +60 -0
- package/packages/gen/src/video/minimax.ts +55 -0
- package/packages/gen/src/video/veo.ts +71 -0
- package/packages/jizura/package.json +16 -0
- package/packages/jizura/src/deny.ts +73 -0
- package/packages/jizura/src/index.ts +7 -0
- package/packages/jizura/src/install.ts +269 -0
- package/packages/jizura/src/layer.ts +325 -0
- package/packages/jizura/src/lyrics.ts +81 -0
- package/packages/jizura/src/pin.ts +8 -0
- package/packages/jizura/src/vendor.ts +140 -0
- package/packages/jizura/src/vite.ts +63 -0
- package/packages/jizura/vendor/JIZURA_LICENSE.txt +21 -0
- package/packages/jizura/vendor/NOTICE +43 -0
- package/packages/jizura/vendor/engine.json +47 -0
- package/packages/jizura/vendor/fonts/BlackHanSans-Regular.woff2 +0 -0
- package/packages/jizura/vendor/fonts/DotGothic16-Regular.woff2 +0 -0
- package/packages/jizura/vendor/fonts/GowunBatang-Bold.woff2 +0 -0
- package/packages/jizura/vendor/fonts/IBMPlexMono-Medium.ttf +0 -0
- package/packages/jizura/vendor/fonts/IBMPlexMono-SemiBold.ttf +0 -0
- package/packages/jizura/vendor/fonts/NotoSansKR-VF.woff2 +0 -0
- package/packages/jizura/vendor/fonts/NotoSerifKR-VF.woff2 +0 -0
- package/packages/jizura/vendor/fonts/OFL-blackhansans.txt +93 -0
- package/packages/jizura/vendor/fonts/OFL-dotgothic16.txt +93 -0
- package/packages/jizura/vendor/fonts/OFL-gowunbatang.txt +94 -0
- package/packages/jizura/vendor/fonts/OFL-ibmplexmono.txt +93 -0
- package/packages/jizura/vendor/fonts/OFL-notosanskr.txt +93 -0
- package/packages/jizura/vendor/fonts/OFL-notoserifkr.txt +94 -0
- package/packages/jizura/vendor/fonts/fonts.json +52 -0
- package/packages/jizura/vendor/jizura_engine.js +35024 -0
- package/packages/motion/README.md +153 -0
- package/packages/motion/package.json +30 -0
- package/packages/motion/src/camera.ts +97 -0
- package/packages/motion/src/captions.ts +487 -0
- package/packages/motion/src/enter.ts +128 -0
- package/packages/motion/src/hangul.ts +129 -0
- package/packages/motion/src/impact.ts +100 -0
- package/packages/motion/src/index.ts +17 -0
- package/packages/motion/src/moves/brushWipe.ts +103 -0
- package/packages/motion/src/moves/cloneArray.ts +111 -0
- package/packages/motion/src/moves/curtains.ts +81 -0
- package/packages/motion/src/moves/dress.ts +191 -0
- package/packages/motion/src/moves/echoStack.ts +70 -0
- package/packages/motion/src/moves/fit.ts +70 -0
- package/packages/motion/src/moves/flood.ts +61 -0
- package/packages/motion/src/moves/ghostStack.ts +88 -0
- package/packages/motion/src/moves/gridFloor.ts +100 -0
- package/packages/motion/src/moves/imageSwarm.ts +113 -0
- package/packages/motion/src/moves/index.ts +38 -0
- package/packages/motion/src/moves/irisBlades.ts +113 -0
- package/packages/motion/src/moves/karaokeLine.ts +108 -0
- package/packages/motion/src/moves/ledBoard.ts +94 -0
- package/packages/motion/src/moves/liquidTab.ts +72 -0
- package/packages/motion/src/moves/markerWrite.ts +63 -0
- package/packages/motion/src/moves/menu.ts +138 -0
- package/packages/motion/src/moves/morphBox.ts +96 -0
- package/packages/motion/src/moves/neonSign.ts +78 -0
- package/packages/motion/src/moves/panelPop.ts +78 -0
- package/packages/motion/src/moves/paperTear.ts +75 -0
- package/packages/motion/src/moves/path.ts +64 -0
- package/packages/motion/src/moves/pathText.ts +107 -0
- package/packages/motion/src/moves/pointSphere.ts +109 -0
- package/packages/motion/src/moves/ransomLetters.ts +73 -0
- package/packages/motion/src/moves/shapeMorph.ts +143 -0
- package/packages/motion/src/moves/slamWords.ts +96 -0
- package/packages/motion/src/moves/sparkTrail.ts +130 -0
- package/packages/motion/src/moves/speedLines.ts +91 -0
- package/packages/motion/src/moves/splitFlap.ts +149 -0
- package/packages/motion/src/moves/stepWords.ts +128 -0
- package/packages/motion/src/moves/strikeOut.ts +98 -0
- package/packages/motion/src/moves/sunburst.ts +58 -0
- package/packages/motion/src/moves/tickerRows.ts +91 -0
- package/packages/motion/src/moves/tokenPicker.ts +115 -0
- package/packages/motion/src/moves/truchet.ts +85 -0
- package/packages/motion/src/moves/wordWall.ts +78 -0
- package/packages/motion/src/moves/worldRoll.ts +32 -0
- package/packages/motion/src/particles.ts +102 -0
- package/packages/motion/src/react/index.tsx +21 -0
- package/packages/motion/src/react/parts.tsx +431 -0
- package/packages/motion/src/react/time.tsx +97 -0
- package/packages/motion/src/text.ts +103 -0
- package/packages/motion/src/transition.ts +82 -0
- package/packages/motion/src/transition3d/cards.ts +65 -0
- package/packages/motion/src/transition3d/chain.ts +84 -0
- package/packages/motion/src/transition3d/dive.ts +181 -0
- package/packages/motion/src/transition3d/fold.ts +110 -0
- package/packages/motion/src/transition3d/gl.ts +219 -0
- package/packages/motion/src/transition3d/index.ts +235 -0
- package/packages/motion/src/transition3d/live.ts +70 -0
- package/packages/motion/src/transition3d/portal.ts +115 -0
- package/packages/motion/src/transition3d/react.tsx +29 -0
- package/packages/motion/src/transition3d/rig.ts +600 -0
- package/packages/motion/src/transition3d/shatter.ts +104 -0
- package/packages/motion/src/transition3d/space.ts +173 -0
- package/packages/motion/src/transition3d/whip.ts +78 -0
- package/packages/motion/src/transition3d/world.ts +737 -0
- package/packages/motion/src/transition3d/zoomOut.ts +114 -0
- package/packages/motion/src/transitions2d/catalog.ts +127 -0
- package/packages/motion/src/transitions2d/css.d.ts +2 -0
- package/packages/motion/src/transitions2d/cult-ui/LICENSE.md +9 -0
- package/packages/motion/src/transitions2d/cult-ui/RollingNumber.tsx +43 -0
- package/packages/motion/src/transitions2d/gl-transitions/LICENSE +25 -0
- package/packages/motion/src/transitions2d/gl-transitions/shaders.ts +1931 -0
- package/packages/motion/src/transitions2d/index.ts +2 -0
- package/packages/motion/src/transitions2d/kokonutui/LICENSE +21 -0
- package/packages/motion/src/transitions2d/kokonutui/MatrixText.css +16 -0
- package/packages/motion/src/transitions2d/kokonutui/MatrixText.tsx +94 -0
- package/packages/motion/src/transitions2d/magicui/HyperText.css +15 -0
- package/packages/motion/src/transitions2d/magicui/HyperText.tsx +115 -0
- package/packages/motion/src/transitions2d/magicui/LICENSE.md +21 -0
- package/packages/motion/src/transitions2d/magicui/MorphingText.css +25 -0
- package/packages/motion/src/transitions2d/magicui/MorphingText.tsx +130 -0
- package/packages/motion/src/transitions2d/magicui/WordRotate.tsx +42 -0
- package/packages/motion/src/transitions2d/react.ts +13 -0
- package/packages/motion/src/transitions2d/skiper-ui/ClipDiv.css +39 -0
- package/packages/motion/src/transitions2d/skiper-ui/ClipDiv.tsx +32 -0
- package/packages/motion/src/transitions2d/smoothui/LICENSE +21 -0
- package/packages/motion/src/transitions2d/smoothui/SharedAxisY.tsx +50 -0
- package/packages/motion/src/transitions2d/smoothui/TextMorph.tsx +90 -0
- package/packages/motion/src/transitions2d/smoothui/shaders.ts +223 -0
- package/packages/motion/src/transitions2d/unlumen/LICENSE +21 -0
- package/packages/motion/src/transitions2d/unlumen/ScrambleText.tsx +114 -0
- package/packages/motion/src/transitions2d/vengeance-ui/LICENSE +21 -0
- package/packages/motion/src/transitions2d/vengeance-ui/MorphText.css +69 -0
- package/packages/motion/src/transitions2d/vengeance-ui/MorphText.tsx +45 -0
- package/packages/motion/src/type.ts +131 -0
- package/packages/motion/src/ui.ts +172 -0
- package/packages/patterns/package.json +15 -0
- package/packages/patterns/src/bars/rank.ts +119 -0
- package/packages/patterns/src/before-after/shrink.ts +127 -0
- package/packages/patterns/src/before-after/strike.ts +125 -0
- package/packages/patterns/src/code/terminal.ts +133 -0
- package/packages/patterns/src/compare/bars.ts +142 -0
- package/packages/patterns/src/compare/duel.ts +103 -0
- package/packages/patterns/src/end/lockup.ts +85 -0
- package/packages/patterns/src/end/slam.ts +91 -0
- package/packages/patterns/src/flow/graph.ts +250 -0
- package/packages/patterns/src/hook-number/counter.ts +101 -0
- package/packages/patterns/src/hook-number/roll.ts +179 -0
- package/packages/patterns/src/hook-number/slam.ts +91 -0
- package/packages/patterns/src/index.ts +38 -0
- package/packages/patterns/src/kit.ts +449 -0
- package/packages/patterns/src/limit/gauge.ts +117 -0
- package/packages/patterns/src/list/cards.ts +131 -0
- package/packages/patterns/src/list/cycle.ts +22 -0
- package/packages/patterns/src/media/panels.ts +100 -0
- package/packages/patterns/src/objects.ts +234 -0
- package/packages/patterns/src/quote/karaoke.ts +126 -0
- package/packages/patterns/src/quote/slam.ts +22 -0
- package/packages/patterns/src/screen/focus.ts +85 -0
- package/packages/patterns/src/steps/path.ts +137 -0
- package/packages/patterns/src/steps/stack.ts +111 -0
- package/packages/patterns/src/term-reveal/chips.ts +92 -0
- package/packages/patterns/src/term-reveal/expand.ts +127 -0
- package/packages/patterns/src/timeline/axis.ts +144 -0
- package/packages/patterns/src/title/mask.ts +85 -0
- package/packages/patterns/src/title/slam.ts +23 -0
- package/packages/patterns/src/toggle-sim/switch.ts +92 -0
- package/packages/patterns/src/trend/columns.ts +108 -0
- package/packages/patterns/src/trend/draw.ts +140 -0
- package/packages/patterns/src/types.ts +67 -0
- package/packages/patterns/src/words/moves.ts +42 -0
- package/packages/patterns/src/words/slam.ts +4 -0
- package/packages/plan/package.json +15 -0
- package/packages/plan/src/asks.ts +256 -0
- package/packages/plan/src/brief.ts +383 -0
- package/packages/plan/src/captions.ts +78 -0
- package/packages/plan/src/detect.ts +93 -0
- package/packages/plan/src/index.ts +27 -0
- package/packages/plan/src/layout.ts +176 -0
- package/packages/plan/src/llm.ts +172 -0
- package/packages/plan/src/look.ts +222 -0
- package/packages/plan/src/plan.ts +179 -0
- package/packages/plan/src/request.ts +55 -0
- package/packages/plan/src/series.ts +76 -0
- package/packages/plan/src/studio.ts +53 -0
- package/packages/plan/src/templates.ts +42 -0
- package/packages/plan/src/themes.ts +48 -0
- package/packages/plan/src/types.ts +157 -0
- package/packages/studio/package.json +12 -0
- package/packages/studio/src/index.ts +1 -0
- package/packages/studio/src/plugin.ts +236 -0
- package/packages/studio/src/ui/main.ts +503 -0
- package/packages/studio/src/ui/studio.css +165 -0
- package/packages/studio/src/ui/timeline.ts +317 -0
- package/packages/themes/kit/THEME-MAKE.md +68 -0
- package/packages/themes/kit/THEME.md +30 -0
- package/packages/themes/kit/briefs/og-intro-15s/brief.json +16 -0
- package/packages/themes/kit/briefs/og-intro-15s/facts.ts +29 -0
- package/packages/themes/kit/briefs/og-intro-15s/logo.svg +12 -0
- package/packages/themes/kit/effects.ts +5 -0
- package/packages/themes/kit/sample/index.html +11 -0
- package/packages/themes/kit/sample/main.ts +9 -0
- package/packages/themes/kit/sample/scenes/scene.ts +15 -0
- package/packages/themes/package.json +19 -0
- package/packages/themes/src/factory.ts +296 -0
- package/packages/themes/src/fx.ts +14 -0
- package/packages/themes/src/index.ts +114 -0
- package/packages/themes/src/slotkit.ts +79 -0
- package/packages/themes/src/slots.ts +46 -0
- package/packages/themes/src/stage3d.ts +197 -0
- package/packages/themes/src/types.ts +58 -0
- package/presets/kawaii-pastel.json +94 -0
- package/presets/neutral-dark.json +82 -0
- package/presets/og.json +98 -0
- package/series/og-shorts.json +14 -0
- package/skills/kasaframe/SKILL.md +33 -0
- package/templates/_shared/project/index.html +11 -0
- package/templates/_shared/project/lib/react.ts +22 -0
- package/templates/_shared/project/lib/stage.ts +292 -0
- package/templates/_shared/project/main.ts +9 -0
- package/templates/_shared/scenes/default.ts +21 -0
- package/templates/_shared/scenes/drop.ts +33 -0
- package/templates/_shared/scenes/end.ts +26 -0
- package/templates/_shared/scenes/hook.ts +18 -0
- package/templates/_shared/scenes/seam.ts +41 -0
- package/templates/_shared/scenes/step.ts +49 -0
- package/templates/ad/preview.png +0 -0
- package/templates/ad/template.json +151 -0
- package/templates/demo/preview.png +0 -0
- package/templates/demo/template.json +141 -0
- package/templates/explainer/preview.png +0 -0
- package/templates/explainer/template.json +193 -0
- package/templates/launch/preview.png +0 -0
- package/templates/launch/template.json +163 -0
- package/templates/mv/preview.png +0 -0
- package/templates/mv/scenes/default.ts +98 -0
- package/templates/mv/template.json +178 -0
- package/templates/promo/preview.png +0 -0
- package/templates/promo/template.json +185 -0
- package/templates/shorts/preview.png +0 -0
- package/templates/shorts/scenes/hook.ts +37 -0
- package/templates/shorts/template.json +196 -0
- package/templates/square/preview.png +0 -0
- package/templates/square/template.json +133 -0
- package/themes/debug-hud/THEME.md +39 -0
- package/themes/debug-hud/effects.ts +389 -0
- package/themes/debug-hud/sample/assets/og/logo.svg +12 -0
- package/themes/debug-hud/sample/beats.json +1 -0
- package/themes/debug-hud/sample/index.html +11 -0
- package/themes/debug-hud/sample/kf.json +59 -0
- package/themes/debug-hud/sample/lib/hudkit.ts +49 -0
- package/themes/debug-hud/sample/lib/og.ts +29 -0
- package/themes/debug-hud/sample/main.ts +9 -0
- package/themes/debug-hud/sample/scenes/end.ts +62 -0
- package/themes/debug-hud/sample/scenes/gather.ts +67 -0
- package/themes/debug-hud/sample/scenes/models.ts +70 -0
- package/themes/debug-hud/sample/scenes/price.ts +79 -0
- package/themes/debug-hud/sample/style.json +91 -0
- package/themes/debug-hud/slots.ts +99 -0
- package/themes/debug-hud/still.png +0 -0
- package/themes/debug-hud/style.json +91 -0
- package/themes/debug-hud/theme.json +68 -0
- package/themes/og-measure/THEME.md +47 -0
- package/themes/og-measure/effects.ts +432 -0
- package/themes/og-measure/sample/assets/brand/og-logo-full.svg +12 -0
- package/themes/og-measure/sample/assets/brand/og-logo.svg +12 -0
- package/themes/og-measure/sample/assets/data/measure.json +353 -0
- package/themes/og-measure/sample/beats.json +1 -0
- package/themes/og-measure/sample/index.html +11 -0
- package/themes/og-measure/sample/kf.json +66 -0
- package/themes/og-measure/sample/lib/data.ts +62 -0
- package/themes/og-measure/sample/main.ts +9 -0
- package/themes/og-measure/sample/measure.ts +78 -0
- package/themes/og-measure/sample/scenes/end.ts +47 -0
- package/themes/og-measure/sample/scenes/gather.ts +51 -0
- package/themes/og-measure/sample/scenes/models.ts +34 -0
- package/themes/og-measure/sample/scenes/one.ts +39 -0
- package/themes/og-measure/sample/scenes/price.ts +56 -0
- package/themes/og-measure/sample/style.json +97 -0
- package/themes/og-measure/slots.ts +88 -0
- package/themes/og-measure/still.png +0 -0
- package/themes/og-measure/style.json +97 -0
- package/themes/og-measure/theme.json +79 -0
- package/themes/riso-zine/THEME.md +43 -0
- package/themes/riso-zine/effects.ts +321 -0
- package/themes/riso-zine/sample/assets/og/logo.svg +12 -0
- package/themes/riso-zine/sample/beats.json +1 -0
- package/themes/riso-zine/sample/index.html +11 -0
- package/themes/riso-zine/sample/kf.json +59 -0
- package/themes/riso-zine/sample/lib/og.ts +29 -0
- package/themes/riso-zine/sample/lib/shot.ts +86 -0
- package/themes/riso-zine/sample/lib/zine.ts +42 -0
- package/themes/riso-zine/sample/main.ts +9 -0
- package/themes/riso-zine/sample/scenes/end.ts +61 -0
- package/themes/riso-zine/sample/scenes/gather.ts +62 -0
- package/themes/riso-zine/sample/scenes/models.ts +52 -0
- package/themes/riso-zine/sample/scenes/price.ts +82 -0
- package/themes/riso-zine/sample/style.json +99 -0
- package/themes/riso-zine/slots.ts +81 -0
- package/themes/riso-zine/still.png +0 -0
- package/themes/riso-zine/style.json +99 -0
- package/themes/riso-zine/theme.json +75 -0
- package/tools/beats/beats.py +372 -0
- package/tools/beats/requirements.txt +3 -0
- package/tools/lyrics/align.py +164 -0
- package/tools/lyrics/requirements.txt +9 -0
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""곡을 재서 beats.json(SPEC 4번)을 쓴다.
|
|
3
|
+
|
|
4
|
+
드롭·구간은 저역 에너지와 onset 으로 잰 시각이다. BPM 을 곱해 만든 시각은
|
|
5
|
+
뒤로 갈수록 밀려서 쓰지 않는다 — 마디·프레이즈도 잰 박을 세어서 얻는다.
|
|
6
|
+
"""
|
|
7
|
+
import argparse
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
import librosa
|
|
14
|
+
from scipy.ndimage import median_filter, uniform_filter1d
|
|
15
|
+
|
|
16
|
+
SR = 22050
|
|
17
|
+
# 5.8ms — 60fps 한 프레임(16.7ms) 안에 드롭 시각이 떨어지게
|
|
18
|
+
HOP = 128
|
|
19
|
+
NFFT = 2048
|
|
20
|
+
BANDS = {"low": (20, 150), "mid": (150, 2000), "high": (2000, SR / 2)}
|
|
21
|
+
EPS = 1e-10
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def nfr(sec):
|
|
25
|
+
return max(1, int(round(sec * SR / HOP)))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def db(p):
|
|
29
|
+
return 10 * np.log10(p + EPS)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Song:
|
|
33
|
+
def __init__(self, path):
|
|
34
|
+
y, _ = librosa.load(path, sr=SR, mono=True)
|
|
35
|
+
self.length = len(y) / SR
|
|
36
|
+
S = np.abs(librosa.stft(y, n_fft=NFFT, hop_length=HOP)) ** 2
|
|
37
|
+
f = librosa.fft_frequencies(sr=SR, n_fft=NFFT)
|
|
38
|
+
self.t = librosa.frames_to_time(np.arange(S.shape[1]), sr=SR, hop_length=HOP)
|
|
39
|
+
self.power = {k: S[(f >= lo) & (f < hi)].sum(0) for k, (lo, hi) in BANDS.items()}
|
|
40
|
+
# 한 프레임짜리 값은 너무 튀어서 30ms 로 고른다(킥 어택은 그대로 남는 길이)
|
|
41
|
+
self.fast = {k: db(uniform_filter1d(p, nfr(0.03))) for k, p in self.power.items()}
|
|
42
|
+
mel = librosa.feature.melspectrogram(S=S, sr=SR, n_mels=128)
|
|
43
|
+
logmel = librosa.power_to_db(mel)
|
|
44
|
+
self.onset = librosa.onset.onset_strength(S=logmel, sr=SR, hop_length=HOP)
|
|
45
|
+
mf = librosa.mel_frequencies(n_mels=128, fmax=SR / 2)
|
|
46
|
+
self.low_onset = librosa.onset.onset_strength(S=logmel[mf < 150], sr=SR, hop_length=HOP)
|
|
47
|
+
self.mfcc = librosa.feature.mfcc(S=logmel, n_mfcc=13)
|
|
48
|
+
self.chroma = librosa.feature.chroma_stft(S=S, sr=SR, hop_length=HOP)
|
|
49
|
+
|
|
50
|
+
def frame(self, sec):
|
|
51
|
+
return int(np.clip(np.searchsorted(self.t, sec), 0, len(self.t) - 1))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def track_beats(song, bpm_hint):
|
|
55
|
+
if bpm_hint:
|
|
56
|
+
start = bpm_hint
|
|
57
|
+
else:
|
|
58
|
+
start = float(librosa.feature.tempo(onset_envelope=song.onset, sr=SR, hop_length=HOP)[0])
|
|
59
|
+
# 반박으로 잡히면 박 사이가 0.7초가 넘어 화면이 박을 놓친다 — 90 아래는 두 배로 센다
|
|
60
|
+
if start < 90:
|
|
61
|
+
start *= 2
|
|
62
|
+
_, bf = librosa.beat.beat_track(
|
|
63
|
+
onset_envelope=song.onset, sr=SR, hop_length=HOP, start_bpm=start, tightness=200
|
|
64
|
+
)
|
|
65
|
+
return librosa.frames_to_time(bf, sr=SR, hop_length=HOP)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def runs(mask):
|
|
69
|
+
out, i, n = [], 0, len(mask)
|
|
70
|
+
while i < n:
|
|
71
|
+
j = i
|
|
72
|
+
while j < n and mask[j] == mask[i]:
|
|
73
|
+
j += 1
|
|
74
|
+
out.append([bool(mask[i]), i, j])
|
|
75
|
+
i = j
|
|
76
|
+
return out
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def bass_runs(song):
|
|
80
|
+
"""저역이 깔린 구간(on)과 빠진 구간(off). 킥 사이 틈은 0.5초 평균으로 메운다."""
|
|
81
|
+
bass = db(uniform_filter1d(song.power["low"], nfr(0.5)))
|
|
82
|
+
ref = np.percentile(bass, 90)
|
|
83
|
+
on, state = np.zeros(len(bass), bool), False
|
|
84
|
+
for i, v in enumerate(bass):
|
|
85
|
+
if state and v < ref - 20:
|
|
86
|
+
state = False
|
|
87
|
+
elif not state and v > ref - 12:
|
|
88
|
+
state = True
|
|
89
|
+
on[i] = state
|
|
90
|
+
rs = runs(on)
|
|
91
|
+
# 1초보다 짧은 on/off 는 앞 구간에 붙인다 — 잠깐 끊긴 것을 구간으로 세지 않는다
|
|
92
|
+
merged = []
|
|
93
|
+
for r in rs:
|
|
94
|
+
if merged and (r[2] - r[1]) < nfr(1.0):
|
|
95
|
+
merged[-1][2] = r[2]
|
|
96
|
+
elif merged and merged[-1][0] == r[0]:
|
|
97
|
+
merged[-1][2] = r[2]
|
|
98
|
+
else:
|
|
99
|
+
merged.append(list(r))
|
|
100
|
+
return merged, ref
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def refine_hit(song, i_from, i_to, level):
|
|
104
|
+
"""[i_from, i_to) 안에서 저역이 level 에 처음 닿는 프레임."""
|
|
105
|
+
idx = np.nonzero(song.fast["low"][i_from:i_to] >= level)[0]
|
|
106
|
+
return None if len(idx) == 0 else i_from + int(idx[0])
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def attack_time(song, hit):
|
|
110
|
+
"""킥 어택 시각. 가운데 맞춘 STFT 창은 계단을 창 길이만큼 번지게 하는데,
|
|
111
|
+
파워가 꼭대기의 절반(-3dB)을 지나는 창 중심이 바로 계단 자리다."""
|
|
112
|
+
raw = db(song.power["low"])
|
|
113
|
+
a, b = max(1, hit - nfr(0.08)), min(len(raw), hit + nfr(0.06))
|
|
114
|
+
half = raw[hit:b].max() - 3
|
|
115
|
+
for j in range(a, b):
|
|
116
|
+
if raw[j] >= half:
|
|
117
|
+
f = (half - raw[j - 1]) / max(raw[j] - raw[j - 1], EPS)
|
|
118
|
+
return float(song.t[j - 1] + np.clip(f, 0, 1) * (song.t[j] - song.t[j - 1]))
|
|
119
|
+
return float(song.t[hit])
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def find_drops(song, rs):
|
|
123
|
+
low = song.fast["low"]
|
|
124
|
+
drops = []
|
|
125
|
+
# 저역이 1초 넘게 빠졌다가 들어오는 곳 — 진짜 드롭
|
|
126
|
+
for k in range(1, len(rs)):
|
|
127
|
+
prev, cur = rs[k - 1], rs[k]
|
|
128
|
+
# 곡 첫머리의 짧은 무음 뒤에 저역이 시작하는 것은 드롭이 아니라 그냥 시작이다
|
|
129
|
+
if not cur[0] or prev[0] or (prev[2] - prev[1]) < nfr(1.0):
|
|
130
|
+
continue
|
|
131
|
+
i0 = cur[1]
|
|
132
|
+
peak = np.percentile(low[i0 : i0 + nfr(4)], 95)
|
|
133
|
+
hit = refine_hit(song, max(prev[1], i0 - nfr(1.5)), i0 + nfr(1.5), peak - 3)
|
|
134
|
+
if hit is None:
|
|
135
|
+
continue
|
|
136
|
+
before = np.median(low[max(prev[1], i0 - nfr(4)) : i0 - nfr(1.0)] if i0 - nfr(1.0) > prev[1] else low[prev[1] : i0])
|
|
137
|
+
drops.append({"i": hit, "contrast": float(peak - before), "how": "bass-in"})
|
|
138
|
+
|
|
139
|
+
# 저역은 깔린 채 위쪽이 잠깐 통째로 끊겼다가(스톱) 크게 다시 치는 곳 — 다시 드롭
|
|
140
|
+
high = song.fast["high"]
|
|
141
|
+
ref = median_filter(high, size=nfr(2.0), mode="nearest")
|
|
142
|
+
# 고역이 원래 성긴 곳(인트로 피아노 같은)의 틈은 스톱이 아니다 — 꽉 찬 구간에서 통째로 빈 것만
|
|
143
|
+
dense = np.percentile(high, 50) - 6
|
|
144
|
+
gap = (high < ref - 18) & (ref >= dense)
|
|
145
|
+
for on, a, b in runs(gap):
|
|
146
|
+
if not on or (b - a) < nfr(0.04):
|
|
147
|
+
continue
|
|
148
|
+
if not any(r[0] and r[1] <= a < r[2] for r in rs):
|
|
149
|
+
continue
|
|
150
|
+
if any(abs(d["i"] - b) < nfr(2.0) for d in drops):
|
|
151
|
+
continue
|
|
152
|
+
depth = float(np.median(ref[a:b]) - high[a:b].min())
|
|
153
|
+
# 킥 사이 짧은 숨(20~25dB)은 리듬일 뿐이고, 다시 드롭 앞 스톱은 30dB 넘게 비었다
|
|
154
|
+
if depth < 30:
|
|
155
|
+
continue
|
|
156
|
+
local = np.percentile(low[max(0, b - nfr(3)) : b + nfr(3)], 95)
|
|
157
|
+
hit = refine_hit(song, b, b + nfr(0.25), local - 3)
|
|
158
|
+
# 스톱 뒤에 저역이 새로 쳐야 한다 — 이어지던 저역에 걸린 것은 드롭이 아니다
|
|
159
|
+
if hit is None or low[hit] - low[a:hit].min() < 6:
|
|
160
|
+
continue
|
|
161
|
+
drops.append({"i": hit, "contrast": depth, "how": "stop"})
|
|
162
|
+
|
|
163
|
+
drops.sort(key=lambda d: d["i"])
|
|
164
|
+
for d in drops:
|
|
165
|
+
d["t"] = attack_time(song, d["i"])
|
|
166
|
+
# 저역이 통째로 빠졌다 들어오는 드롭이 스톱 뒤 다시 치는 것보다 크게 들린다
|
|
167
|
+
scale = 1.0 if d["how"] == "bass-in" else 0.8
|
|
168
|
+
d["strength"] = round(float(np.clip(d["contrast"] / 45, 0, 1) * scale), 2)
|
|
169
|
+
return drops
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def downbeat_flags(song, beats, drops):
|
|
173
|
+
"""박마다 마디 첫 박인지. 잰 드롭을 닻으로 삼아 닻마다 4박을 다시 센다."""
|
|
174
|
+
n = len(beats)
|
|
175
|
+
anchors = sorted({int(np.argmin(np.abs(beats - d["t"]))) for d in drops})
|
|
176
|
+
if not anchors:
|
|
177
|
+
kick = song.low_onset[[song.frame(b) for b in beats]]
|
|
178
|
+
scores = [kick[p::4].mean() if len(kick[p::4]) else 0 for p in range(4)]
|
|
179
|
+
anchors = [int(np.argmax(scores))]
|
|
180
|
+
flags = np.zeros(n, bool)
|
|
181
|
+
for i in range(n):
|
|
182
|
+
prior = [a for a in anchors if a <= i]
|
|
183
|
+
a = prior[-1] if prior else anchors[0]
|
|
184
|
+
flags[i] = (i - a) % 4 == 0
|
|
185
|
+
return flags
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def novelty_cuts(song, downbeats, rs, taken):
|
|
189
|
+
"""음색·화성이 바뀌는 마디 경계(자기유사 체커보드)."""
|
|
190
|
+
if len(downbeats) < 12:
|
|
191
|
+
return []
|
|
192
|
+
frames = [song.frame(d) for d in downbeats]
|
|
193
|
+
feat = np.vstack([song.mfcc, song.chroma, *[song.fast[k][None, :] for k in BANDS]])
|
|
194
|
+
sync = librosa.util.sync(feat, frames, aggregate=np.mean)[:, 1:]
|
|
195
|
+
sync = (sync - sync.mean(1, keepdims=True)) / (sync.std(1, keepdims=True) + EPS)
|
|
196
|
+
sync /= np.linalg.norm(sync, axis=0, keepdims=True) + EPS
|
|
197
|
+
ssm = sync.T @ sync
|
|
198
|
+
K, m = 4, ssm.shape[0]
|
|
199
|
+
sign = np.r_[-np.ones(K), np.ones(K)]
|
|
200
|
+
kernel = np.outer(sign, sign)
|
|
201
|
+
nov = np.zeros(m)
|
|
202
|
+
for i in range(K, m - K):
|
|
203
|
+
nov[i] = (ssm[i - K : i + K, i - K : i + K] * kernel).sum()
|
|
204
|
+
nov = np.maximum(nov, 0)
|
|
205
|
+
if nov.max() <= 0:
|
|
206
|
+
return []
|
|
207
|
+
thr = nov[nov > 0].mean() + nov[nov > 0].std()
|
|
208
|
+
bar = np.median(np.diff(downbeats))
|
|
209
|
+
cuts = []
|
|
210
|
+
for i in range(1, m - 1):
|
|
211
|
+
if not (nov[i] > thr and nov[i] >= nov[i - 1] and nov[i] >= nov[i + 1]):
|
|
212
|
+
continue
|
|
213
|
+
# sync 는 첫 경계 앞을 한 칸으로 잡아서 i 번째 칸은 i 번째 다운비트에서 시작한다
|
|
214
|
+
t = downbeats[i]
|
|
215
|
+
fi = song.frame(t)
|
|
216
|
+
if not any(r[0] and r[1] <= fi < r[2] for r in rs):
|
|
217
|
+
continue
|
|
218
|
+
if any(abs(t - x) < 2 * bar for x in taken + [c["t"] for c in cuts]):
|
|
219
|
+
continue
|
|
220
|
+
cuts.append({"t": float(t), "strength": round(float(nov[i] / nov.max()), 2)})
|
|
221
|
+
return cuts
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def snap_back(t, downbeats, beats):
|
|
225
|
+
"""t 에서 끝난 구간의 마디 첫 박 — 마지막 한 방이 마디 첫 박에 떨어지고 바로 비는 곡이 많다."""
|
|
226
|
+
bar = np.median(np.diff(downbeats)) if len(downbeats) > 1 else 2.0
|
|
227
|
+
prior = downbeats[(downbeats <= t + 0.1) & (downbeats > t - bar / 2)]
|
|
228
|
+
if len(prior):
|
|
229
|
+
return float(prior[-1])
|
|
230
|
+
return float(beats[np.argmin(np.abs(beats - t))]) if len(beats) else t
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def build_sections(song, rs, ref, drops, beats, downbeats):
|
|
234
|
+
secs = []
|
|
235
|
+
first_on = next((r for r in rs if r[0]), None)
|
|
236
|
+
if first_on is None or song.t[first_on[1]] > 1.0:
|
|
237
|
+
secs.append({"t": 0.0, "kind": "intro"})
|
|
238
|
+
else:
|
|
239
|
+
secs.append({"t": 0.0, "kind": "main"})
|
|
240
|
+
for d in drops:
|
|
241
|
+
secs.append({"t": d["t"], "kind": "drop", "strength": d["strength"]})
|
|
242
|
+
for k in range(1, len(rs)):
|
|
243
|
+
if rs[k][0] or not rs[k - 1][0]:
|
|
244
|
+
continue
|
|
245
|
+
if (rs[k][2] - rs[k][1]) < nfr(2.0):
|
|
246
|
+
continue
|
|
247
|
+
later_on = any(r[0] for r in rs[k + 1 :])
|
|
248
|
+
prev = rs[k - 1]
|
|
249
|
+
loud = np.nonzero(song.fast["low"][prev[1] : rs[k][1] + nfr(0.5)] >= ref - 15)[0]
|
|
250
|
+
end = song.t[prev[1] + int(loud[-1])] if len(loud) else song.t[rs[k][1]]
|
|
251
|
+
secs.append({"t": snap_back(end, downbeats, beats), "kind": "break" if later_on else "outro"})
|
|
252
|
+
for c in novelty_cuts(song, downbeats, rs, [s["t"] for s in secs]):
|
|
253
|
+
secs.append({"t": c["t"], "kind": "main", "strength": c["strength"]})
|
|
254
|
+
secs.sort(key=lambda s: s["t"])
|
|
255
|
+
return secs
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def phrase_starts(sections, downbeats, end):
|
|
259
|
+
"""구간 시작마다 다시 센 4마디 묶음. 드롭 앞 구간은 드롭에서 거꾸로 센다."""
|
|
260
|
+
if len(downbeats) < 2:
|
|
261
|
+
return [s["t"] for s in sections]
|
|
262
|
+
bar = float(np.median(np.diff(downbeats)))
|
|
263
|
+
per = 4 if bar <= 2.0 else 2
|
|
264
|
+
out = []
|
|
265
|
+
for k, s in enumerate(sections):
|
|
266
|
+
a = s["t"]
|
|
267
|
+
b = sections[k + 1]["t"] if k + 1 < len(sections) else end
|
|
268
|
+
inside = [d for d in downbeats if a - bar / 4 <= d < b - bar / 4]
|
|
269
|
+
if k + 1 < len(sections) and sections[k + 1]["kind"] == "drop":
|
|
270
|
+
picks = inside[::-1][per - 1 :: per][::-1]
|
|
271
|
+
else:
|
|
272
|
+
picks = inside[::per]
|
|
273
|
+
out.append(a)
|
|
274
|
+
out += [p for p in picks if p - a > bar / 2]
|
|
275
|
+
return sorted(set(round(x, 4) for x in out))
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def energy_curves(song, a, b, hz):
|
|
279
|
+
step = 1.0 / hz
|
|
280
|
+
edges = np.arange(a, b + EPS, step)
|
|
281
|
+
out = {"hz": hz}
|
|
282
|
+
for k, p in song.power.items():
|
|
283
|
+
# 정규화는 곡 전체 기준 — 잘라 쓴 구간이 조용해도 1 까지 부풀지 않게
|
|
284
|
+
whole = db(uniform_filter1d(p, nfr(step)))
|
|
285
|
+
hi = np.percentile(whole, 99)
|
|
286
|
+
lo = hi - 45
|
|
287
|
+
vals = []
|
|
288
|
+
for e in edges[:-1]:
|
|
289
|
+
i, j = song.frame(e), song.frame(e + step)
|
|
290
|
+
v = db(p[i : max(j, i + 1)].mean())
|
|
291
|
+
vals.append(round(float(np.clip((v - lo) / (hi - lo), 0, 1)), 3))
|
|
292
|
+
out[k] = vals
|
|
293
|
+
return out
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def analyze(path, start, duration, hz, bpm_hint):
|
|
297
|
+
song = Song(path)
|
|
298
|
+
a = max(0.0, start)
|
|
299
|
+
b = song.length if duration is None else min(song.length, a + duration)
|
|
300
|
+
|
|
301
|
+
beats = track_beats(song, bpm_hint)
|
|
302
|
+
rs, ref = bass_runs(song)
|
|
303
|
+
drops = find_drops(song, rs)
|
|
304
|
+
# 드롭 바로 옆 박은 잰 드롭 시각으로 맞춘다 — 마커가 한 점에 겹치게
|
|
305
|
+
for d in drops:
|
|
306
|
+
j = int(np.argmin(np.abs(beats - d["t"])))
|
|
307
|
+
if abs(beats[j] - d["t"]) < 0.06:
|
|
308
|
+
beats[j] = d["t"]
|
|
309
|
+
flags = downbeat_flags(song, beats, drops)
|
|
310
|
+
downbeats = beats[flags]
|
|
311
|
+
sections = build_sections(song, rs, ref, drops, beats, downbeats)
|
|
312
|
+
phrases = phrase_starts(sections, downbeats, song.length)
|
|
313
|
+
|
|
314
|
+
def clip(ts):
|
|
315
|
+
return [round(float(t) - a, 4) for t in ts if a <= t < b]
|
|
316
|
+
|
|
317
|
+
secs = []
|
|
318
|
+
for s in sections:
|
|
319
|
+
if s["t"] < b:
|
|
320
|
+
secs.append({**s, "t": round(max(0.0, s["t"] - a), 4)})
|
|
321
|
+
while len(secs) > 1 and secs[1]["t"] == 0.0:
|
|
322
|
+
secs.pop(0)
|
|
323
|
+
# 박 간격은 프레임 단위로 떨어져 중앙값이 한쪽으로 쏠린다 — 박 번호에 대한 기울기로 잰다
|
|
324
|
+
bpm = 60.0 / float(np.polyfit(np.arange(len(beats)), beats, 1)[0]) if len(beats) > 1 else 0.0
|
|
325
|
+
out = {
|
|
326
|
+
"source": os.path.basename(path),
|
|
327
|
+
"from": round(a, 4),
|
|
328
|
+
"duration": round(b - a, 4),
|
|
329
|
+
"bpm": round(bpm, 2),
|
|
330
|
+
"beats": clip(beats),
|
|
331
|
+
"downbeats": clip(downbeats),
|
|
332
|
+
"bars": clip(downbeats),
|
|
333
|
+
"phrases": sorted(set([0.0] + clip(phrases))),
|
|
334
|
+
"sections": secs,
|
|
335
|
+
"drops": [round(d["t"] - a, 4) for d in drops if a <= d["t"] < b],
|
|
336
|
+
"energy": energy_curves(song, a, b, hz),
|
|
337
|
+
}
|
|
338
|
+
return out
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def report(o):
|
|
342
|
+
lines = [
|
|
343
|
+
f"bpm {o['bpm']} · 박 {len(o['beats'])} · 마디 {len(o['downbeats'])} · 프레이즈 {len(o['phrases'])} · 길이 {o['duration']}초 (곡 {o['from']}초부터)",
|
|
344
|
+
"드롭 " + (" · ".join(f"{t:.3f}" for t in o["drops"]) or "없음"),
|
|
345
|
+
"구간 " + " · ".join(f"{s['t']:.2f} {s['kind']}" for s in o["sections"]),
|
|
346
|
+
]
|
|
347
|
+
return "\n".join(lines)
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def main():
|
|
351
|
+
ap = argparse.ArgumentParser(description="곡 → beats.json")
|
|
352
|
+
ap.add_argument("audio")
|
|
353
|
+
ap.add_argument("--out", default="beats.json")
|
|
354
|
+
ap.add_argument("--from", dest="start", type=float, default=0.0)
|
|
355
|
+
ap.add_argument("--duration", type=float, default=None)
|
|
356
|
+
ap.add_argument("--hz", type=int, default=20)
|
|
357
|
+
ap.add_argument("--bpm", type=float, default=None, help="박 추적 시작값(반박·두배박으로 잘못 잡힐 때만)")
|
|
358
|
+
args = ap.parse_args()
|
|
359
|
+
if not os.path.isfile(args.audio):
|
|
360
|
+
print(f"곡이 없다: {args.audio}", file=sys.stderr)
|
|
361
|
+
return 2
|
|
362
|
+
o = analyze(args.audio, args.start, args.duration, args.hz, args.bpm)
|
|
363
|
+
out_dir = os.path.dirname(os.path.abspath(args.out))
|
|
364
|
+
o["source"] = os.path.relpath(os.path.abspath(args.audio), out_dir)
|
|
365
|
+
with open(args.out, "w") as f:
|
|
366
|
+
json.dump(o, f, ensure_ascii=False, separators=(",", ":"))
|
|
367
|
+
print(report(o), file=sys.stderr)
|
|
368
|
+
return 0
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
if __name__ == "__main__":
|
|
372
|
+
sys.exit(main())
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"""공식 가사에 시각을 붙인다 — 보컬을 떼고(demucs htdemucs) whisper 강제 정렬(stable-ts align)로 줄·어절 시각.
|
|
2
|
+
|
|
3
|
+
python align.py --audio 곡 --text 공식가사.txt --lang ko --out lyrics.json [--from 초 --duration 초] [--model large-v3-turbo]
|
|
4
|
+
|
|
5
|
+
글자는 공식 가사가 정본이다. 정렬이 돌려준 글자는 시각을 얻는 데만 쓰고, 어긋난 글자는 앞뒤 시각 사이로 메운다.
|
|
6
|
+
흐름은 natsu_mv/align_lyrics.py(demucs + stable-whisper align) 를 옮겼다. 결과 시각은 --from 을 0 으로 센다(beats.json 과 같다).
|
|
7
|
+
"""
|
|
8
|
+
import argparse
|
|
9
|
+
import difflib
|
|
10
|
+
import hashlib
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
import subprocess
|
|
14
|
+
import sys
|
|
15
|
+
import tempfile
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
CACHE = Path(os.environ.get("KF_LYRICS_CACHE", Path.home() / ".cache" / "kasaframe" / "lyrics"))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def log(msg):
|
|
22
|
+
print(f"[lyrics] {msg}", file=sys.stderr, flush=True)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def cut(audio, start, duration, out):
|
|
26
|
+
args = ["ffmpeg", "-v", "error", "-y"]
|
|
27
|
+
if start:
|
|
28
|
+
args += ["-ss", f"{start}"]
|
|
29
|
+
args += ["-i", audio]
|
|
30
|
+
if duration:
|
|
31
|
+
args += ["-t", f"{duration}"]
|
|
32
|
+
subprocess.run(args + ["-ac", "2", "-ar", "44100", out], check=True)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def separate(wav, device):
|
|
36
|
+
"""보컬만 — 같은 소리는 한 번만 뗀다(~/.cache/kasaframe/lyrics/<해시>).
|
|
37
|
+
demucs 명령은 torchaudio(→ torchcodec)로 저장해 ffmpeg 9 에서 죽어서, 모델만 빌려 soundfile 로 읽고 쓴다(demucs.separate 와 같은 정규화)"""
|
|
38
|
+
digest = hashlib.sha256(Path(wav).read_bytes()).hexdigest()[:16]
|
|
39
|
+
vocals = CACHE / digest / "vocals.wav"
|
|
40
|
+
if vocals.exists():
|
|
41
|
+
log(f"보컬 캐시 {vocals}")
|
|
42
|
+
return str(vocals)
|
|
43
|
+
log("보컬 떼는 중(demucs htdemucs)")
|
|
44
|
+
import soundfile as sf
|
|
45
|
+
import torch
|
|
46
|
+
from demucs.apply import apply_model
|
|
47
|
+
from demucs.pretrained import get_model
|
|
48
|
+
|
|
49
|
+
model = get_model("htdemucs")
|
|
50
|
+
model.eval()
|
|
51
|
+
data, sr = sf.read(wav, dtype="float32", always_2d=True)
|
|
52
|
+
if sr != model.samplerate:
|
|
53
|
+
raise SystemExit(f"{sr}Hz — demucs 는 {model.samplerate}Hz 를 받는다")
|
|
54
|
+
x = torch.from_numpy(data.T.copy())
|
|
55
|
+
if x.shape[0] == 1:
|
|
56
|
+
x = x.repeat(2, 1)
|
|
57
|
+
ref = x.mean(0)
|
|
58
|
+
mean, std = ref.mean(), ref.std() + 1e-8
|
|
59
|
+
with torch.no_grad():
|
|
60
|
+
out = apply_model(model, ((x - mean) / std)[None], device=device, split=True, overlap=0.25, progress=False)[0]
|
|
61
|
+
out = out * std + mean
|
|
62
|
+
vocals.parent.mkdir(parents=True, exist_ok=True)
|
|
63
|
+
sf.write(str(vocals), out[model.sources.index("vocals")].T.numpy(), model.samplerate)
|
|
64
|
+
return str(vocals)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def char_times(words):
|
|
68
|
+
"""정렬된 낱말을 글자마다 (글자, 시작, 끝)으로 — 낱말 안에서는 고르게 나눈다"""
|
|
69
|
+
out = []
|
|
70
|
+
for text, start, end in words:
|
|
71
|
+
chars = [c for c in text if not c.isspace()]
|
|
72
|
+
n = len(chars) or 1
|
|
73
|
+
for i, c in enumerate(chars):
|
|
74
|
+
out.append((c, start + (end - start) * i / n, start + (end - start) * (i + 1) / n))
|
|
75
|
+
return out
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def fill(times):
|
|
79
|
+
"""못 맞춘 글자(None)를 앞뒤 시각 사이로 메운다"""
|
|
80
|
+
known = [i for i, t in enumerate(times) if t is not None]
|
|
81
|
+
if not known:
|
|
82
|
+
raise SystemExit("정렬된 글자가 하나도 공식 가사와 안 맞는다 — 언어(--lang)·곡 구간(--from)을 본다")
|
|
83
|
+
for i, t in enumerate(times):
|
|
84
|
+
if t is not None:
|
|
85
|
+
continue
|
|
86
|
+
prev = max((k for k in known if k < i), default=None)
|
|
87
|
+
nxt = min((k for k in known if k > i), default=None)
|
|
88
|
+
if prev is None:
|
|
89
|
+
times[i] = (times[nxt][0], times[nxt][0])
|
|
90
|
+
elif nxt is None:
|
|
91
|
+
times[i] = (times[prev][1], times[prev][1])
|
|
92
|
+
else:
|
|
93
|
+
a, b = times[prev][1], times[nxt][0]
|
|
94
|
+
span = nxt - prev
|
|
95
|
+
times[i] = (a + (b - a) * (i - prev - 1) / span, a + (b - a) * (i - prev) / span)
|
|
96
|
+
return times
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def main():
|
|
100
|
+
ap = argparse.ArgumentParser()
|
|
101
|
+
ap.add_argument("--audio", required=True)
|
|
102
|
+
ap.add_argument("--text", required=True)
|
|
103
|
+
ap.add_argument("--lang", default="ko")
|
|
104
|
+
ap.add_argument("--out", required=True)
|
|
105
|
+
ap.add_argument("--from", dest="start", type=float, default=0.0)
|
|
106
|
+
ap.add_argument("--duration", type=float, default=0.0)
|
|
107
|
+
ap.add_argument("--model", default=os.environ.get("WHISPER_MODEL", "large-v3-turbo"))
|
|
108
|
+
ap.add_argument("--device", default=os.environ.get("WHISPER_DEVICE", "cpu"))
|
|
109
|
+
ap.add_argument("--no-separate", action="store_true", help="이미 보컬만 있는 소리")
|
|
110
|
+
a = ap.parse_args()
|
|
111
|
+
|
|
112
|
+
lines = [ln.strip() for ln in Path(a.text).read_text(encoding="utf-8").splitlines() if ln.strip()]
|
|
113
|
+
if not lines:
|
|
114
|
+
raise SystemExit(f"{a.text} 에 가사 줄이 없다")
|
|
115
|
+
|
|
116
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
117
|
+
wav = os.path.join(tmp, Path(a.audio).stem + ".wav")
|
|
118
|
+
cut(a.audio, a.start, a.duration, wav)
|
|
119
|
+
vocals = wav if a.no_separate else separate(wav, a.device)
|
|
120
|
+
|
|
121
|
+
import stable_whisper
|
|
122
|
+
|
|
123
|
+
log(f"정렬 — {a.model} · {a.device} · {a.lang} · 줄 {len(lines)}")
|
|
124
|
+
model = stable_whisper.load_model(a.model, device=a.device)
|
|
125
|
+
result = model.align(vocals, "\n".join(lines), language=a.lang, original_split=True)
|
|
126
|
+
words = [(w.word, float(w.start), float(w.end)) for seg in result.segments for w in seg.words]
|
|
127
|
+
|
|
128
|
+
aligned = char_times(words)
|
|
129
|
+
official = [(li, ci) for li, ln in enumerate(lines) for ci, c in enumerate(ln) if not c.isspace()]
|
|
130
|
+
off_chars = [lines[li][ci] for li, ci in official]
|
|
131
|
+
sm = difflib.SequenceMatcher(None, off_chars, [c for c, _, _ in aligned], autojunk=False)
|
|
132
|
+
times = [None] * len(off_chars)
|
|
133
|
+
matched = 0
|
|
134
|
+
for blk in sm.get_matching_blocks():
|
|
135
|
+
for k in range(blk.size):
|
|
136
|
+
_, s, e = aligned[blk.b + k]
|
|
137
|
+
times[blk.a + k] = (s, e)
|
|
138
|
+
matched += 1
|
|
139
|
+
times = fill(times)
|
|
140
|
+
log(f"글자 {len(off_chars)} 중 {matched} 이 정렬 글자와 맞았다" + ("" if matched == len(off_chars) else " — 나머지는 앞뒤 시각 사이로 메웠다"))
|
|
141
|
+
|
|
142
|
+
at = {}
|
|
143
|
+
for (li, ci), t in zip(official, times):
|
|
144
|
+
at[(li, ci)] = t
|
|
145
|
+
out_lines = []
|
|
146
|
+
for li, ln in enumerate(lines):
|
|
147
|
+
idx = [ci for ci, c in enumerate(ln) if not c.isspace()]
|
|
148
|
+
words_out = []
|
|
149
|
+
ci = 0
|
|
150
|
+
for w in ln.split():
|
|
151
|
+
first = ln.index(w, ci)
|
|
152
|
+
last = first + len(w) - 1
|
|
153
|
+
ci = last + 1
|
|
154
|
+
words_out.append({"w": w, "start": round(at[(li, first)][0], 3), "end": round(at[(li, last)][1], 3)})
|
|
155
|
+
out_lines.append({"text": ln, "start": round(at[(li, idx[0])][0], 3), "end": round(at[(li, idx[-1])][1], 3), "words": words_out})
|
|
156
|
+
|
|
157
|
+
data = {"source": os.path.abspath(a.audio), "from": a.start, "lang": a.lang, "aligner": f"demucs htdemucs + stable-ts align ({a.model})", "lines": out_lines}
|
|
158
|
+
Path(a.out).write_text(json.dumps(data, ensure_ascii=False, indent=1), encoding="utf-8")
|
|
159
|
+
for ln in out_lines:
|
|
160
|
+
log(f"{ln['start']:7.2f} - {ln['end']:7.2f} {ln['text']}")
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
if __name__ == "__main__":
|
|
164
|
+
main()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# kf lyrics align — 보컬 분리(demucs) + 공식 가사 강제 정렬(stable-ts 의 whisper align).
|
|
2
|
+
# MMS 강제 정렬 가중치는 CC-BY-NC(비상업)라 넣지 않는다. torch 가 3.13 이하에서 서서 kf setup lyrics 가 3.12 venv 를 만든다.
|
|
3
|
+
demucs==4.0.1
|
|
4
|
+
stable-ts==2.19.1
|
|
5
|
+
openai-whisper==20250625
|
|
6
|
+
torch==2.12.1
|
|
7
|
+
torchaudio==2.11.0
|
|
8
|
+
# torchaudio 의 저장은 torchcodec 이 맡는데 ffmpeg 4–8 판만 싣는다(ffmpeg 9 에서 죽는다) — 소리 읽고 쓰기는 soundfile 로 한다
|
|
9
|
+
soundfile==0.14.0
|