hyperframes 0.8.221 → 0.8.223
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/dist/{add-7CVO7K6M.js → add-PBLOPJHC.js} +16 -15
- package/dist/{agentPromptGenerator-YFC2SJLF.js → agentPromptGenerator-OD74HKYZ.js} +12 -11
- package/dist/{animatedGifPrep-YSMY5GU2.js → animatedGifPrep-QCG2BTDC.js} +12 -11
- package/dist/api.d.ts +5 -3
- package/dist/api.js +38 -26
- package/dist/{asset-ZVKHSO3M.js → asset-KHXCO4OR.js} +2 -2
- package/dist/{assetCataloger-6IBSEOK7.js → assetCataloger-ZX5WZTDQ.js} +13 -12
- package/dist/{audio-JUV3TVSW.js → audio-7AH2C6PB.js} +153 -1160
- package/dist/{auth-2J6FP462.js → auth-DJWMGXQB.js} +5 -5
- package/dist/{autoUpdate-ML6EZK6D.js → autoUpdate-KJMLYSHE.js} +2 -2
- package/dist/{backgroundChecks-MAWP2REX.js → backgroundChecks-XLVQMMXY.js} +3 -3
- package/dist/backgroundChecksWorker.js +3 -3
- package/dist/{batchRender-Z7MGNJZH.js → batchRender-UR67LI4H.js} +12 -9
- package/dist/{beats-LRZOZUUQ.js → beats-ISWSYNN6.js} +54 -22
- package/dist/{benchmark-XJWLDTIL.js → benchmark-7JUATINH.js} +12 -11
- package/dist/billing-VGKY3FMX.js +86 -0
- package/dist/{browser-STEVEWWA.js → browser-HNGQB47C.js} +3 -3
- package/dist/{bundleWithLocalizedFonts-WH63ZWUT.js → bundleWithLocalizedFonts-4XWX2XPS.js} +2 -2
- package/dist/{capture-VB5ID7HT.js → capture-GFDP5THL.js} +3 -3
- package/dist/{capture-U3ZT3GNI.js → capture-LBEGVQTJ.js} +80 -38
- package/dist/{captureCompositionFrame-MXJ3WO2R.js → captureCompositionFrame-5L3J4MZ4.js} +18 -17
- package/dist/{catalog-ICGHSRPZ.js → catalog-SNUTPI57.js} +16 -15
- package/dist/{catch-up-DJPQKXQB.js → catch-up-FE3HDMLJ.js} +4 -4
- package/dist/{check-TL7AGWPO.js → check-MQCBMOKA.js} +47 -45
- package/dist/{checkAudio-GPTU6EGB.js → checkAudio-6VPMLIY6.js} +22 -21
- package/dist/{checkBrowser-FG5DAW2R.js → checkBrowser-SHUVFQ4S.js} +45 -39
- package/dist/{chunk-YKMFCE5B.js → chunk-2GMHYOV3.js} +1 -1
- package/dist/{chunk-TNQCXU37.js → chunk-2HBB5U52.js} +1 -1
- package/dist/{chunk-UNQ3CVKW.js → chunk-3FGEDDSA.js} +27 -28
- package/dist/{chunk-HSHKLYDI.js → chunk-44IPXXSK.js} +7 -5
- package/dist/{chunk-TVT465RJ.js → chunk-44YG42L5.js} +144 -41
- package/dist/{chunk-ZBLSSWSE.js → chunk-45UOXUUH.js} +16 -3
- package/dist/chunk-4JRFMRCQ.js +288 -0
- package/dist/{chunk-M2F6VGCP.js → chunk-4XQQQ4KN.js} +85 -50
- package/dist/{chunk-6MUI2H6P.js → chunk-54Q3H2UQ.js} +5 -2
- package/dist/{chunk-67CALYTU.js → chunk-664JAO7C.js} +1 -1
- package/dist/{chunk-H3HC6U4I.js → chunk-6LE7K3YM.js} +17 -14
- package/dist/{chunk-Z7YQEDA5.js → chunk-7LKEHM2R.js} +1 -1
- package/dist/{chunk-I45R2REQ.js → chunk-7XWCCFYW.js} +1 -1
- package/dist/{chunk-L63FJVSC.js → chunk-A2KNKY4Z.js} +1 -1
- package/dist/{chunk-MEB6HWBM.js → chunk-A5WWEW6U.js} +2 -2
- package/dist/{chunk-PBNWRWKA.js → chunk-AKMY4QVI.js} +2 -1
- package/dist/{chunk-OPKSVV4G.js → chunk-AKTI2SHL.js} +2 -2
- package/dist/{chunk-VZBJ5BQF.js → chunk-AW3XJY4S.js} +1 -1
- package/dist/chunk-AW7UW2Z7.js +312 -0
- package/dist/{chunk-DWTFLQ3P.js → chunk-B2ZZYISD.js} +4 -2
- package/dist/{chunk-625I5VBE.js → chunk-B5HFCGI7.js} +2 -2
- package/dist/{chunk-AZXDEC2G.js → chunk-B6F33PUK.js} +6 -8
- package/dist/{chunk-AW7A27JM.js → chunk-BDEBKAD2.js} +1 -1
- package/dist/{chunk-322M35EB.js → chunk-BN75GXZM.js} +3 -3
- package/dist/{chunk-KSC4O2RY.js → chunk-C2KEGBR3.js} +53 -4
- package/dist/{chunk-6YW3FEHC.js → chunk-C466I3DT.js} +9 -8
- package/dist/{chunk-M2BCU4Y5.js → chunk-CXEU6XNL.js} +6 -20
- package/dist/{chunk-KQPP4NIZ.js → chunk-CYE2NNFF.js} +2 -2
- package/dist/{chunk-U6WH572X.js → chunk-DFK4RMNE.js} +5 -5
- package/dist/chunk-DY7PQLIE.js +248 -0
- package/dist/chunk-EF735J3K.js +59 -0
- package/dist/{chunk-XFMO3BEN.js → chunk-EHZESMRB.js} +18 -6
- package/dist/chunk-EJOFIHX4.js +46 -0
- package/dist/{chunk-3422KMTD.js → chunk-EPQC3FGZ.js} +4 -0
- package/dist/{chunk-2ZNURTH5.js → chunk-EX75C5HT.js} +4459 -4312
- package/dist/{chunk-4ZM727AO.js → chunk-FKBWONRY.js} +5 -5
- package/dist/{chunk-YISDQ7YP.js → chunk-FORV75JT.js} +26 -14
- package/dist/{chunk-ZKPRJPWN.js → chunk-G5KX4X6W.js} +59 -59
- package/dist/{chunk-SGTEKMJW.js → chunk-HOTXWVVP.js} +93 -5
- package/dist/{chunk-LYZB5CJN.js → chunk-HT3D5AKG.js} +160 -19
- package/dist/{chunk-BIROA7JM.js → chunk-HYRPH6LL.js} +7 -6
- package/dist/{chunk-35JKCWYI.js → chunk-I6OY5MS6.js} +1 -1
- package/dist/{chunk-S5GOFDX5.js → chunk-IJI2JNN7.js} +1 -1
- package/dist/{chunk-SAKL7SZH.js → chunk-IQ7FABPU.js} +3 -3
- package/dist/{chunk-YV2QQUTL.js → chunk-JNQCM6CR.js} +2 -2
- package/dist/{chunk-TMK3MW7B.js → chunk-JO4LHFFP.js} +10 -10
- package/dist/chunk-JTZHDD63.js +70 -0
- package/dist/{chunk-YSZ4VMXI.js → chunk-K5GMPWMG.js} +1 -1
- package/dist/{chunk-ROVRC3CG.js → chunk-KCDWRMTC.js} +5 -5
- package/dist/{chunk-74E7EHVH.js → chunk-KJGYQVFD.js} +1 -1
- package/dist/{chunk-3STL4WJ6.js → chunk-KT2WLSX5.js} +19 -10
- package/dist/{chunk-OMLDAF44.js → chunk-KWYK65GR.js} +9 -8
- package/dist/{chunk-F6WHVEUS.js → chunk-LAIGIOEA.js} +5 -1
- package/dist/{chunk-3PJ3HVLG.js → chunk-LV5AVW6U.js} +1 -1
- package/dist/{chunk-XETZLYGW.js → chunk-M4UVOUWC.js} +2 -2
- package/dist/{chunk-DMCU2ELU.js → chunk-M7HNGAWN.js} +3 -3
- package/dist/chunk-MEJH7VEA.js +63 -0
- package/dist/{chunk-MYXFBIJO.js → chunk-MTVL7FWZ.js} +1 -1
- package/dist/{chunk-MYNBV7WG.js → chunk-MUHOFRGW.js} +1 -1
- package/dist/{chunk-7DVR3DL3.js → chunk-N6XKBBT5.js} +8 -8
- package/dist/{chunk-OOEOJPFY.js → chunk-NLWG5TU7.js} +2 -2
- package/dist/chunk-NZZQCWUC.js +205 -0
- package/dist/{chunk-ZOLKM3VZ.js → chunk-OL2C3ODS.js} +9 -9
- package/dist/{chunk-QLQVQQP6.js → chunk-OVINGNLQ.js} +3 -3
- package/dist/{chunk-MXVH6UW6.js → chunk-OWFSGDQS.js} +6 -57
- package/dist/chunk-OZM6VLD7.js +71 -0
- package/dist/{chunk-5YT2KHPO.js → chunk-P5QGZMGC.js} +2 -2
- package/dist/{chunk-NYOQP6DO.js → chunk-PBPHKD56.js} +1 -1
- package/dist/chunk-PHEPL7OX.js +1048 -0
- package/dist/{chunk-AZI2T2KO.js → chunk-PX7Y4HMM.js} +1 -1
- package/dist/{chunk-IDWJJ7PP.js → chunk-QNLHDYYO.js} +2 -2
- package/dist/{chunk-N4XNRHFM.js → chunk-QNW43LWB.js} +1 -1
- package/dist/{chunk-24F7TOW2.js → chunk-QU5OYMTB.js} +140 -54
- package/dist/chunk-QZGKKQ77.js +570 -0
- package/dist/{chunk-NQOCM4KQ.js → chunk-RKVKFXYB.js} +3 -3
- package/dist/{chunk-Y4GLFHO5.js → chunk-RORIFIUW.js} +1 -1
- package/dist/{chunk-MESSJFK3.js → chunk-RWSVSCOP.js} +38 -28
- package/dist/chunk-RZ6CXJ56.js +24 -0
- package/dist/chunk-SDBVVDBW.js +113 -0
- package/dist/{chunk-YBNF5ZOC.js → chunk-SFS5BTQ3.js} +1 -1
- package/dist/{chunk-BQNTY7J5.js → chunk-SNFVQDKE.js} +1 -1
- package/dist/{chunk-J74ZUXVU.js → chunk-SWC3QIEH.js} +1 -1
- package/dist/{chunk-D2RQVJLZ.js → chunk-SX7ESVCQ.js} +5 -29
- package/dist/{chunk-P6FGS4U6.js → chunk-UFYWGUUV.js} +6 -6
- package/dist/{chunk-GSCFMG4C.js → chunk-UGUWSAJT.js} +3 -3
- package/dist/chunk-UQECNXFA.js +5013 -0
- package/dist/{chunk-XDTCPMR3.js → chunk-UQVAAEPQ.js} +2 -2
- package/dist/{chunk-NHXGFQWQ.js → chunk-UVF4U3ZF.js} +1 -1
- package/dist/{chunk-YSTBSLWY.js → chunk-VBCBHDIW.js} +1 -1
- package/dist/chunk-VJM6NX54.js +250 -0
- package/dist/{chunk-5SKC4G26.js → chunk-VMRQDPFL.js} +1 -1
- package/dist/chunk-WGOIJN57.js +95 -0
- package/dist/{chunk-RVCWVOXM.js → chunk-WQLTKHPP.js} +3 -3
- package/dist/{chunk-RVIMLJXC.js → chunk-WUXDIF5D.js} +60 -23
- package/dist/{chunk-QYUXDFJY.js → chunk-WWOHLNFO.js} +12 -10
- package/dist/{chunk-JGZUG5V4.js → chunk-XZEHFUQF.js} +2 -2
- package/dist/{chunk-6HKUUBAV.js → chunk-Y4INSXS7.js} +2 -2
- package/dist/{chunk-O7WR4AHX.js → chunk-ZEKV5T3I.js} +14 -14
- package/dist/{clean-3NMJWZXK.js → clean-JZOPMJMV.js} +27 -26
- package/dist/cli.js +59 -56
- package/dist/{cloud-CB3NYNUR.js → cloud-VMPF2KMA.js} +4 -4
- package/dist/{cloudrun-2CTKCIXV.js → cloudrun-LA2FKS2F.js} +10 -9
- package/dist/commands/layout-audit.browser.js +19 -3
- package/dist/commands/motion-signature.browser.js +8 -4
- package/dist/{compare-FVY3AMTT.js → compare-IQCFSC5Z.js} +37 -36
- package/dist/{compiler-SEQRWEEN.js → compiler-J7OZQIPD.js} +8 -8
- package/dist/{component-AEMJRROX.js → component-TRGBVFCI.js} +3 -3
- package/dist/{compositions-NRBSIBGZ.js → compositions-FOC2CAZX.js} +18 -17
- package/dist/curve-ID3Z522S.js +329 -0
- package/dist/cuts-MWHQSE2Z.js +123 -0
- package/dist/{delete-T4E53ELR.js → delete-47KZ7PLI.js} +5 -5
- package/dist/{deploy-PUF2DW3H.js → deploy-NTNEO4TI.js} +8 -8
- package/dist/describeProject-WWREIVQV.js +56 -0
- package/dist/{deterministicFonts-2ISM3LMW.js → deterministicFonts-LV2JMOJL.js} +2 -2
- package/dist/diff-GH4KCQGQ.js +1825 -0
- package/dist/{dist-VARV35QH.js → dist-24QQO5IL.js} +6 -6
- package/dist/{dist-B6C3DU6I.js → dist-XW7FATO6.js} +7 -6
- package/dist/{doctor-FVBU575B.js → doctor-4ZH7WFU6.js} +16 -15
- package/dist/{dotEnv-BGFXSQOA.js → dotEnv-33RDHX7P.js} +1 -1
- package/dist/energy-2C65KXBH.js +134 -0
- package/dist/{events-RSPDI7FX.js → events-FUFFA55P.js} +3 -3
- package/dist/{events-DZ5PRR6F.js → events-Q3EBOW2Y.js} +2 -2
- package/dist/events-QO5G2VCC.js +221 -0
- package/dist/extract-Z6TLBM5B.js +309 -0
- package/dist/face-WI6BPPUG.js +171 -0
- package/dist/{feedback-AALA3OA7.js → feedback-M5GZWDXP.js} +16 -15
- package/dist/{ffmpeg-YXKE5CUE.js → ffmpeg-27H6P7ZU.js} +13 -12
- package/dist/{figma-37R727XZ.js → figma-AI6TSWVO.js} +3 -3
- package/dist/fontLocalizeCli.js +16 -15
- package/dist/frames-WUTLVZIR.js +352 -0
- package/dist/generate-3CJREF5U.js +74 -0
- package/dist/{get-L3VKJ6JF.js → get-KTDRE33B.js} +5 -5
- package/dist/{gpuPolicy-6QIFFWAI.js → gpuPolicy-Z4MM64HY.js} +12 -11
- package/dist/{grade-compare-7IN5QDJD.js → grade-compare-IM7Z7HWI.js} +41 -37
- package/dist/{heifImagePrep-AWII25PM.js → heifImagePrep-CXI2ZMUX.js} +13 -12
- package/dist/{help-B4MB7MWW.js → help-5FR6BRLR.js} +7 -1
- package/dist/{history-TQO6AWEQ.js → history-5P5YVP5H.js} +17 -8
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +72 -72
- package/dist/hyperframes-player.global.js +3 -3
- package/dist/hyperframes-slideshow.global.js +8 -8
- package/dist/index-gen-OPMQ5WSN.js +61 -0
- package/dist/{info-7CBHVXSG.js → info-5ZGNJJVA.js} +11 -10
- package/dist/{init-D7HKPQ5A.js → init-NWIAEYSX.js} +35 -33
- package/dist/{inspect-VHDQL55M.js → inspect-HBLAVW5C.js} +38 -36
- package/dist/{installer-EJNLL6SV.js → installer-KVFTBZZ5.js} +8 -7
- package/dist/{keyframes-IFLBMAJP.js → keyframes-LFCLUY2R.js} +7 -7
- package/dist/{lambda-I7EQULHC.js → lambda-RFWTTMLU.js} +19 -18
- package/dist/{layout-MOCEANRO.js → layout-WOG2Y5ND.js} +38 -36
- package/dist/{lint-HFXGSQKN.js → lint-7MALXMMF.js} +12 -12
- package/dist/{lintProject-VCDI6A2W.js → lintProject-6H64SX3V.js} +6 -6
- package/dist/{list-OFYIXVON.js → list-XRYAT24W.js} +5 -5
- package/dist/{localPage-QOOQ5YA2.js → localPage-IN36JVJU.js} +12 -11
- package/dist/{login-WAG7B4PM.js → login-32WGVGTM.js} +15 -9
- package/dist/{logout-6VFJ7WMW.js → logout-SLI6YTHI.js} +2 -2
- package/dist/look-ZWVE6JO3.js +180 -0
- package/dist/{manager-34U5CEFB.js → manager-SFL6GLYX.js} +14 -12
- package/dist/manifest-QSJYVERU.js +49 -0
- package/dist/measure-Q74BJTRQ.js +46 -0
- package/dist/{media-treatment-2TLX6NKS.js → media-treatment-3R6DYEAZ.js} +24 -23
- package/dist/{media-use-ZNTB7W6N.js → media-use-ZM2WCRQC.js} +9 -5
- package/dist/{models-M2F4WTAR.js → models-NNC53UPU.js} +16 -15
- package/dist/{motionShot-6WCTCV4W.js → motionShot-5BI5JFUP.js} +21 -20
- package/dist/{normalize-QJVXFMWO.js → normalize-MBNGRVQA.js} +2 -1
- package/dist/{normalize-audio-T6PIPWOT.js → normalize-audio-6Z2WN56Q.js} +15 -14
- package/dist/{open-BC5METIY.js → open-5NCEN6RC.js} +15 -14
- package/dist/{parakeetRunner-UXVY7PV2.js → parakeetRunner-DH3XKR3C.js} +19 -17
- package/dist/{pipeline-GJAJPWPB.js → pipeline-CGEGQAPH.js} +15 -14
- package/dist/{play-UCIRUHCU.js → play-K37BN736.js} +28 -27
- package/dist/{policies-J5BWAZHM.js → policies-U4PFXF5E.js} +4 -2
- package/dist/{preflight-GVRYYIH5.js → preflight-CG7H3D5B.js} +13 -12
- package/dist/{present-46QLZOK4.js → present-KQ53DOHA.js} +24 -23
- package/dist/{preview-HWXMP7WL.js → preview-V7CYHL6U.js} +26 -25
- package/dist/probe-JVW2MPY3.js +178 -0
- package/dist/{producer-2PBHUE5O.js → producer-UD32S7PX.js} +1 -1
- package/dist/{projectConfig-C4S3LBBX.js → projectConfig-WXCB5AZE.js} +10 -9
- package/dist/{publication-GESNVVMS.js → publication-KG4UDZRM.js} +6 -5
- package/dist/{publish-IBY26S3T.js → publish-MEQB543T.js} +22 -21
- package/dist/{refresh-I6ITGHKL.js → refresh-2LU4XDL7.js} +2 -2
- package/dist/{remove-background-3OBWOHVZ.js → remove-background-FSV5KQK3.js} +16 -15
- package/dist/{render-LSI5WXS7.js → render-O4S4SURS.js} +10 -9
- package/dist/{render-SR5RISLU.js → render-SQXZAGPQ.js} +160 -46
- package/dist/{render-3F6GQ5WW.js → render-SY4AXKXC.js} +40 -39
- package/dist/{render-batch-HV4W3PZM.js → render-batch-GTZQUB3H.js} +10 -9
- package/dist/renderSetupWorker.js +6 -6
- package/dist/{resolver-R5X3HAPE.js → resolver-BQZNCVJS.js} +8 -7
- package/dist/run-67OPNJGD.js +31 -0
- package/dist/{screenshotCapture-U3IYWTDB.js → screenshotCapture-4THETOMD.js} +2 -1
- package/dist/{sherpa-2Q6U4ZFY.js → sherpa-KH3PJAUG.js} +18 -16
- package/dist/skills/hyperframes-cli/references/beats.md +1 -1
- package/dist/skills/media-use/SKILL.md +20 -21
- package/dist/skills/media-use/audio/scripts/lib/gemini-tts.mjs +13 -1
- package/dist/skills/media-use/audio/scripts/lib/gemini-tts.test.mjs +10 -0
- package/dist/skills/media-use/audio/scripts/lib/heygen.mjs +26 -1
- package/dist/skills/media-use/audio/scripts/lib/heygen.test.mjs +33 -0
- package/dist/skills/media-use/references/heygen.md +58 -0
- package/dist/skills/media-use/references/operations.md +9 -6
- package/dist/skills/media-use/references/setup-providers.md +11 -12
- package/dist/skills/media-use/scripts/lib/index-gen.d.mts +1 -0
- package/dist/skills/media-use/scripts/lib/manifest.d.mts +21 -0
- package/dist/{skills-FSGXQSHA.js → skills-FTZZJGAB.js} +5 -5
- package/dist/{skillsUpdateCheck-UW6643XX.js → skillsUpdateCheck-LZPD2CZI.js} +3 -3
- package/dist/{slideshow-SJGK4RQS.js → slideshow-ARJR22W4.js} +1 -1
- package/dist/{snapshot-HFPB34Y7.js → snapshot-4BORZ3ED.js} +60 -47
- package/dist/{src-VMTQQUUP.js → src-6ZOFAM3F.js} +21 -14
- package/dist/{src-ROWFWCEN.js → src-D7AO7PGH.js} +12 -11
- package/dist/{staticProjectServer-4TGZJIWN.js → staticProjectServer-Q23A6XU2.js} +25 -24
- package/dist/{status-4AAPTTRW.js → status-VIJRZ4ZK.js} +34 -9
- package/dist/studio/assets/hyperframes-player-D0W1SNqK.js +478 -0
- package/dist/studio/assets/{index-BDE7dwov.js → index-DD9KJoEr.js} +119 -119
- package/dist/studio/assets/{index-D0jGq2dS.js → index-mbwAH5iR.js} +1 -1
- package/dist/studio/index.html +1 -1
- package/dist/{studio-api-TSHXVZ6R.js → studio-api-XVVJZ7YT.js} +24 -19
- package/dist/{studioServer-74ZBLNP2.js → studioServer-6HG3AMTW.js} +77 -114
- package/dist/sync-Q5SRIL7V.js +115 -0
- package/dist/{telemetry-3NDLZOPR.js → telemetry-VXPSJ3X3.js} +3 -3
- package/dist/templates/blank/index.html +1 -1
- package/dist/templates/from-file/index.html +1 -1
- package/dist/{timeline-5IFZJU7M.js → timeline-6477OWFA.js} +31 -26
- package/dist/{tokens-UFNPQVLS.js → tokens-ZUUNEDKT.js} +2 -2
- package/dist/{transcribe-7KQAUHEN.js → transcribe-HA4UGLKO.js} +17 -15
- package/dist/{transcribe-NAXKBIPW.js → transcribe-ITVANIDK.js} +41 -23
- package/dist/{tts-BVTJEP72.js → tts-KMZPHG3K.js} +1 -1
- package/dist/{updateCheck-KDSFL3XX.js → updateCheck-SVADAQ43.js} +2 -2
- package/dist/{upgrade-EXX4C35N.js → upgrade-WKW4FDNF.js} +2 -2
- package/dist/{urlDownloader-4UFCIAPH.js → urlDownloader-VWHCESDD.js} +11 -10
- package/dist/{validate-QYOHY3N6.js → validate-7VG2RLP2.js} +31 -30
- package/dist/{video-HRL3V2R5.js → video-LM3FYHGG.js} +13 -12
- package/dist/warmCheck.js +47 -45
- package/package.json +1 -1
- package/dist/chunk-Q3PPGPEA.js +0 -5061
- package/dist/studio/assets/hyperframes-player-B_wvwarc.js +0 -478
- package/dist/{chunk-NOH32H42.js → chunk-HBAUU3IK.js} +124 -124
- package/dist/{chunk-NHA4NRBE.js → chunk-T5ELONXY.js} +0 -0
- package/dist/{destroy-BQ5R7LUF.js → destroy-6NWJMQX2.js} +4 -4
- package/dist/{synthesize-4JC74JW5.js → synthesize-DIT2SR3D.js} +5 -5
|
@@ -4,63 +4,57 @@ import { dirname as __hf_dirname } from "node:path";
|
|
|
4
4
|
var require = __hf_createRequire(import.meta.url);
|
|
5
5
|
var __filename = __hf_fileURLToPath(import.meta.url);
|
|
6
6
|
var __dirname = __hf_dirname(__filename);
|
|
7
|
+
import {
|
|
8
|
+
DEFAULT_CAPABILITIES,
|
|
9
|
+
analyzeTargets,
|
|
10
|
+
previewTarget,
|
|
11
|
+
runFile,
|
|
12
|
+
serviceAccess,
|
|
13
|
+
serviceFailure
|
|
14
|
+
} from "./chunk-PHEPL7OX.js";
|
|
7
15
|
import {
|
|
8
16
|
uploadAssetViaDirectUpload
|
|
9
17
|
} from "./chunk-CE7EQUBV.js";
|
|
10
18
|
import {
|
|
11
19
|
HyperframesCloudClient
|
|
12
20
|
} from "./chunk-6A45RKAK.js";
|
|
13
|
-
import {
|
|
14
|
-
describeProject
|
|
15
|
-
} from "./chunk-ZOLKM3VZ.js";
|
|
16
|
-
import "./chunk-LLMSX6V6.js";
|
|
17
21
|
import {
|
|
18
22
|
PITCH_RATE,
|
|
19
|
-
STEADY_BEAT_CONFIDENCE,
|
|
20
23
|
bandFramesOf,
|
|
21
|
-
envelope,
|
|
22
|
-
localBeatEvidence,
|
|
23
24
|
loudness,
|
|
24
25
|
medianInterval,
|
|
25
26
|
pitchTrack,
|
|
26
|
-
rhythm
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
tempoOf
|
|
33
|
-
} from "./chunk-NOH32H42.js";
|
|
27
|
+
rhythm
|
|
28
|
+
} from "./chunk-HBAUU3IK.js";
|
|
29
|
+
import {
|
|
30
|
+
describeProject
|
|
31
|
+
} from "./chunk-OL2C3ODS.js";
|
|
32
|
+
import "./chunk-LLMSX6V6.js";
|
|
34
33
|
import {
|
|
35
34
|
ensureDOMParser
|
|
36
35
|
} from "./chunk-ZBAF6L74.js";
|
|
37
|
-
import {
|
|
38
|
-
refreshIfNeeded,
|
|
39
|
-
resolveCloudBaseUrl
|
|
40
|
-
} from "./chunk-YSTBSLWY.js";
|
|
41
|
-
import {
|
|
42
|
-
buildAuthHeaders,
|
|
43
|
-
tryResolveCredential
|
|
44
|
-
} from "./chunk-MESSJFK3.js";
|
|
45
36
|
import {
|
|
46
37
|
downloadToFile
|
|
47
38
|
} from "./chunk-NO6F7CLR.js";
|
|
39
|
+
import "./chunk-VBCBHDIW.js";
|
|
40
|
+
import "./chunk-RWSVSCOP.js";
|
|
48
41
|
import {
|
|
49
42
|
decodeAudio,
|
|
50
43
|
probeAudio
|
|
51
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-SWC3QIEH.js";
|
|
52
45
|
import {
|
|
53
46
|
loadTranscript
|
|
54
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-54Q3H2UQ.js";
|
|
55
48
|
import {
|
|
56
49
|
resolveProject
|
|
57
|
-
} from "./chunk-
|
|
58
|
-
import "./chunk-
|
|
59
|
-
import "./chunk-
|
|
50
|
+
} from "./chunk-SNFVQDKE.js";
|
|
51
|
+
import "./chunk-AW3XJY4S.js";
|
|
52
|
+
import "./chunk-7LKEHM2R.js";
|
|
60
53
|
import "./chunk-5ZBMHUY2.js";
|
|
54
|
+
import "./chunk-EHZESMRB.js";
|
|
61
55
|
import "./chunk-A4ZTSQLW.js";
|
|
62
|
-
import "./chunk-
|
|
63
|
-
import "./chunk-
|
|
56
|
+
import "./chunk-LAIGIOEA.js";
|
|
57
|
+
import "./chunk-45UOXUUH.js";
|
|
64
58
|
import "./chunk-PXVQOMKL.js";
|
|
65
59
|
import "./chunk-EQGKUPBJ.js";
|
|
66
60
|
import "./chunk-VLA6UJGH.js";
|
|
@@ -74,14 +68,15 @@ import "./chunk-S3S4TGEH.js";
|
|
|
74
68
|
import "./chunk-WYKRGEDD.js";
|
|
75
69
|
import "./chunk-54HJ63Q2.js";
|
|
76
70
|
import "./chunk-2GICKZ3I.js";
|
|
77
|
-
import "./chunk-
|
|
71
|
+
import "./chunk-4XQQQ4KN.js";
|
|
78
72
|
import "./chunk-Z5J67X44.js";
|
|
79
73
|
import "./chunk-5S7W3TUO.js";
|
|
80
74
|
import "./chunk-D3MUHMFG.js";
|
|
81
|
-
import "./chunk-
|
|
75
|
+
import "./chunk-FKBWONRY.js";
|
|
82
76
|
import "./chunk-YWRUQ7XZ.js";
|
|
83
|
-
import "./chunk-
|
|
84
|
-
import "./chunk-
|
|
77
|
+
import "./chunk-OWFSGDQS.js";
|
|
78
|
+
import "./chunk-MEJH7VEA.js";
|
|
79
|
+
import "./chunk-UQECNXFA.js";
|
|
85
80
|
import "./chunk-VC76R6W2.js";
|
|
86
81
|
import "./chunk-OFQWTKPW.js";
|
|
87
82
|
import "./chunk-RQVDTPGD.js";
|
|
@@ -91,26 +86,26 @@ import "./chunk-FXMKHHPO.js";
|
|
|
91
86
|
import "./chunk-LAGZGKKN.js";
|
|
92
87
|
import "./chunk-K4MJX7SR.js";
|
|
93
88
|
import "./chunk-WE42NVH7.js";
|
|
94
|
-
import "./chunk-
|
|
95
|
-
import "./chunk-CZGHFATT.js";
|
|
89
|
+
import "./chunk-HT3D5AKG.js";
|
|
96
90
|
import {
|
|
97
91
|
findFfBinary
|
|
98
|
-
} from "./chunk-
|
|
92
|
+
} from "./chunk-HYRPH6LL.js";
|
|
99
93
|
import {
|
|
100
94
|
resolveAuthoredAssetFile
|
|
101
|
-
} from "./chunk-
|
|
102
|
-
import "./chunk-
|
|
103
|
-
import "./chunk-
|
|
95
|
+
} from "./chunk-AKMY4QVI.js";
|
|
96
|
+
import "./chunk-CZGHFATT.js";
|
|
97
|
+
import "./chunk-C2KEGBR3.js";
|
|
98
|
+
import "./chunk-T5ELONXY.js";
|
|
104
99
|
import "./chunk-FR7YBU3H.js";
|
|
105
100
|
import "./chunk-DPVXBVLL.js";
|
|
106
101
|
import "./chunk-GWTIFRF5.js";
|
|
107
102
|
import "./chunk-2RY2LWAA.js";
|
|
108
|
-
import "./chunk-
|
|
103
|
+
import "./chunk-EPQC3FGZ.js";
|
|
109
104
|
import "./chunk-WC4MTXGN.js";
|
|
110
105
|
import "./chunk-FBN2M2HK.js";
|
|
111
106
|
import {
|
|
112
107
|
withMeta
|
|
113
|
-
} from "./chunk-
|
|
108
|
+
} from "./chunk-K5GMPWMG.js";
|
|
114
109
|
import "./chunk-BR2JQQC5.js";
|
|
115
110
|
import "./chunk-BLBMPEBX.js";
|
|
116
111
|
import "./chunk-ISN5GRYI.js";
|
|
@@ -120,7 +115,7 @@ import {
|
|
|
120
115
|
} from "./chunk-DP5LF7GF.js";
|
|
121
116
|
import "./chunk-J3RXEDR2.js";
|
|
122
117
|
import "./chunk-QBXDU24O.js";
|
|
123
|
-
import "./chunk-
|
|
118
|
+
import "./chunk-P5QGZMGC.js";
|
|
124
119
|
import "./chunk-E63BDV4Z.js";
|
|
125
120
|
import "./chunk-G7VEYUZ2.js";
|
|
126
121
|
import "./chunk-XT6MXC7A.js";
|
|
@@ -128,665 +123,11 @@ import "./chunk-7KDQAD2W.js";
|
|
|
128
123
|
import "./chunk-M2WBOQ2Q.js";
|
|
129
124
|
|
|
130
125
|
// src/commands/audio.ts
|
|
131
|
-
import { join as
|
|
132
|
-
|
|
133
|
-
// src/audio/analysis/providers/api.ts
|
|
134
|
-
import { randomUUID } from "crypto";
|
|
135
|
-
|
|
136
|
-
// src/audio/analysis/providers/shared.ts
|
|
137
|
-
import { execFile } from "child_process";
|
|
138
|
-
import { mkdtemp, rm, writeFile } from "fs/promises";
|
|
139
|
-
import { tmpdir } from "os";
|
|
140
|
-
import { join } from "path";
|
|
141
|
-
import { promisify } from "util";
|
|
142
|
-
var runFile = promisify(execFile);
|
|
143
|
-
var unavailable = (reason) => ({ ok: false, reason });
|
|
144
|
-
var AVAILABLE = { ok: true };
|
|
145
|
-
function encodeWav(signal) {
|
|
146
|
-
const channels = signal.channels.length;
|
|
147
|
-
const frames = signal.channels[0]?.length ?? 0;
|
|
148
|
-
const data = frames * channels * 2;
|
|
149
|
-
const wav = Buffer.alloc(44 + data);
|
|
150
|
-
wav.write("RIFF", 0);
|
|
151
|
-
wav.writeUInt32LE(36 + data, 4);
|
|
152
|
-
wav.write("WAVEfmt ", 8);
|
|
153
|
-
wav.writeUInt32LE(16, 16);
|
|
154
|
-
wav.writeUInt16LE(1, 20);
|
|
155
|
-
wav.writeUInt16LE(channels, 22);
|
|
156
|
-
wav.writeUInt32LE(signal.sampleRate, 24);
|
|
157
|
-
wav.writeUInt32LE(signal.sampleRate * channels * 2, 28);
|
|
158
|
-
wav.writeUInt16LE(channels * 2, 32);
|
|
159
|
-
wav.writeUInt16LE(16, 34);
|
|
160
|
-
wav.write("data", 36);
|
|
161
|
-
wav.writeUInt32LE(data, 40);
|
|
162
|
-
let offset = 44;
|
|
163
|
-
for (let i = 0; i < frames; i++)
|
|
164
|
-
for (const channel of signal.channels) {
|
|
165
|
-
const sample = Math.max(-1, Math.min(1, channel[i]));
|
|
166
|
-
wav.writeInt16LE(Math.round(sample * 32767), offset);
|
|
167
|
-
offset += 2;
|
|
168
|
-
}
|
|
169
|
-
return wav;
|
|
170
|
-
}
|
|
171
|
-
async function withWavFile(signal, use) {
|
|
172
|
-
const dir = await mkdtemp(join(tmpdir(), "hf-audio-"));
|
|
173
|
-
try {
|
|
174
|
-
const path = join(dir, "audio.wav");
|
|
175
|
-
await writeFile(path, encodeWav(signal));
|
|
176
|
-
return await use(path);
|
|
177
|
-
} finally {
|
|
178
|
-
await rm(dir, { recursive: true, force: true });
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
function perSignal(compute) {
|
|
182
|
-
const answers = /* @__PURE__ */ new WeakMap();
|
|
183
|
-
return (signal) => {
|
|
184
|
-
let answer = answers.get(signal);
|
|
185
|
-
if (!answer) answers.set(signal, answer = compute(signal));
|
|
186
|
-
return answer;
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
function downbeatsWithMeter(beats, downbeats) {
|
|
190
|
-
const bar = medianInterval(downbeats);
|
|
191
|
-
const beat = medianInterval(beats);
|
|
192
|
-
const meter = bar && beat ? Math.round(bar / beat) : null;
|
|
193
|
-
return { times: downbeats, meter: meter && meter > 0 ? meter : null };
|
|
194
|
-
}
|
|
195
|
-
var round = (t) => Math.round(t * 1e3) / 1e3;
|
|
196
|
-
var rounded = (times) => times.map(round);
|
|
197
|
-
var NO_HEYGEN_CREDENTIAL = "no HeyGen credential: set HEYGEN_API_KEY or run `hyperframes auth login --api-key`";
|
|
198
|
-
async function heygenHeaders() {
|
|
199
|
-
try {
|
|
200
|
-
const credential = await tryResolveCredential();
|
|
201
|
-
return credential ? buildAuthHeaders(await refreshIfNeeded(credential)) : NO_HEYGEN_CREDENTIAL;
|
|
202
|
-
} catch (error) {
|
|
203
|
-
return error instanceof Error ? error.message : String(error);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
async function serviceAccess(env, path, defaultMs) {
|
|
207
|
-
const timeout = Number(process.env[env.timeout]);
|
|
208
|
-
const timeoutMs = timeout > 0 ? timeout : defaultMs;
|
|
209
|
-
const url = process.env[env.url]?.trim();
|
|
210
|
-
const key = process.env[env.key]?.trim();
|
|
211
|
-
if (url === "") return `${env.url} is empty, which turns this service off`;
|
|
212
|
-
if (key)
|
|
213
|
-
return {
|
|
214
|
-
url: url || `${resolveCloudBaseUrl()}${path}`,
|
|
215
|
-
headers: { "x-api-key": key },
|
|
216
|
-
timeoutMs
|
|
217
|
-
};
|
|
218
|
-
if (url) return `${env.url} is set but ${env.key} is not`;
|
|
219
|
-
const headers = await heygenHeaders();
|
|
220
|
-
if (typeof headers === "string") return headers;
|
|
221
|
-
return { url: `${resolveCloudBaseUrl()}${path}`, headers, timeoutMs };
|
|
222
|
-
}
|
|
223
|
-
function errorMessageIn(text) {
|
|
224
|
-
try {
|
|
225
|
-
return JSON.parse(text).error?.message;
|
|
226
|
-
} catch {
|
|
227
|
-
return void 0;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
async function serviceFailure(response, service) {
|
|
231
|
-
const text = await response.text().catch(() => "");
|
|
232
|
-
const detail = errorMessageIn(text) ?? text.slice(0, 200);
|
|
233
|
-
return new Error(`${service} answered ${response.status}${detail ? `: ${detail}` : ""}`);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// src/audio/analysis/providers/api.ts
|
|
237
|
-
var URL_ENV = "HYPERFRAMES_AUDIO_API_URL";
|
|
238
|
-
var KEY_ENV = "HYPERFRAMES_AUDIO_API_KEY";
|
|
239
|
-
var TIMEOUT_ENV = "HYPERFRAMES_AUDIO_API_TIMEOUT_MS";
|
|
240
|
-
var DEFAULT_TIMEOUT_MS = 12e4;
|
|
241
|
-
var UPLOAD_RATE = 16e3;
|
|
242
|
-
var SINC_ZEROS = 16;
|
|
243
|
-
var ROLLOFF = 0.9;
|
|
244
|
-
var SINC_STEPS = 512;
|
|
245
|
-
var HANN_SINC = Float32Array.from({ length: SINC_ZEROS * SINC_STEPS + 2 }, (_, k) => {
|
|
246
|
-
const x = k / SINC_STEPS;
|
|
247
|
-
if (x >= SINC_ZEROS) return 0;
|
|
248
|
-
const sinc = x === 0 ? 1 : Math.sin(Math.PI * x) / (Math.PI * x);
|
|
249
|
-
return sinc * (0.5 + 0.5 * Math.cos(Math.PI * x / SINC_ZEROS));
|
|
250
|
-
});
|
|
251
|
-
function resample(input, from, to) {
|
|
252
|
-
if (from === to) return input;
|
|
253
|
-
const step = from / to;
|
|
254
|
-
const scale = Math.min(1, to / from) * ROLLOFF;
|
|
255
|
-
const reach = SINC_ZEROS / scale;
|
|
256
|
-
const output = new Float32Array(Math.round(input.length / step));
|
|
257
|
-
for (let i = 0; i < output.length; i++) {
|
|
258
|
-
const center = i * step;
|
|
259
|
-
const last = Math.min(input.length - 1, Math.floor(center + reach));
|
|
260
|
-
let sum = 0;
|
|
261
|
-
let weights = 0;
|
|
262
|
-
for (let n = Math.max(0, Math.ceil(center - reach)); n <= last; n++) {
|
|
263
|
-
const at = Math.abs(n - center) * scale * SINC_STEPS;
|
|
264
|
-
const k = Math.floor(at);
|
|
265
|
-
const weight = HANN_SINC[k] + (at - k) * (HANN_SINC[k + 1] - HANN_SINC[k]);
|
|
266
|
-
sum += input[n] * weight;
|
|
267
|
-
weights += weight;
|
|
268
|
-
}
|
|
269
|
-
output[i] = weights ? sum / weights : 0;
|
|
270
|
-
}
|
|
271
|
-
return output;
|
|
272
|
-
}
|
|
273
|
-
function monoInput(channels) {
|
|
274
|
-
const mono = new Float32Array(channels[0]?.length ?? 0);
|
|
275
|
-
let loudest2 = mono;
|
|
276
|
-
let loudestEnergy = 0;
|
|
277
|
-
for (const channel of channels) {
|
|
278
|
-
let energy = 0;
|
|
279
|
-
for (let i = 0; i < mono.length; i++) {
|
|
280
|
-
const value = channel[i];
|
|
281
|
-
mono[i] += value / channels.length;
|
|
282
|
-
energy += value * value;
|
|
283
|
-
}
|
|
284
|
-
if (energy > loudestEnergy) {
|
|
285
|
-
loudest2 = channel;
|
|
286
|
-
loudestEnergy = energy;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
const monoEnergy = mono.reduce((energy, value) => energy + value * value, 0);
|
|
290
|
-
return monoEnergy < loudestEnergy * 0.1 ? loudest2 : mono;
|
|
291
|
-
}
|
|
292
|
-
function uploaded(signal) {
|
|
293
|
-
return {
|
|
294
|
-
sampleRate: UPLOAD_RATE,
|
|
295
|
-
channels: [resample(monoInput(signal.channels), signal.sampleRate, UPLOAD_RATE)]
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
var askedTogether = (capability) => capability === "beats" || capability === "downbeats" ? ["beats", "downbeats"] : [capability];
|
|
299
|
-
var access = () => serviceAccess(
|
|
300
|
-
{ url: URL_ENV, key: KEY_ENV, timeout: TIMEOUT_ENV },
|
|
301
|
-
"/v3/audio/analysis",
|
|
302
|
-
DEFAULT_TIMEOUT_MS
|
|
303
|
-
);
|
|
304
|
-
async function granted() {
|
|
305
|
-
const found = await access();
|
|
306
|
-
if (typeof found === "string") throw new Error(found);
|
|
307
|
-
return found;
|
|
308
|
-
}
|
|
309
|
-
var isNumberList = (value) => Array.isArray(value) && value.every((t) => typeof t === "number" && Number.isFinite(t));
|
|
310
|
-
function checked(capability, body) {
|
|
311
|
-
const value = body[capability];
|
|
312
|
-
if (!value || typeof value !== "object")
|
|
313
|
-
throw new Error(`the service did not answer ${capability}`);
|
|
314
|
-
const valid = {
|
|
315
|
-
beats: () => isNumberList(value.times),
|
|
316
|
-
downbeats: () => isNumberList(value.times),
|
|
317
|
-
sections: () => Array.isArray(value.spans) && value.spans.every((s3) => isNumberList([s3.start, s3.end])),
|
|
318
|
-
describe: () => Array.isArray(value.tags) && value.tags.every(
|
|
319
|
-
(t) => typeof t.label === "string" && typeof t.score === "number"
|
|
320
|
-
)
|
|
321
|
-
}[capability];
|
|
322
|
-
if (!valid())
|
|
323
|
-
throw new Error(`the service answered ${capability} in a shape this CLI cannot read`);
|
|
324
|
-
}
|
|
325
|
-
var uploadedAsset = perSignal(async (analyzed) => {
|
|
326
|
-
const { url, headers, timeoutMs } = await granted();
|
|
327
|
-
const deadline = AbortSignal.timeout(timeoutMs);
|
|
328
|
-
const boundedFetch = (input, init) => fetch(input, {
|
|
329
|
-
...init,
|
|
330
|
-
redirect: "error",
|
|
331
|
-
signal: deadline
|
|
332
|
-
});
|
|
333
|
-
const client = new HyperframesCloudClient({
|
|
334
|
-
baseUrl: new URL(url).origin,
|
|
335
|
-
getAuthHeaders: () => headers,
|
|
336
|
-
fetchImpl: boundedFetch
|
|
337
|
-
});
|
|
338
|
-
const asset = await uploadAssetViaDirectUpload({
|
|
339
|
-
client,
|
|
340
|
-
bytes: new Uint8Array(encodeWav(uploaded(analyzed))),
|
|
341
|
-
filename: "audio.wav",
|
|
342
|
-
contentType: "audio/wav",
|
|
343
|
-
idempotencyKey: randomUUID(),
|
|
344
|
-
fetchImpl: boundedFetch
|
|
345
|
-
});
|
|
346
|
-
return asset.asset_id;
|
|
347
|
-
});
|
|
348
|
-
async function ask(analyzed, capabilities2) {
|
|
349
|
-
const { url, headers, timeoutMs } = await granted();
|
|
350
|
-
const request = {
|
|
351
|
-
version: 1,
|
|
352
|
-
capabilities: capabilities2,
|
|
353
|
-
audio: { type: "asset_id", asset_id: await uploadedAsset(analyzed) }
|
|
354
|
-
};
|
|
355
|
-
const response = await fetch(url, {
|
|
356
|
-
method: "POST",
|
|
357
|
-
redirect: "error",
|
|
358
|
-
headers: {
|
|
359
|
-
...headers,
|
|
360
|
-
"idempotency-key": randomUUID(),
|
|
361
|
-
"content-type": "application/json"
|
|
362
|
-
},
|
|
363
|
-
body: JSON.stringify(request),
|
|
364
|
-
signal: AbortSignal.timeout(timeoutMs)
|
|
365
|
-
});
|
|
366
|
-
if (!response.ok) throw await serviceFailure(response, "the service");
|
|
367
|
-
const body = await response.json();
|
|
368
|
-
return body?.data ?? body ?? {};
|
|
369
|
-
}
|
|
370
|
-
var requests = /* @__PURE__ */ new Map();
|
|
371
|
-
function answerFor(signal, capability) {
|
|
372
|
-
const together = askedTogether(capability);
|
|
373
|
-
const key = together.join(",");
|
|
374
|
-
let request = requests.get(key);
|
|
375
|
-
if (!request) requests.set(key, request = perSignal((s3) => ask(s3, together)));
|
|
376
|
-
return request(signal);
|
|
377
|
-
}
|
|
378
|
-
function beatSnapper(signal) {
|
|
379
|
-
const measured3 = rhythm(signal).beats.times;
|
|
380
|
-
return snapper(measured3, (medianInterval(measured3) ?? 0) / 4, "signal beats");
|
|
381
|
-
}
|
|
382
|
-
function snappedSections(signal, body) {
|
|
383
|
-
const onBeat2 = beatSnapper(signal);
|
|
384
|
-
const end = (signal.channels[0]?.length ?? 0) / signal.sampleRate;
|
|
385
|
-
const move = (t) => t <= 0 || t >= end ? t : onBeat2.snap(t);
|
|
386
|
-
const spans = body.sections.spans.map((s3) => ({
|
|
387
|
-
...s3,
|
|
388
|
-
start: rounded([move(s3.start)])[0],
|
|
389
|
-
end: rounded([move(s3.end)])[0]
|
|
390
|
-
}));
|
|
391
|
-
return { spans, snap: onBeat2.report() };
|
|
392
|
-
}
|
|
393
|
-
function measured(capability, signal, body) {
|
|
394
|
-
const value = capability === "beats" ? { times: rounded(body.beats.times) } : capability === "downbeats" ? { times: rounded(body.downbeats.times), meter: body.downbeats.meter ?? null } : capability === "sections" ? snappedSections(signal, body) : body.describe;
|
|
395
|
-
return body.source ? { ...value, source: body.source } : value;
|
|
396
|
-
}
|
|
397
|
-
var API_CAPABILITIES = ["beats", "downbeats", "sections", "describe"];
|
|
398
|
-
var apiProvider = {
|
|
399
|
-
id: "api",
|
|
400
|
-
local: false,
|
|
401
|
-
capabilities: API_CAPABILITIES,
|
|
402
|
-
async available() {
|
|
403
|
-
const found = await access();
|
|
404
|
-
return typeof found === "string" ? unavailable(found) : AVAILABLE;
|
|
405
|
-
},
|
|
406
|
-
async analyze(capability, signal) {
|
|
407
|
-
const asked = capability;
|
|
408
|
-
const body = await answerFor(signal, asked);
|
|
409
|
-
checked(asked, body);
|
|
410
|
-
return measured(asked, signal, body);
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
|
|
414
|
-
// src/audio/analysis/providers/apple.ts
|
|
415
|
-
import { createHash } from "crypto";
|
|
416
|
-
import { existsSync } from "fs";
|
|
417
|
-
import { mkdir, rename, writeFile as writeFile2 } from "fs/promises";
|
|
418
|
-
import { homedir } from "os";
|
|
419
|
-
import { join as join2 } from "path";
|
|
420
|
-
var SOUND_ANALYSIS = "/System/Library/Frameworks/SoundAnalysis.framework";
|
|
421
|
-
var MUSIC_UNDERSTANDING_MACOS = 27;
|
|
422
|
-
var SOUND_TAGGER = `
|
|
423
|
-
import Foundation
|
|
424
|
-
import SoundAnalysis
|
|
425
|
-
|
|
426
|
-
final class Collector: NSObject, SNResultsObserving {
|
|
427
|
-
var sums: [String: Double] = [:]
|
|
428
|
-
var windows = 0
|
|
429
|
-
var failure: Error?
|
|
430
|
-
func request(_ request: SNRequest, didProduce result: SNResult) {
|
|
431
|
-
guard let result = result as? SNClassificationResult else { return }
|
|
432
|
-
windows += 1
|
|
433
|
-
for c in result.classifications { sums[c.identifier, default: 0] += c.confidence }
|
|
434
|
-
}
|
|
435
|
-
func request(_ request: SNRequest, didFailWithError error: Error) { failure = error }
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
do {
|
|
439
|
-
let analyzer = try SNAudioFileAnalyzer(url: URL(fileURLWithPath: CommandLine.arguments[1]))
|
|
440
|
-
let collector = Collector()
|
|
441
|
-
try analyzer.add(try SNClassifySoundRequest(classifierIdentifier: .version1), withObserver: collector)
|
|
442
|
-
analyzer.analyze()
|
|
443
|
-
if let failure = collector.failure { throw failure }
|
|
444
|
-
let count = Double(max(1, collector.windows))
|
|
445
|
-
var tags: [[String: Any]] = []
|
|
446
|
-
for (label, sum) in collector.sums.sorted(by: { $0.value > $1.value }).prefix(10) {
|
|
447
|
-
let score: Double = sum / count
|
|
448
|
-
if score >= 0.01 { tags.append(["label": label, "score": (score * 1000).rounded() / 1000]) }
|
|
449
|
-
}
|
|
450
|
-
let json = try JSONSerialization.data(withJSONObject: ["tags": tags, "windows": collector.windows])
|
|
451
|
-
FileHandle.standardOutput.write(json)
|
|
452
|
-
} catch {
|
|
453
|
-
FileHandle.standardError.write(Data("\\(error)".utf8))
|
|
454
|
-
exit(1)
|
|
455
|
-
}
|
|
456
|
-
`;
|
|
457
|
-
var CLASSIFIER_WINDOW_SECONDS = 3;
|
|
458
|
-
function atLeastOneWindow(signal) {
|
|
459
|
-
const length = Math.ceil(CLASSIFIER_WINDOW_SECONDS * signal.sampleRate);
|
|
460
|
-
if ((signal.channels[0]?.length ?? 0) >= length) return signal;
|
|
461
|
-
return {
|
|
462
|
-
...signal,
|
|
463
|
-
channels: signal.channels.map((channel) => {
|
|
464
|
-
const padded = new Float32Array(length);
|
|
465
|
-
padded.set(channel);
|
|
466
|
-
return padded;
|
|
467
|
-
})
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
var helperDir = () => join2(homedir(), ".cache", "hyperframes", "audio-helpers");
|
|
471
|
-
function helperPath(name, source) {
|
|
472
|
-
const hash = createHash("sha256").update(source).digest("hex").slice(0, 12);
|
|
473
|
-
return join2(helperDir(), `${name}-${hash}`);
|
|
474
|
-
}
|
|
475
|
-
async function hasSwiftCompiler() {
|
|
476
|
-
try {
|
|
477
|
-
await runFile("xcrun", ["--find", "swiftc"], { timeout: 3e4 });
|
|
478
|
-
return true;
|
|
479
|
-
} catch {
|
|
480
|
-
return false;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
var firstLine = (error) => (error.stderr || String(error)).trim().split("\n")[0];
|
|
484
|
-
function swiftcArgs(source, output) {
|
|
485
|
-
return [
|
|
486
|
-
"--sdk",
|
|
487
|
-
"macosx",
|
|
488
|
-
"swiftc",
|
|
489
|
-
"-O",
|
|
490
|
-
"-swift-version",
|
|
491
|
-
"5",
|
|
492
|
-
"-module-cache-path",
|
|
493
|
-
join2(helperDir(), "module-cache"),
|
|
494
|
-
source,
|
|
495
|
-
"-o",
|
|
496
|
-
output
|
|
497
|
-
];
|
|
498
|
-
}
|
|
499
|
-
var builds = /* @__PURE__ */ new Map();
|
|
500
|
-
function compiled(name, source) {
|
|
501
|
-
const binary = helperPath(name, source);
|
|
502
|
-
if (existsSync(binary)) return Promise.resolve(binary);
|
|
503
|
-
let build = builds.get(binary);
|
|
504
|
-
if (!build) {
|
|
505
|
-
build = (async () => {
|
|
506
|
-
await mkdir(helperDir(), { recursive: true });
|
|
507
|
-
const file = `${binary}.swift`;
|
|
508
|
-
await writeFile2(file, source);
|
|
509
|
-
const args = swiftcArgs(file, `${binary}.tmp`);
|
|
510
|
-
await runFile("xcrun", args, { timeout: 5 * 6e4 }).catch((error) => {
|
|
511
|
-
throw new Error(`could not build the ${name} helper: ${firstLine(error)}`);
|
|
512
|
-
});
|
|
513
|
-
await rename(`${binary}.tmp`, binary);
|
|
514
|
-
return binary;
|
|
515
|
-
})();
|
|
516
|
-
builds.set(binary, build);
|
|
517
|
-
}
|
|
518
|
-
return build;
|
|
519
|
-
}
|
|
520
|
-
async function macosMajor() {
|
|
521
|
-
if (process.platform !== "darwin") return null;
|
|
522
|
-
const { stdout } = await runFile("sw_vers", ["-productVersion"], { timeout: 1e4 });
|
|
523
|
-
return Number.parseInt(stdout, 10) || null;
|
|
524
|
-
}
|
|
525
|
-
var appleSoundProvider = {
|
|
526
|
-
id: "apple-sound",
|
|
527
|
-
local: true,
|
|
528
|
-
capabilities: ["describe"],
|
|
529
|
-
async available() {
|
|
530
|
-
if (process.platform !== "darwin") return unavailable("macOS only");
|
|
531
|
-
if (!existsSync(SOUND_ANALYSIS))
|
|
532
|
-
return unavailable("SoundAnalysis.framework is not on this Mac");
|
|
533
|
-
if (existsSync(helperPath("apple-sound", SOUND_TAGGER))) return AVAILABLE;
|
|
534
|
-
if (!await hasSwiftCompiler()) return unavailable("no Swift compiler to build the helper");
|
|
535
|
-
return AVAILABLE;
|
|
536
|
-
},
|
|
537
|
-
async analyze(_capability, signal) {
|
|
538
|
-
const helper = await compiled("apple-sound", SOUND_TAGGER);
|
|
539
|
-
const { stdout } = await withWavFile(
|
|
540
|
-
atLeastOneWindow(signal),
|
|
541
|
-
(wav) => runFile(helper, [wav], { timeout: 5 * 6e4, maxBuffer: 8 * 1024 * 1024 })
|
|
542
|
-
);
|
|
543
|
-
const { tags } = JSON.parse(stdout);
|
|
544
|
-
return {
|
|
545
|
-
tags: tags.map((t) => ({ label: t.label, score: Math.round(t.score * 1e3) / 1e3 }))
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
};
|
|
549
|
-
var appleMuProvider = {
|
|
550
|
-
id: "apple-mu",
|
|
551
|
-
local: true,
|
|
552
|
-
capabilities: ["beats", "downbeats", "sections"],
|
|
553
|
-
async available() {
|
|
554
|
-
const major = await macosMajor();
|
|
555
|
-
if (major === null) return unavailable("macOS only");
|
|
556
|
-
if (major < MUSIC_UNDERSTANDING_MACOS)
|
|
557
|
-
return unavailable(
|
|
558
|
-
`Music Understanding needs macOS ${MUSIC_UNDERSTANDING_MACOS}; this Mac runs ${major}`
|
|
559
|
-
);
|
|
560
|
-
return unavailable("no Music Understanding helper yet: it needs the macOS 27 SDK to build");
|
|
561
|
-
},
|
|
562
|
-
analyze() {
|
|
563
|
-
return Promise.reject(new Error("Music Understanding is not available"));
|
|
564
|
-
}
|
|
565
|
-
};
|
|
566
|
-
|
|
567
|
-
// src/audio/analysis/providers/beatThis.ts
|
|
568
|
-
import { existsSync as existsSync2 } from "fs";
|
|
569
|
-
import { homedir as homedir2 } from "os";
|
|
570
|
-
import { join as join3 } from "path";
|
|
571
|
-
var PYTHON_ENV = "HYPERFRAMES_BEAT_THIS_PYTHON";
|
|
572
|
-
var CHECKPOINT_ENV = "HYPERFRAMES_BEAT_THIS_CHECKPOINT";
|
|
573
|
-
function checkpointPath() {
|
|
574
|
-
const configured = process.env[CHECKPOINT_ENV]?.trim();
|
|
575
|
-
if (configured) return configured;
|
|
576
|
-
const torchHome = process.env.TORCH_HOME ?? join3(homedir2(), ".cache", "torch");
|
|
577
|
-
return join3(torchHome, "hub", "checkpoints", "beat_this-small0.ckpt");
|
|
578
|
-
}
|
|
579
|
-
var FIND_PACKAGE = "import importlib.util,sys; sys.exit(importlib.util.find_spec('beat_this') is None)";
|
|
580
|
-
var TRACK = `
|
|
581
|
-
import json, sys
|
|
582
|
-
from beat_this.inference import File2Beats
|
|
583
|
-
beats, downbeats = File2Beats(checkpoint_path=sys.argv[2], device="cpu", dbn=False)(sys.argv[1])
|
|
584
|
-
print(json.dumps({"beats": [float(t) for t in beats], "downbeats": [float(t) for t in downbeats]}))
|
|
585
|
-
`;
|
|
586
|
-
var installed = /* @__PURE__ */ new Map();
|
|
587
|
-
function hasPackage(python) {
|
|
588
|
-
let found = installed.get(python);
|
|
589
|
-
if (!found) {
|
|
590
|
-
found = runFile(python, ["-c", FIND_PACKAGE], { timeout: 3e4, windowsHide: true }).then(
|
|
591
|
-
() => true,
|
|
592
|
-
() => false
|
|
593
|
-
);
|
|
594
|
-
installed.set(python, found);
|
|
595
|
-
}
|
|
596
|
-
return found;
|
|
597
|
-
}
|
|
598
|
-
var track = perSignal(
|
|
599
|
-
(signal) => withWavFile(signal, async (wav) => {
|
|
600
|
-
const python = process.env[PYTHON_ENV].trim();
|
|
601
|
-
const { stdout } = await runFile(python, ["-c", TRACK, wav, checkpointPath()], {
|
|
602
|
-
maxBuffer: 64 * 1024 * 1024,
|
|
603
|
-
timeout: 10 * 6e4,
|
|
604
|
-
windowsHide: true
|
|
605
|
-
});
|
|
606
|
-
const answer = JSON.parse(stdout.trim().split("\n").pop());
|
|
607
|
-
return { beats: rounded(answer.beats), downbeats: rounded(answer.downbeats) };
|
|
608
|
-
})
|
|
609
|
-
);
|
|
610
|
-
var beatThisProvider = {
|
|
611
|
-
id: "beat-this",
|
|
612
|
-
local: true,
|
|
613
|
-
capabilities: ["beats", "downbeats"],
|
|
614
|
-
async available() {
|
|
615
|
-
const python = process.env[PYTHON_ENV]?.trim();
|
|
616
|
-
if (!python) return unavailable(`${PYTHON_ENV} is not set`);
|
|
617
|
-
if (!existsSync2(python)) return unavailable(`${PYTHON_ENV} names no file`);
|
|
618
|
-
if (!existsSync2(checkpointPath()))
|
|
619
|
-
return unavailable(`no Beat This! weights at ${checkpointPath()}`);
|
|
620
|
-
if (!await hasPackage(python)) return unavailable(`beat_this is not installed for ${python}`);
|
|
621
|
-
return AVAILABLE;
|
|
622
|
-
},
|
|
623
|
-
async analyze(capability, signal) {
|
|
624
|
-
const { beats, downbeats } = await track(signal);
|
|
625
|
-
return capability === "beats" ? { times: beats } : downbeatsWithMeter(beats, downbeats);
|
|
626
|
-
}
|
|
627
|
-
};
|
|
628
|
-
|
|
629
|
-
// src/audio/analysis/fileTime.ts
|
|
630
|
-
var round2 = (t) => Math.round(t * 1e3) / 1e3;
|
|
631
|
-
function withSnap(value, at) {
|
|
632
|
-
return value.snap ? { ...value, snap: { ...value.snap, unsnapped: value.snap.unsnapped.map(at) } } : value;
|
|
633
|
-
}
|
|
634
|
-
var SHIFTS = {
|
|
635
|
-
moments: (m, at) => Object.fromEntries(Object.entries(m).map(([k, t]) => [k, at(t)])),
|
|
636
|
-
onsets: (o, at) => ({ ...o, events: o.events.map((e) => ({ ...e, t: at(e.t) })) }),
|
|
637
|
-
silence: (spans, at) => spans.map((s3) => ({ start: at(s3.start), end: at(s3.end) })),
|
|
638
|
-
loudness: (l, at) => ({
|
|
639
|
-
...l,
|
|
640
|
-
clipping: {
|
|
641
|
-
...l.clipping,
|
|
642
|
-
firstAt: l.clipping.firstAt === null ? null : at(l.clipping.firstAt)
|
|
643
|
-
}
|
|
644
|
-
}),
|
|
645
|
-
envelope: (e, _at, offset) => ({ startsAt: round2(offset), ...e }),
|
|
646
|
-
beats: (b, at) => withSnap({ ...b, times: b.times.map(at) }, at),
|
|
647
|
-
downbeats: (b, at) => withSnap({ ...b, times: b.times.map(at) }, at),
|
|
648
|
-
bpm: (tempo, at) => ({
|
|
649
|
-
...tempo,
|
|
650
|
-
curve: tempo.curve.map((p) => ({ ...p, t: at(p.t) }))
|
|
651
|
-
}),
|
|
652
|
-
sections: (s3, at) => withSnap(
|
|
653
|
-
{
|
|
654
|
-
...s3,
|
|
655
|
-
spans: s3.spans.map((span) => ({ ...span, start: at(span.start), end: at(span.end) }))
|
|
656
|
-
},
|
|
657
|
-
at
|
|
658
|
-
)
|
|
659
|
-
};
|
|
660
|
-
function shiftedTimes(capability, value, offset) {
|
|
661
|
-
if (value === null || typeof value !== "object") return value;
|
|
662
|
-
const shift = SHIFTS[capability];
|
|
663
|
-
return shift ? shift(value, (t) => round2(t + offset), offset) : value;
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
// src/audio/analysis/analyze.ts
|
|
667
|
-
var DEFAULT_CAPABILITIES = [
|
|
668
|
-
"kind",
|
|
669
|
-
"moments",
|
|
670
|
-
"onsets",
|
|
671
|
-
"loudness",
|
|
672
|
-
"silence",
|
|
673
|
-
"envelope"
|
|
674
|
-
];
|
|
675
|
-
function audioAnalysisProviders() {
|
|
676
|
-
return [apiProvider, appleMuProvider, beatThisProvider, appleSoundProvider, signalProvider];
|
|
677
|
-
}
|
|
678
|
-
function envelopeHopMs(seconds, asked) {
|
|
679
|
-
if (asked !== void 0) return asked;
|
|
680
|
-
return Math.max(5, Math.ceil(seconds * 1e3 / 2e3));
|
|
681
|
-
}
|
|
682
|
-
var round3 = (t) => Math.round(t * 1e3) / 1e3;
|
|
683
|
-
function within(value, from, to) {
|
|
684
|
-
if (!value || typeof value !== "object" || !("events" in value)) return value;
|
|
685
|
-
const onsets = value;
|
|
686
|
-
return { ...onsets, events: onsets.events.filter((e) => e.t >= from && e.t < to) };
|
|
687
|
-
}
|
|
688
|
-
function frame(signal, context) {
|
|
689
|
-
const before = context?.before ?? 0;
|
|
690
|
-
const skip = Math.round(before * signal.sampleRate);
|
|
691
|
-
const length = signal.channels[0]?.length ?? 0;
|
|
692
|
-
const end = Math.max(skip, length - Math.round((context?.after ?? 0) * signal.sampleRate));
|
|
693
|
-
const cut = skip > 0 || end < length;
|
|
694
|
-
const windowed = cut ? { ...signal, channels: signal.channels.map((c) => c.subarray(skip, end)) } : signal;
|
|
695
|
-
return { windowed, before, end: end / signal.sampleRate, cut };
|
|
696
|
-
}
|
|
697
|
-
function optionsFor(capability, request, seconds) {
|
|
698
|
-
const options = { ...request.options?.[capability] };
|
|
699
|
-
if (capability === "envelope")
|
|
700
|
-
options.hopMs = envelopeHopMs(seconds, options.hopMs);
|
|
701
|
-
return options;
|
|
702
|
-
}
|
|
703
|
-
async function analyzeSignal(signal, request, providers = audioAnalysisProviders()) {
|
|
704
|
-
const quality = request.quality ?? "local";
|
|
705
|
-
const { beats, bpm } = request.provider ?? {};
|
|
706
|
-
if (beats && bpm && beats !== bpm) throw new Error("beats and bpm must use the same provider");
|
|
707
|
-
const beatProvider = beats ?? bpm;
|
|
708
|
-
const framing = frame(signal, request.context);
|
|
709
|
-
const analysis = {
|
|
710
|
-
analyzed: round3(signalDuration(framing.windowed)),
|
|
711
|
-
values: {},
|
|
712
|
-
provenance: {},
|
|
713
|
-
ladder: {},
|
|
714
|
-
warnings: []
|
|
715
|
-
};
|
|
716
|
-
const ladders = /* @__PURE__ */ new Map();
|
|
717
|
-
const ladderFor = (capability) => {
|
|
718
|
-
let result = ladders.get(capability);
|
|
719
|
-
if (!result) {
|
|
720
|
-
const withContext = capability === "onsets" && framing.cut;
|
|
721
|
-
const input = withContext ? signal : framing.windowed;
|
|
722
|
-
result = runLadder(capability, input, providers, {
|
|
723
|
-
quality,
|
|
724
|
-
provider: capability === "beats" ? beatProvider : request.provider?.[capability],
|
|
725
|
-
options: optionsFor(capability, request, analysis.analyzed)
|
|
726
|
-
}).then((answer) => settled(capability, answer, input));
|
|
727
|
-
ladders.set(capability, result);
|
|
728
|
-
}
|
|
729
|
-
return result;
|
|
730
|
-
};
|
|
731
|
-
for (const capability of request.capabilities) {
|
|
732
|
-
const withContext = capability === "onsets" && framing.cut;
|
|
733
|
-
const result = capability === "bpm" ? tempoFromBeats(await ladderFor("beats")) : await ladderFor(capability);
|
|
734
|
-
const value = withContext ? within(result.value, framing.before, framing.end) : result.value;
|
|
735
|
-
const offset = (request.fileOffset ?? 0) - (withContext ? framing.before : 0);
|
|
736
|
-
analysis.values[capability] = shiftedTimes(capability, value, offset);
|
|
737
|
-
analysis.provenance[capability] = result.provenance;
|
|
738
|
-
analysis.ladder[capability] = result.steps;
|
|
739
|
-
const said = new Set(analysis.warnings);
|
|
740
|
-
analysis.warnings.push(...result.warnings.filter((w) => !said.has(w)));
|
|
741
|
-
}
|
|
742
|
-
analysis.warnings.push(...serviceHint(quality, analysis, request.capabilities));
|
|
743
|
-
return analysis;
|
|
744
|
-
}
|
|
745
|
-
function serviceHint(quality, analysis, capabilities2) {
|
|
746
|
-
const leftToService = (capability) => analysis.values[capability] == null && (analysis.ladder[capability] ?? []).some((s3) => s3.outcome === "excluded");
|
|
747
|
-
return quality === "local" && capabilities2.some(leftToService) ? ["a service could have answered what is missing: --quality best uploads the audio to HeyGen"] : [];
|
|
748
|
-
}
|
|
749
|
-
var DIGITAL_SILENCE_DB = -80;
|
|
750
|
-
var HEARD_LIFT = 1.5;
|
|
751
|
-
var roundTime = (t) => Math.round(t * 1e3) / 1e3;
|
|
752
|
-
function settled(capability, result, signal) {
|
|
753
|
-
if (capability !== "beats" && capability !== "downbeats") return result;
|
|
754
|
-
const value = result.value;
|
|
755
|
-
if (!value?.times) return result;
|
|
756
|
-
const beat = beatOf(capability, value, signal);
|
|
757
|
-
const onSignal = result.provenance === "signal" ? value : snappedToSignal(value, signal, beat);
|
|
758
|
-
const quiet = silence(signal, { thresholdDb: DIGITAL_SILENCE_DB });
|
|
759
|
-
const evidence = localBeatEvidence(
|
|
760
|
-
signal,
|
|
761
|
-
onSignal.times,
|
|
762
|
-
capability === "downbeats" ? beat : void 0
|
|
763
|
-
);
|
|
764
|
-
const unheard = onSignal.times.map(
|
|
765
|
-
(t, i) => quiet.some((span) => t >= span.start && t < span.end) || evidence[i].confidence < STEADY_BEAT_CONFIDENCE && evidence[i].lift < HEARD_LIFT
|
|
766
|
-
);
|
|
767
|
-
return { ...result, value: { ...onSignal, unheard } };
|
|
768
|
-
}
|
|
769
|
-
function beatOf(capability, value, signal) {
|
|
770
|
-
const interval = medianInterval(value.times);
|
|
771
|
-
const own = capability === "beats" ? interval : interval && value.meter ? interval / value.meter : null;
|
|
772
|
-
return own ?? medianInterval(rhythm(signal).beats.times) ?? 0;
|
|
773
|
-
}
|
|
774
|
-
function snappedToSignal(value, signal, beat) {
|
|
775
|
-
const onBeat2 = snapper(rhythm(signal).beats.times, beat / 4, "signal beats");
|
|
776
|
-
return {
|
|
777
|
-
...value,
|
|
778
|
-
times: value.times.map((t) => roundTime(onBeat2.snap(t))),
|
|
779
|
-
snap: onBeat2.report()
|
|
780
|
-
};
|
|
781
|
-
}
|
|
782
|
-
function tempoFromBeats(beats) {
|
|
783
|
-
const times = beats.value?.times;
|
|
784
|
-
return { ...beats, value: times ? tempoOf(times) : null };
|
|
785
|
-
}
|
|
126
|
+
import { join as join4, resolve as resolve2 } from "path";
|
|
786
127
|
|
|
787
128
|
// src/audio/analysis/targets.ts
|
|
788
|
-
import { dirname, join
|
|
789
|
-
var
|
|
129
|
+
import { dirname, join, resolve } from "path";
|
|
130
|
+
var round = (t) => Math.round(t * 1e3) / 1e3;
|
|
790
131
|
function placementOf(row) {
|
|
791
132
|
return {
|
|
792
133
|
start: row.absStart,
|
|
@@ -798,12 +139,12 @@ function placementOf(row) {
|
|
|
798
139
|
};
|
|
799
140
|
}
|
|
800
141
|
function filmTime(placement, fileTime2) {
|
|
801
|
-
return
|
|
142
|
+
return round(placement.start + (fileTime2 - placement.mediaStart) / placement.playbackRate);
|
|
802
143
|
}
|
|
803
144
|
function fileTime(placement, filmTime2) {
|
|
804
|
-
return
|
|
145
|
+
return round(placement.mediaStart + (filmTime2 - placement.start) * placement.playbackRate);
|
|
805
146
|
}
|
|
806
|
-
var soundingRows = (timeline) => timeline.tracks.filter((
|
|
147
|
+
var soundingRows = (timeline) => timeline.tracks.filter((track) => track.kind === "audio" || track.kind === "video").flatMap((track) => track.rows).filter((row) => row.src && row.volume !== 0 && /^(audio|video)$/.test(row.kind)).sort((a, b) => a.absStart - b.absStart);
|
|
807
148
|
function matches(row, query) {
|
|
808
149
|
switch (query.by) {
|
|
809
150
|
case "all":
|
|
@@ -820,25 +161,25 @@ function targetOf(projectDir, row, query) {
|
|
|
820
161
|
const from = query.by === "range" ? Math.max(placement.start, query.start) : placement.start;
|
|
821
162
|
const to = query.by === "range" ? Math.min(placement.end, query.end) : placement.end;
|
|
822
163
|
return {
|
|
823
|
-
path: resolveAuthoredAssetFile(projectDir, row.file, row.src) ?? resolve(dirname(
|
|
164
|
+
path: resolveAuthoredAssetFile(projectDir, row.file, row.src) ?? resolve(dirname(join(projectDir, row.file)), row.src),
|
|
824
165
|
file: row.src,
|
|
825
166
|
ref: row.ref || null,
|
|
826
167
|
kind: row.kind,
|
|
827
168
|
placement,
|
|
828
169
|
window: {
|
|
829
170
|
from: fileTime(placement, from),
|
|
830
|
-
seconds:
|
|
171
|
+
seconds: round((to - from) * placement.playbackRate)
|
|
831
172
|
},
|
|
832
173
|
clip: {
|
|
833
174
|
from: placement.mediaStart,
|
|
834
|
-
seconds:
|
|
175
|
+
seconds: round((placement.end - placement.start) * placement.playbackRate)
|
|
835
176
|
}
|
|
836
177
|
};
|
|
837
178
|
}
|
|
838
179
|
function filmTargets(projectDir, timeline, query) {
|
|
839
180
|
if (query.by === "element") {
|
|
840
181
|
const id = query.ref.startsWith("#") ? query.ref.slice(1) : null;
|
|
841
|
-
const found = timeline.tracks.flatMap((
|
|
182
|
+
const found = timeline.tracks.flatMap((track) => track.rows).filter((row2) => row2.ref === query.ref || id !== null && row2.id === id);
|
|
842
183
|
if (found.length !== 1)
|
|
843
184
|
throw new Error(
|
|
844
185
|
`${query.ref} ${found.length ? `matches ${found.length} clips` : "was not found"}; use a ref from hyperframes timeline`
|
|
@@ -856,8 +197,8 @@ var BARS = "\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";
|
|
|
856
197
|
var SPARK_WIDTH = 48;
|
|
857
198
|
var ONSETS_SHOWN = 12;
|
|
858
199
|
var s = (t) => t.toFixed(3);
|
|
859
|
-
function sparkline(
|
|
860
|
-
const { values } =
|
|
200
|
+
function sparkline(envelope, width = SPARK_WIDTH) {
|
|
201
|
+
const { values } = envelope;
|
|
861
202
|
if (values.length === 0) return "";
|
|
862
203
|
const per = Math.max(1, Math.ceil(values.length / width));
|
|
863
204
|
const slices = [];
|
|
@@ -884,8 +225,8 @@ function loudnessLine(loudness2, at) {
|
|
|
884
225
|
const clip = count && firstAt !== null ? `, clips ${count}\xD7 from ${at(firstAt)}` : "";
|
|
885
226
|
return ` loudness ${lufs2}, true peak ${loudness2.truePeakDb} dBTP${clip}`;
|
|
886
227
|
}
|
|
887
|
-
function silenceLine(
|
|
888
|
-
return
|
|
228
|
+
function silenceLine(silence, at) {
|
|
229
|
+
return silence.length ? ` silent ${silence.map((g) => `${at(g.start)}\u2013${at(g.end)}`).join(" ")}` : null;
|
|
889
230
|
}
|
|
890
231
|
function snapNote(snap) {
|
|
891
232
|
if (!snap) return "";
|
|
@@ -926,7 +267,7 @@ var LINES = [
|
|
|
926
267
|
["onsets", hitsLine],
|
|
927
268
|
["loudness", loudnessLine],
|
|
928
269
|
["silence", silenceLine],
|
|
929
|
-
["envelope", (
|
|
270
|
+
["envelope", (envelope) => ` ${sparkline(envelope)}`],
|
|
930
271
|
["describe", describeLine],
|
|
931
272
|
["bpm", tempoLine],
|
|
932
273
|
["beats", beatsLine],
|
|
@@ -956,365 +297,17 @@ function formatReport(report) {
|
|
|
956
297
|
return report.items.map((item) => formatItem(item).join("\n")).join("\n\n");
|
|
957
298
|
}
|
|
958
299
|
|
|
959
|
-
// src/audio/analysis/run.ts
|
|
960
|
-
import { existsSync as existsSync3 } from "fs";
|
|
961
|
-
|
|
962
|
-
// src/audio/analysis/kindCache.ts
|
|
963
|
-
import { createHash as createHash2, randomUUID as randomUUID2 } from "crypto";
|
|
964
|
-
import { mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "fs";
|
|
965
|
-
import { dirname as dirname2, join as join5 } from "path";
|
|
966
|
-
var CACHE_VERSION = 1;
|
|
967
|
-
var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
968
|
-
var finite = (value) => typeof value === "number" && Number.isFinite(value);
|
|
969
|
-
var probability = (value) => finite(value) && value >= 0 && value <= 1;
|
|
970
|
-
function isKindFeatures(value) {
|
|
971
|
-
return record(value) && finite(value.duration) && value.duration >= 0 && [value.regularity, value.syllables, value.sustain].every(probability) && (value.voiced === void 0 || probability(value.voiced));
|
|
972
|
-
}
|
|
973
|
-
function isKindGuess(value) {
|
|
974
|
-
return record(value) && typeof value.value === "string" && ["sfx", "music", "voice", "mixed"].includes(value.value) && probability(value.confidence) && isKindFeatures(value.features);
|
|
975
|
-
}
|
|
976
|
-
function kindSourceIdentity(path) {
|
|
977
|
-
const { size, mtimeMs, ctimeMs, ino } = statSync(path);
|
|
978
|
-
return JSON.stringify({ size, mtimeMs, ctimeMs, ino });
|
|
979
|
-
}
|
|
980
|
-
function kindCacheFile(dir, target, request, sampleRate, source = kindSourceIdentity(target.path)) {
|
|
981
|
-
const key = JSON.stringify({
|
|
982
|
-
version: CACHE_VERSION,
|
|
983
|
-
path: target.path,
|
|
984
|
-
source,
|
|
985
|
-
clip: target.clip,
|
|
986
|
-
sampleRate,
|
|
987
|
-
quality: request.quality,
|
|
988
|
-
provider: request.provider?.kind,
|
|
989
|
-
options: request.options?.kind
|
|
990
|
-
});
|
|
991
|
-
return join5(dir, `${createHash2("sha256").update(key).digest("hex")}.json`);
|
|
992
|
-
}
|
|
993
|
-
function readKindCache(file) {
|
|
994
|
-
if (file === null) return null;
|
|
995
|
-
let value;
|
|
996
|
-
try {
|
|
997
|
-
value = JSON.parse(readFileSync(file, "utf8"));
|
|
998
|
-
} catch {
|
|
999
|
-
return null;
|
|
1000
|
-
}
|
|
1001
|
-
if (!isKindGuess(value)) return null;
|
|
1002
|
-
return {
|
|
1003
|
-
analyzed: value.features.duration,
|
|
1004
|
-
values: { kind: value },
|
|
1005
|
-
provenance: { kind: "signal" },
|
|
1006
|
-
ladder: { kind: [{ provider: "signal", outcome: "answered" }] },
|
|
1007
|
-
warnings: []
|
|
1008
|
-
};
|
|
1009
|
-
}
|
|
1010
|
-
function writeKindCache(file, value) {
|
|
1011
|
-
const temporary = `${file}.${randomUUID2()}.tmp`;
|
|
1012
|
-
try {
|
|
1013
|
-
mkdirSync(dirname2(file), { recursive: true });
|
|
1014
|
-
writeFileSync(temporary, JSON.stringify(value));
|
|
1015
|
-
renameSync(temporary, file);
|
|
1016
|
-
return null;
|
|
1017
|
-
} catch {
|
|
1018
|
-
return "kind could not be cached; another query will analyze the clip again";
|
|
1019
|
-
} finally {
|
|
1020
|
-
try {
|
|
1021
|
-
rmSync(temporary, { force: true });
|
|
1022
|
-
} catch {
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
function cacheKindAnalysis(file, analysis) {
|
|
1027
|
-
if (analysis.provenance.kind !== "signal" || analysis.warnings.length || !isKindGuess(analysis.values.kind))
|
|
1028
|
-
return;
|
|
1029
|
-
const warning = writeKindCache(file, analysis.values.kind);
|
|
1030
|
-
if (warning) analysis.warnings.push(warning);
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
// src/audio/analysis/run.ts
|
|
1034
|
-
var round5 = (t) => Math.round(t * 1e3) / 1e3;
|
|
1035
|
-
var EDGE_CONTEXT_SECONDS = 0.1;
|
|
1036
|
-
var KIND_SAMPLE_RATE = 16e3;
|
|
1037
|
-
var KIND_DECODE_BYTES = 256 * 1024 * 1024;
|
|
1038
|
-
var RHYTHM_SAMPLE_RATE = 22050;
|
|
1039
|
-
var RHYTHM = ["beats", "downbeats", "bpm", "sections"];
|
|
1040
|
-
async function previewTarget(path, file, at, mediaStart = 0) {
|
|
1041
|
-
if (at === null) return { path, file, ref: null, kind: "file", placement: null };
|
|
1042
|
-
const stream = existsSync3(path) ? await probeAudio(path) : null;
|
|
1043
|
-
if (stream && mediaStart >= stream.duration)
|
|
1044
|
-
throw new Error(
|
|
1045
|
-
`skipping ${mediaStart} s leaves nothing of ${file}, which is ${round5(stream.duration)} s long`
|
|
1046
|
-
);
|
|
1047
|
-
const length = stream ? stream.duration - mediaStart : 0;
|
|
1048
|
-
return {
|
|
1049
|
-
path,
|
|
1050
|
-
file,
|
|
1051
|
-
ref: null,
|
|
1052
|
-
kind: "file",
|
|
1053
|
-
placement: {
|
|
1054
|
-
start: at,
|
|
1055
|
-
end: round5(at + length),
|
|
1056
|
-
dataStart: at,
|
|
1057
|
-
mediaStart,
|
|
1058
|
-
playbackRate: 1,
|
|
1059
|
-
volume: 1
|
|
1060
|
-
},
|
|
1061
|
-
window: { from: mediaStart, seconds: length }
|
|
1062
|
-
};
|
|
1063
|
-
}
|
|
1064
|
-
var emptyItem = (target) => ({
|
|
1065
|
-
file: target.file,
|
|
1066
|
-
ref: target.ref,
|
|
1067
|
-
element: target.kind === "file" ? null : target.kind,
|
|
1068
|
-
placement: target.placement,
|
|
1069
|
-
timebase: "file",
|
|
1070
|
-
window: null,
|
|
1071
|
-
duration: null,
|
|
1072
|
-
sampleRate: null,
|
|
1073
|
-
channels: null,
|
|
1074
|
-
provenance: {},
|
|
1075
|
-
warnings: []
|
|
1076
|
-
});
|
|
1077
|
-
function unreadable(target) {
|
|
1078
|
-
if (/^[a-z][a-z\d+.-]*:\/\//i.test(target.file)) return "remote sources are not analyzed";
|
|
1079
|
-
if (!existsSync3(target.path)) return "file not found";
|
|
1080
|
-
return null;
|
|
1081
|
-
}
|
|
1082
|
-
function decodeSpan(target, stream) {
|
|
1083
|
-
const from = target.window?.from ?? 0;
|
|
1084
|
-
const seconds = target.window?.seconds ?? stream.duration - from;
|
|
1085
|
-
const before = Math.min(from, EDGE_CONTEXT_SECONDS);
|
|
1086
|
-
const after = Math.max(0, Math.min(EDGE_CONTEXT_SECONDS, stream.duration - from - seconds));
|
|
1087
|
-
return {
|
|
1088
|
-
from,
|
|
1089
|
-
read: { from: from - before, seconds: seconds + before + after },
|
|
1090
|
-
context: { before, after }
|
|
1091
|
-
};
|
|
1092
|
-
}
|
|
1093
|
-
var loudest = (signal) => envelope(signal, { hopMs: 10, scale: "linear" }).values.reduce(
|
|
1094
|
-
(max, value) => Math.max(max, value),
|
|
1095
|
-
0
|
|
1096
|
-
);
|
|
1097
|
-
function retained(signal, before, after) {
|
|
1098
|
-
const skip = Math.round(before * signal.sampleRate);
|
|
1099
|
-
const length = signal.channels[0]?.length ?? 0;
|
|
1100
|
-
const end = Math.max(skip, length - Math.round(after * signal.sampleRate));
|
|
1101
|
-
if (!skip && end >= length) return signal;
|
|
1102
|
-
return { ...signal, channels: signal.channels.map((channel) => channel.subarray(skip, end)) };
|
|
1103
|
-
}
|
|
1104
|
-
async function skippedPeak(target, kept, stream) {
|
|
1105
|
-
const skipped = target.kind === "file" ? target.window?.from ?? 0 : 0;
|
|
1106
|
-
if (skipped <= 0) return [];
|
|
1107
|
-
const head = await decodeAudio(target.path, { from: 0, seconds: skipped }, stream);
|
|
1108
|
-
if (!head || loudest(head.signal) <= loudest(kept)) return [];
|
|
1109
|
-
return [
|
|
1110
|
-
`the loudest part of ${target.file} is in the first ${round5(skipped)} s, which is skipped`
|
|
1111
|
-
];
|
|
1112
|
-
}
|
|
1113
|
-
function coversPart({ window, clip }) {
|
|
1114
|
-
return !!window && !!clip && (window.from > clip.from || window.from + window.seconds < clip.from + clip.seconds);
|
|
1115
|
-
}
|
|
1116
|
-
function clipKindRate(target, stream) {
|
|
1117
|
-
const seconds = Math.min(target.clip.seconds, Math.max(0, stream.duration - target.clip.from));
|
|
1118
|
-
const bytes = seconds * stream.sampleRate * stream.channels * 4;
|
|
1119
|
-
return bytes <= KIND_DECODE_BYTES ? stream.sampleRate : Math.min(stream.sampleRate, KIND_SAMPLE_RATE);
|
|
1120
|
-
}
|
|
1121
|
-
async function clipKindSignal(target, stream, sampleRate, windowSignal, purpose = "kind") {
|
|
1122
|
-
if (windowSignal) return windowSignal;
|
|
1123
|
-
const seconds = Math.min(target.clip.seconds, Math.max(0, stream.duration - target.clip.from));
|
|
1124
|
-
if (seconds * sampleRate * stream.channels * 4 > KIND_DECODE_BYTES)
|
|
1125
|
-
throw new Error(`whole clip exceeds the ${purpose} analysis decode limit`);
|
|
1126
|
-
return (await decodeAudio(target.path, target.clip, stream, { sampleRate }))?.signal;
|
|
1127
|
-
}
|
|
1128
|
-
async function clipKind(target, request, stream, cache, windowSignal) {
|
|
1129
|
-
const sampleRate = windowSignal ? stream.sampleRate : clipKindRate(target, stream);
|
|
1130
|
-
const file = cache ? kindCacheFile(cache.dir, target, request, sampleRate, cache.identity) : null;
|
|
1131
|
-
const cached = readKindCache(file);
|
|
1132
|
-
if (cached) return cached;
|
|
1133
|
-
const signal = await clipKindSignal(target, stream, sampleRate, windowSignal);
|
|
1134
|
-
if (!signal) return null;
|
|
1135
|
-
const analysis = await analyzeSignal(signal, {
|
|
1136
|
-
...request,
|
|
1137
|
-
capabilities: ["kind"],
|
|
1138
|
-
fileOffset: target.clip.from,
|
|
1139
|
-
context: windowSignal ? request.context : void 0
|
|
1140
|
-
});
|
|
1141
|
-
if (file && cache && file === kindCacheFile(cache.dir, target, request, sampleRate))
|
|
1142
|
-
cacheKindAnalysis(file, analysis);
|
|
1143
|
-
return analysis;
|
|
1144
|
-
}
|
|
1145
|
-
async function wholeClipKind(target, signal, request, stream, cache) {
|
|
1146
|
-
try {
|
|
1147
|
-
const kind = await clipKind(
|
|
1148
|
-
target,
|
|
1149
|
-
request,
|
|
1150
|
-
stream,
|
|
1151
|
-
cache,
|
|
1152
|
-
coversPart(target) ? void 0 : signal
|
|
1153
|
-
);
|
|
1154
|
-
if (!kind) throw new Error("no audio stream");
|
|
1155
|
-
return kind;
|
|
1156
|
-
} catch (error) {
|
|
1157
|
-
const kind = await analyzeSignal(signal, { ...request, capabilities: ["kind"] });
|
|
1158
|
-
kind.warnings.push(
|
|
1159
|
-
`kind uses only the selected range: could not analyze the whole clip (${firstLine2(error)})`
|
|
1160
|
-
);
|
|
1161
|
-
return kind;
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
var firstLine2 = (error) => error instanceof Error ? error.message.split("\n")[0] : String(error);
|
|
1165
|
-
var between = (from, to) => (t) => t >= from && t < to;
|
|
1166
|
-
function beatsBetween(value, from, to) {
|
|
1167
|
-
const keep = value.times.map(between(from, to));
|
|
1168
|
-
return {
|
|
1169
|
-
...value,
|
|
1170
|
-
times: value.times.filter((_, i) => keep[i]),
|
|
1171
|
-
unheard: value.unheard.filter((_, i) => keep[i])
|
|
1172
|
-
};
|
|
1173
|
-
}
|
|
1174
|
-
var PULSE_BEATS = 2;
|
|
1175
|
-
var heardTimes = (beats) => beats.times.filter((_, i) => !beats.unheard[i]);
|
|
1176
|
-
var CUTS = {
|
|
1177
|
-
beats: (_value, { beats, pulse }) => pulse ? beats : { times: [], unheard: [], confidence: 0, reason: "no steady beat" },
|
|
1178
|
-
downbeats: (value, { from, to, pulse }) => pulse ? beatsBetween(value, from, to) : { times: [], unheard: [], meter: null, confidence: "low" },
|
|
1179
|
-
bpm: (value, { from, to, beats, pulse }) => pulse && beats ? {
|
|
1180
|
-
value: tempoOf(heardTimes(beats)).value,
|
|
1181
|
-
curve: value.curve.filter((point) => between(from, to)(point.t))
|
|
1182
|
-
} : { value: null, curve: [] },
|
|
1183
|
-
sections: (value, { from, to }) => {
|
|
1184
|
-
const sections = value;
|
|
1185
|
-
return { ...sections, spans: sections.spans.filter((s3) => s3.end > from && s3.start < to) };
|
|
1186
|
-
}
|
|
1187
|
-
};
|
|
1188
|
-
var beatsIn = (values, from, to) => values.beats ? beatsBetween(values.beats, from, to) : null;
|
|
1189
|
-
var pulseIn = (beats) => !!beats && heardTimes(beats).length >= Math.max(PULSE_BEATS, beats.times.length / 2);
|
|
1190
|
-
function rhythmBetween(values, asked, from, to) {
|
|
1191
|
-
const beats = beatsIn(values, from, to);
|
|
1192
|
-
const window = { from, to, beats, pulse: pulseIn(beats) };
|
|
1193
|
-
return Object.fromEntries(
|
|
1194
|
-
asked.map((capability) => {
|
|
1195
|
-
const value = values[capability];
|
|
1196
|
-
return [capability, value == null ? value : CUTS[capability]?.(value, window) ?? value];
|
|
1197
|
-
})
|
|
1198
|
-
);
|
|
1199
|
-
}
|
|
1200
|
-
async function wholeClipRhythm(target, signal, request, stream) {
|
|
1201
|
-
const asked = request.capabilities.filter((capability) => RHYTHM.includes(capability));
|
|
1202
|
-
try {
|
|
1203
|
-
const rate = Math.min(stream.sampleRate, RHYTHM_SAMPLE_RATE);
|
|
1204
|
-
const clip = await clipKindSignal(target, stream, rate, void 0, "rhythm");
|
|
1205
|
-
if (!clip) throw new Error("no audio stream");
|
|
1206
|
-
const needsBeats = asked.some((c) => c === "bpm" || c === "downbeats");
|
|
1207
|
-
const measure = needsBeats && !asked.includes("beats") ? [...asked, "beats"] : asked;
|
|
1208
|
-
const whole = await analyzeSignal(clip, {
|
|
1209
|
-
...request,
|
|
1210
|
-
capabilities: measure,
|
|
1211
|
-
fileOffset: target.clip.from,
|
|
1212
|
-
context: void 0
|
|
1213
|
-
});
|
|
1214
|
-
const from = request.fileOffset ?? 0;
|
|
1215
|
-
const to = from + target.window.seconds;
|
|
1216
|
-
const cut = rhythmBetween(whole.values, asked, from, to);
|
|
1217
|
-
const beatAnswers = asked.filter((capability) => capability !== "sections");
|
|
1218
|
-
if (!beatAnswers.length || pulseIn(beatsIn(whole.values, from, to)))
|
|
1219
|
-
return { ...whole, values: cut };
|
|
1220
|
-
const own = await analyzeSignal(signal, { ...request, capabilities: beatAnswers });
|
|
1221
|
-
return {
|
|
1222
|
-
...own,
|
|
1223
|
-
values: { ...cut, ...own.values },
|
|
1224
|
-
provenance: { ...whole.provenance, ...own.provenance },
|
|
1225
|
-
ladder: { ...whole.ladder, ...own.ladder },
|
|
1226
|
-
warnings: [.../* @__PURE__ */ new Set([...whole.warnings, ...own.warnings])]
|
|
1227
|
-
};
|
|
1228
|
-
} catch (error) {
|
|
1229
|
-
const rhythm2 = await analyzeSignal(signal, { ...request, capabilities: asked });
|
|
1230
|
-
rhythm2.warnings.push(
|
|
1231
|
-
`beats, bars and sections use only the selected range: could not analyze the whole clip (${firstLine2(error)})`
|
|
1232
|
-
);
|
|
1233
|
-
return rhythm2;
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
async function analyzeWindow(target, signal, request, stream, cache) {
|
|
1237
|
-
const kindApart = request.capabilities.includes("kind") && target.clip !== void 0;
|
|
1238
|
-
const rhythmApart = coversPart(target) && request.capabilities.some((capability) => RHYTHM.includes(capability));
|
|
1239
|
-
if (!kindApart && !rhythmApart) return analyzeSignal(signal, request);
|
|
1240
|
-
const apart = (capability) => kindApart && capability === "kind" || rhythmApart && RHYTHM.includes(capability);
|
|
1241
|
-
const parts = [
|
|
1242
|
-
await analyzeSignal(signal, {
|
|
1243
|
-
...request,
|
|
1244
|
-
capabilities: request.capabilities.filter((capability) => !apart(capability))
|
|
1245
|
-
}),
|
|
1246
|
-
...kindApart ? [await wholeClipKind(target, signal, request, stream, cache)] : [],
|
|
1247
|
-
...rhythmApart ? [await wholeClipRhythm(target, signal, request, stream)] : []
|
|
1248
|
-
];
|
|
1249
|
-
const [window] = parts;
|
|
1250
|
-
return {
|
|
1251
|
-
...window,
|
|
1252
|
-
values: Object.assign({}, ...parts.map((part) => part.values)),
|
|
1253
|
-
provenance: Object.assign({}, ...parts.map((part) => part.provenance)),
|
|
1254
|
-
ladder: Object.assign({}, ...parts.map((part) => part.ladder)),
|
|
1255
|
-
warnings: [...new Set(parts.flatMap((part) => part.warnings))]
|
|
1256
|
-
};
|
|
1257
|
-
}
|
|
1258
|
-
async function analyzeTarget(target, request, full, cacheDir) {
|
|
1259
|
-
const item = emptyItem(target);
|
|
1260
|
-
const problem = unreadable(target);
|
|
1261
|
-
if (problem) return { ...item, error: problem };
|
|
1262
|
-
const stream = await probeAudio(target.path);
|
|
1263
|
-
if (!stream) return { ...item, error: "no audio stream" };
|
|
1264
|
-
const cache = cacheDir ? { dir: cacheDir, identity: kindSourceIdentity(target.path) } : void 0;
|
|
1265
|
-
const { from, read: read2, context } = decodeSpan(target, stream);
|
|
1266
|
-
const decoded = await decodeAudio(target.path, read2, stream);
|
|
1267
|
-
if (!decoded) return { ...item, error: "no audio stream" };
|
|
1268
|
-
const analysis = await analyzeWindow(
|
|
1269
|
-
target,
|
|
1270
|
-
decoded.signal,
|
|
1271
|
-
{ ...request, fileOffset: from, context },
|
|
1272
|
-
stream,
|
|
1273
|
-
cache
|
|
1274
|
-
);
|
|
1275
|
-
return {
|
|
1276
|
-
...item,
|
|
1277
|
-
window: { from: round5(from), to: round5(from + analysis.analyzed) },
|
|
1278
|
-
duration: round5(stream.duration),
|
|
1279
|
-
sampleRate: stream.sampleRate,
|
|
1280
|
-
channels: stream.channels,
|
|
1281
|
-
...analysis.values,
|
|
1282
|
-
provenance: analysis.provenance,
|
|
1283
|
-
...full ? { ladder: analysis.ladder } : {},
|
|
1284
|
-
warnings: [
|
|
1285
|
-
...analysis.warnings,
|
|
1286
|
-
...await skippedPeak(
|
|
1287
|
-
target,
|
|
1288
|
-
retained(decoded.signal, context.before, context.after),
|
|
1289
|
-
stream
|
|
1290
|
-
)
|
|
1291
|
-
]
|
|
1292
|
-
};
|
|
1293
|
-
}
|
|
1294
|
-
async function analyzeTargets(targets, request, full = false, cacheDir) {
|
|
1295
|
-
const items = [];
|
|
1296
|
-
for (const target of targets) {
|
|
1297
|
-
try {
|
|
1298
|
-
items.push(await analyzeTarget(target, request, full, cacheDir));
|
|
1299
|
-
} catch (error) {
|
|
1300
|
-
const reason = error instanceof Error ? error.message.split("\n")[0] : String(error);
|
|
1301
|
-
items.push({ ...emptyItem(target), error: `could not read: ${reason}` });
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
return { version: 1, items };
|
|
1305
|
-
}
|
|
1306
|
-
|
|
1307
300
|
// src/audio/read/pitch.ts
|
|
1308
|
-
function
|
|
301
|
+
function within(track, start, end) {
|
|
1309
302
|
let lo = 0;
|
|
1310
|
-
let hi =
|
|
303
|
+
let hi = track.length;
|
|
1311
304
|
while (lo < hi) {
|
|
1312
305
|
const mid = lo + hi >> 1;
|
|
1313
|
-
if (
|
|
306
|
+
if (track[mid].t < start) lo = mid + 1;
|
|
1314
307
|
else hi = mid;
|
|
1315
308
|
}
|
|
1316
309
|
const out = [];
|
|
1317
|
-
for (let i = lo; i <
|
|
310
|
+
for (let i = lo; i < track.length && track[i].t < end; i++) out.push(track[i].hz);
|
|
1318
311
|
return out;
|
|
1319
312
|
}
|
|
1320
313
|
var semitones = (a, b) => 12 * Math.log2(a / b);
|
|
@@ -1479,16 +472,16 @@ function formatRead(analysis, range) {
|
|
|
1479
472
|
}
|
|
1480
473
|
|
|
1481
474
|
// src/audio/read/read.ts
|
|
1482
|
-
import { createHash
|
|
475
|
+
import { createHash } from "crypto";
|
|
1483
476
|
import {
|
|
1484
477
|
createReadStream,
|
|
1485
|
-
existsSync as
|
|
1486
|
-
mkdirSync as
|
|
1487
|
-
readFileSync as
|
|
1488
|
-
renameSync
|
|
1489
|
-
writeFileSync as
|
|
478
|
+
existsSync as existsSync2,
|
|
479
|
+
mkdirSync as mkdirSync2,
|
|
480
|
+
readFileSync as readFileSync2,
|
|
481
|
+
renameSync,
|
|
482
|
+
writeFileSync as writeFileSync2
|
|
1490
483
|
} from "fs";
|
|
1491
|
-
import { basename, extname, join as
|
|
484
|
+
import { basename, extname, join as join3 } from "path";
|
|
1492
485
|
|
|
1493
486
|
// src/audio/read/signal.ts
|
|
1494
487
|
var READ_RATE = 22050;
|
|
@@ -1509,7 +502,7 @@ var asSignal = (samples, sampleRate = READ_RATE) => ({
|
|
|
1509
502
|
function mixed(tracks) {
|
|
1510
503
|
const length = Math.max(0, ...tracks.map((t) => t.length));
|
|
1511
504
|
const sum = new Float32Array(length);
|
|
1512
|
-
for (const
|
|
505
|
+
for (const track of tracks) for (let i = 0; i < track.length; i++) sum[i] += track[i];
|
|
1513
506
|
return sum;
|
|
1514
507
|
}
|
|
1515
508
|
function levels(samples, sampleRate, hop, window = hop * 2) {
|
|
@@ -1544,7 +537,7 @@ function quantile(values, q) {
|
|
|
1544
537
|
return sorted[Math.min(sorted.length - 1, Math.max(0, Math.floor(q * (sorted.length - 1))))];
|
|
1545
538
|
}
|
|
1546
539
|
var median = (values) => quantile(values, 0.5);
|
|
1547
|
-
var
|
|
540
|
+
var round2 = (n, places = 2) => {
|
|
1548
541
|
const k = 10 ** places;
|
|
1549
542
|
return Math.round(n * k) / k;
|
|
1550
543
|
};
|
|
@@ -1592,16 +585,16 @@ function floors(db) {
|
|
|
1592
585
|
return out;
|
|
1593
586
|
}
|
|
1594
587
|
var BLOCK = 1e-3;
|
|
1595
|
-
function refined(samples, sampleRate,
|
|
588
|
+
function refined(samples, sampleRate, frame, floorDb) {
|
|
1596
589
|
const block = Math.max(1, Math.round(BLOCK * sampleRate));
|
|
1597
|
-
const from = Math.max(0, Math.round((
|
|
1598
|
-
const to = Math.min(samples.length, Math.round((
|
|
590
|
+
const from = Math.max(0, Math.round((frame - 2) * HOP * sampleRate));
|
|
591
|
+
const to = Math.min(samples.length, Math.round((frame + 2) * HOP * sampleRate));
|
|
1599
592
|
for (let a = from; a + block <= to; a += block) {
|
|
1600
593
|
let power = 0;
|
|
1601
594
|
for (let i = a; i < a + block; i++) power += samples[i] ** 2;
|
|
1602
595
|
if (10 * Math.log10(power / block + 1e-12) >= floorDb + RISE_DB / 2) return a / sampleRate;
|
|
1603
596
|
}
|
|
1604
|
-
return
|
|
597
|
+
return frame * HOP;
|
|
1605
598
|
}
|
|
1606
599
|
function onsetOf(db, f, base2, from) {
|
|
1607
600
|
let onset = f;
|
|
@@ -1784,7 +777,7 @@ function foundIn({ samples: source, heldBy = [] }, input, mixDb) {
|
|
|
1784
777
|
return { ...f, ...kindOf(f, power), print: printOf(power) };
|
|
1785
778
|
});
|
|
1786
779
|
}
|
|
1787
|
-
function
|
|
780
|
+
function measured(input, mixDb) {
|
|
1788
781
|
const all = input.sources.flatMap((source) => foundIn(source, input, mixDb)).sort((a, b) => a.t - b.t);
|
|
1789
782
|
const out = [];
|
|
1790
783
|
for (const sound of all) {
|
|
@@ -1834,20 +827,20 @@ function drumGroups(members, beats) {
|
|
|
1834
827
|
}
|
|
1835
828
|
function effectOf(m, group, kind, levels2) {
|
|
1836
829
|
return {
|
|
1837
|
-
t:
|
|
1838
|
-
end:
|
|
830
|
+
t: round2(m.t),
|
|
831
|
+
end: round2(m.end),
|
|
1839
832
|
kind,
|
|
1840
833
|
group,
|
|
1841
834
|
band: m.band,
|
|
1842
835
|
attackMs: Math.round((m.peak - m.t) * 1e3),
|
|
1843
|
-
tail:
|
|
836
|
+
tail: round2(m.end - m.peak),
|
|
1844
837
|
...levels2,
|
|
1845
838
|
count: 1
|
|
1846
839
|
};
|
|
1847
840
|
}
|
|
1848
841
|
function findEffects(input) {
|
|
1849
842
|
const mixDb = levels(input.mix, input.sampleRate, HOP);
|
|
1850
|
-
const sounds =
|
|
843
|
+
const sounds = measured(input, mixDb);
|
|
1851
844
|
const members = /* @__PURE__ */ new Map();
|
|
1852
845
|
for (const m of sounds) members.set(m.group, [...members.get(m.group) ?? [], m]);
|
|
1853
846
|
const drums = drumGroups(members, input.beats);
|
|
@@ -1865,7 +858,7 @@ function findEffects(input) {
|
|
|
1865
858
|
const group = names.get(m.group);
|
|
1866
859
|
const previous = events[events.length - 1];
|
|
1867
860
|
if (previous?.group === group && m.t - previous.end <= TRAIN_GAP) {
|
|
1868
|
-
previous.end =
|
|
861
|
+
previous.end = round2(m.end);
|
|
1869
862
|
previous.count++;
|
|
1870
863
|
} else
|
|
1871
864
|
events.push(effectOf(m, group, kindOfGroup.get(group) ?? m.kind, levelsOf(input, mixDb, m)));
|
|
@@ -1954,10 +947,10 @@ function runs(db) {
|
|
|
1954
947
|
const merged = candidates(quiet, 0, db.length).flatMap(
|
|
1955
948
|
(span) => span.quiet && !holdsUp(db, span) ? silencesIn(db, span) : [span]
|
|
1956
949
|
);
|
|
1957
|
-
const
|
|
950
|
+
const settled = joined(merged, (s3) => !s3.quiet && s3.end - s3.start < SHORTEST_SEGMENT);
|
|
1958
951
|
return {
|
|
1959
|
-
segments:
|
|
1960
|
-
breaks:
|
|
952
|
+
segments: settled.filter((s3) => !s3.quiet),
|
|
953
|
+
breaks: settled.filter((s3) => s3.quiet && s3.start > 0 && s3.end < db.length * HOP2)
|
|
1961
954
|
};
|
|
1962
955
|
}
|
|
1963
956
|
function soundShare(fine, run) {
|
|
@@ -2062,7 +1055,7 @@ function fadeFrom(db, run) {
|
|
|
2062
1055
|
const last = db[b - 1] ?? body;
|
|
2063
1056
|
if (body - last < FADE_DB) return null;
|
|
2064
1057
|
for (let f = Math.max(a, b - FADE_WINDOW / HOP2); f < b; f++)
|
|
2065
|
-
if (db[f] < body - 3) return
|
|
1058
|
+
if (db[f] < body - 3) return round2(f * HOP2, 1);
|
|
2066
1059
|
return null;
|
|
2067
1060
|
}
|
|
2068
1061
|
var leading = (mix) => Object.entries(mix).filter(([, share]) => share >= LEADING_SHARE).sort((a, b) => b[1] - a[1]).map(([name]) => name);
|
|
@@ -2079,7 +1072,7 @@ function newPiece(id, heard) {
|
|
|
2079
1072
|
id,
|
|
2080
1073
|
instruments: leading(heard.mix),
|
|
2081
1074
|
bpm: heard.bpm,
|
|
2082
|
-
firstAt:
|
|
1075
|
+
firstAt: round2(heard.run.start),
|
|
2083
1076
|
print: heard.print,
|
|
2084
1077
|
mix: heard.mix
|
|
2085
1078
|
};
|
|
@@ -2100,7 +1093,7 @@ function energyCurve(melodic, sampleRate, duration, musical) {
|
|
|
2100
1093
|
) / (end - start);
|
|
2101
1094
|
energy.push({
|
|
2102
1095
|
start,
|
|
2103
|
-
end: Math.min(
|
|
1096
|
+
end: Math.min(round2(end), round2(duration, 3)),
|
|
2104
1097
|
db: power > 0 ? Math.round(10 * Math.log10(power)) : -120
|
|
2105
1098
|
});
|
|
2106
1099
|
}
|
|
@@ -2134,8 +1127,8 @@ function readMusic(input) {
|
|
|
2134
1127
|
};
|
|
2135
1128
|
if (!isMusic(heard)) {
|
|
2136
1129
|
ambience.push({
|
|
2137
|
-
start:
|
|
2138
|
-
end: Math.min(
|
|
1130
|
+
start: round2(run.start),
|
|
1131
|
+
end: Math.min(round2(run.end), round2(duration, 3)),
|
|
2139
1132
|
db: Math.round(10 * Math.log10(Math.max(1e-12, energyOf(melodic, input.sampleRate, run))))
|
|
2140
1133
|
});
|
|
2141
1134
|
continue;
|
|
@@ -2151,8 +1144,8 @@ function readMusic(input) {
|
|
|
2151
1144
|
entry = previous ? "new" : "start";
|
|
2152
1145
|
}
|
|
2153
1146
|
segments.push({
|
|
2154
|
-
start:
|
|
2155
|
-
end: Math.min(
|
|
1147
|
+
start: round2(run.start),
|
|
1148
|
+
end: Math.min(round2(run.end), round2(duration, 3)),
|
|
2156
1149
|
piece: piece.id,
|
|
2157
1150
|
entry,
|
|
2158
1151
|
bpm: heard.bpm,
|
|
@@ -2163,7 +1156,7 @@ function readMusic(input) {
|
|
|
2163
1156
|
music: {
|
|
2164
1157
|
segments,
|
|
2165
1158
|
pieces: pieces.map(({ print: _print, mix: _mix, ...piece }) => piece),
|
|
2166
|
-
breaks: breaks.filter((b) => liesBetweenMusic(found, b, musical)).map((b) => ({ start:
|
|
1159
|
+
breaks: breaks.filter((b) => liesBetweenMusic(found, b, musical)).map((b) => ({ start: round2(b.start), end: round2(b.end) })),
|
|
2167
1160
|
energy: energyCurve(melodic, input.sampleRate, duration, musical)
|
|
2168
1161
|
},
|
|
2169
1162
|
ambience,
|
|
@@ -2172,33 +1165,33 @@ function readMusic(input) {
|
|
|
2172
1165
|
}
|
|
2173
1166
|
|
|
2174
1167
|
// src/audio/read/stems.ts
|
|
2175
|
-
import { randomUUID
|
|
2176
|
-
import { existsSync
|
|
2177
|
-
import { mkdtemp
|
|
2178
|
-
import { tmpdir
|
|
2179
|
-
import { join as
|
|
1168
|
+
import { randomUUID } from "crypto";
|
|
1169
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs";
|
|
1170
|
+
import { mkdtemp, rm } from "fs/promises";
|
|
1171
|
+
import { tmpdir } from "os";
|
|
1172
|
+
import { join as join2 } from "path";
|
|
2180
1173
|
import { setTimeout as sleep } from "timers/promises";
|
|
2181
|
-
var
|
|
2182
|
-
var
|
|
2183
|
-
var
|
|
2184
|
-
var
|
|
1174
|
+
var URL_ENV = "HYPERFRAMES_AUDIO_STEMS_URL";
|
|
1175
|
+
var KEY_ENV = "HYPERFRAMES_AUDIO_API_KEY";
|
|
1176
|
+
var TIMEOUT_ENV = "HYPERFRAMES_AUDIO_STEMS_TIMEOUT_MS";
|
|
1177
|
+
var DEFAULT_TIMEOUT_MS = 30 * 6e4;
|
|
2185
1178
|
var RETRY_MS = 5e3;
|
|
2186
1179
|
var DONE = "stems.json";
|
|
2187
1180
|
var STEM_NAMES = ["vocals", "drums", "bass", "guitar", "piano", "other"];
|
|
2188
1181
|
var VOICE_STEM = "vocals";
|
|
2189
1182
|
var DRUM_STEM = "drums";
|
|
2190
1183
|
var stemsAccess = () => serviceAccess(
|
|
2191
|
-
{ url:
|
|
1184
|
+
{ url: URL_ENV, key: KEY_ENV, timeout: TIMEOUT_ENV },
|
|
2192
1185
|
"/v3/audio/stems",
|
|
2193
|
-
|
|
1186
|
+
DEFAULT_TIMEOUT_MS
|
|
2194
1187
|
);
|
|
2195
1188
|
function cachedStems(dir) {
|
|
2196
|
-
const done =
|
|
2197
|
-
if (!
|
|
2198
|
-
const names = JSON.parse(
|
|
1189
|
+
const done = join2(dir, DONE);
|
|
1190
|
+
if (!existsSync(done)) return null;
|
|
1191
|
+
const names = JSON.parse(readFileSync(done, "utf8"));
|
|
2199
1192
|
if (!STEM_NAMES.every((name) => typeof names[name] === "string")) return null;
|
|
2200
|
-
const paths = Object.fromEntries(STEM_NAMES.map((name) => [name,
|
|
2201
|
-
return Object.values(paths).every((p) =>
|
|
1193
|
+
const paths = Object.fromEntries(STEM_NAMES.map((name) => [name, join2(dir, names[name])]));
|
|
1194
|
+
return Object.values(paths).every((p) => existsSync(p)) ? paths : null;
|
|
2202
1195
|
}
|
|
2203
1196
|
var StillRunning = class extends Error {
|
|
2204
1197
|
};
|
|
@@ -2222,7 +1215,7 @@ async function encoded(path, dir, signal) {
|
|
|
2222
1215
|
if (!ffmpeg) throw new Error("ffmpeg is required to separate stems; run: npx hyperframes doctor");
|
|
2223
1216
|
const audio = await probeAudio(path);
|
|
2224
1217
|
if (!audio) throw new Error("the recording has no audio track ffmpeg can decode");
|
|
2225
|
-
const out =
|
|
1218
|
+
const out = join2(dir, "upload.mp3");
|
|
2226
1219
|
await runFile(
|
|
2227
1220
|
ffmpeg,
|
|
2228
1221
|
[
|
|
@@ -2245,7 +1238,7 @@ async function separated(url, request, signal) {
|
|
|
2245
1238
|
}
|
|
2246
1239
|
async function fetchStems(path, dir, { url, headers, timeoutMs }) {
|
|
2247
1240
|
const signal = AbortSignal.timeout(timeoutMs);
|
|
2248
|
-
const scratch = await
|
|
1241
|
+
const scratch = await mkdtemp(join2(tmpdir(), "hf-stems-"));
|
|
2249
1242
|
try {
|
|
2250
1243
|
const mp3 = await encoded(path, scratch, signal);
|
|
2251
1244
|
const client = new HyperframesCloudClient({
|
|
@@ -2256,10 +1249,10 @@ async function fetchStems(path, dir, { url, headers, timeoutMs }) {
|
|
|
2256
1249
|
const asset = await uploadAssetViaDirectUpload({
|
|
2257
1250
|
client,
|
|
2258
1251
|
path: mp3,
|
|
2259
|
-
size:
|
|
1252
|
+
size: statSync(mp3).size,
|
|
2260
1253
|
filename: "audio.mp3",
|
|
2261
1254
|
contentType: "audio/mpeg",
|
|
2262
|
-
idempotencyKey:
|
|
1255
|
+
idempotencyKey: randomUUID(),
|
|
2263
1256
|
signal
|
|
2264
1257
|
});
|
|
2265
1258
|
const current = await separated(
|
|
@@ -2269,7 +1262,7 @@ async function fetchStems(path, dir, { url, headers, timeoutMs }) {
|
|
|
2269
1262
|
redirect: "error",
|
|
2270
1263
|
headers: {
|
|
2271
1264
|
...headers,
|
|
2272
|
-
"idempotency-key":
|
|
1265
|
+
"idempotency-key": randomUUID(),
|
|
2273
1266
|
"content-type": "application/json"
|
|
2274
1267
|
},
|
|
2275
1268
|
body: JSON.stringify({ version: 1, audio: { type: "asset_id", asset_id: asset.asset_id } })
|
|
@@ -2286,19 +1279,19 @@ async function fetchStems(path, dir, { url, headers, timeoutMs }) {
|
|
|
2286
1279
|
throw new Error(
|
|
2287
1280
|
`the stems service returned an incomplete separation: missing ${missing.join(", ")}`
|
|
2288
1281
|
);
|
|
2289
|
-
|
|
1282
|
+
mkdirSync(dir, { recursive: true });
|
|
2290
1283
|
const names = {};
|
|
2291
1284
|
for (const name of STEM_NAMES) {
|
|
2292
1285
|
const stem = stems.find((candidate) => candidate.name === name);
|
|
2293
1286
|
if (!stem) continue;
|
|
2294
1287
|
const file = `${name}.audio`;
|
|
2295
|
-
await downloadToFile(stem.url,
|
|
1288
|
+
await downloadToFile(stem.url, join2(dir, file), { signal });
|
|
2296
1289
|
names[name] = file;
|
|
2297
1290
|
}
|
|
2298
|
-
|
|
1291
|
+
writeFileSync(join2(dir, DONE), JSON.stringify(names));
|
|
2299
1292
|
return cachedStems(dir);
|
|
2300
1293
|
} finally {
|
|
2301
|
-
await
|
|
1294
|
+
await rm(scratch, { recursive: true, force: true });
|
|
2302
1295
|
}
|
|
2303
1296
|
}
|
|
2304
1297
|
|
|
@@ -2341,32 +1334,32 @@ function sentenceGroups(words) {
|
|
|
2341
1334
|
});
|
|
2342
1335
|
return groups;
|
|
2343
1336
|
}
|
|
2344
|
-
function ending(
|
|
1337
|
+
function ending(track, start, end) {
|
|
2345
1338
|
const split = start + (end - start) * 0.7;
|
|
2346
|
-
const body =
|
|
2347
|
-
const tail =
|
|
1339
|
+
const body = within(track, start, split);
|
|
1340
|
+
const tail = within(track, split, end);
|
|
2348
1341
|
if (body.length < MIN_PITCH_FRAMES || tail.length < 2) return null;
|
|
2349
1342
|
const shift = semitones(median(tail), median(body));
|
|
2350
1343
|
if (shift >= ENDING_SEMITONES) return "rising";
|
|
2351
1344
|
if (shift <= -ENDING_SEMITONES) return "falling";
|
|
2352
1345
|
return "level";
|
|
2353
1346
|
}
|
|
2354
|
-
function pitchOf(
|
|
2355
|
-
const hz =
|
|
1347
|
+
function pitchOf(track, start, end) {
|
|
1348
|
+
const hz = within(track, start, end);
|
|
2356
1349
|
return hz.length >= MIN_PITCH_FRAMES ? Math.round(median(hz)) : null;
|
|
2357
1350
|
}
|
|
2358
|
-
function summary(sentences, pauses,
|
|
1351
|
+
function summary(sentences, pauses, track) {
|
|
2359
1352
|
const timed = sentences.filter((s3) => s3.rate !== null);
|
|
2360
1353
|
const seconds = timed.reduce((n, s3) => n + (s3.end - s3.start), 0);
|
|
2361
|
-
const meanRate = seconds ?
|
|
1354
|
+
const meanRate = seconds ? round2(timed.reduce((n, s3) => n + s3.rate * (s3.end - s3.start), 0) / seconds, 1) : null;
|
|
2362
1355
|
return {
|
|
2363
1356
|
sentences,
|
|
2364
1357
|
pauses,
|
|
2365
1358
|
meanRate,
|
|
2366
|
-
medianPitchHz:
|
|
1359
|
+
medianPitchHz: track.length ? Math.round(median(track.map((p) => p.hz))) : null
|
|
2367
1360
|
};
|
|
2368
1361
|
}
|
|
2369
|
-
function voiceFromWords(words,
|
|
1362
|
+
function voiceFromWords(words, track, levelOf) {
|
|
2370
1363
|
const ordered = words.filter((w) => w.end > w.start).sort((a, b) => a.start - b.start);
|
|
2371
1364
|
const unit = rateUnit(ordered);
|
|
2372
1365
|
const sentences = sentenceGroups(ordered).map((group) => {
|
|
@@ -2374,12 +1367,12 @@ function voiceFromWords(words, track2, levelOf) {
|
|
|
2374
1367
|
const end = group[group.length - 1].end;
|
|
2375
1368
|
const count = spoken(group, unit);
|
|
2376
1369
|
return {
|
|
2377
|
-
start:
|
|
2378
|
-
end:
|
|
1370
|
+
start: round2(start),
|
|
1371
|
+
end: round2(end),
|
|
2379
1372
|
text: joined2(group, unit),
|
|
2380
|
-
rate: count && end > start ?
|
|
2381
|
-
pitchHz: pitchOf(
|
|
2382
|
-
ending: ending(
|
|
1373
|
+
rate: count && end > start ? round2(count / (end - start), 1) : null,
|
|
1374
|
+
pitchHz: pitchOf(track, start, end),
|
|
1375
|
+
ending: ending(track, start, end),
|
|
2383
1376
|
againstMusic: null
|
|
2384
1377
|
};
|
|
2385
1378
|
});
|
|
@@ -2387,15 +1380,15 @@ function voiceFromWords(words, track2, levelOf) {
|
|
|
2387
1380
|
for (let i = 1; i < ordered.length; i++) {
|
|
2388
1381
|
const gap = ordered[i].start - ordered[i - 1].end;
|
|
2389
1382
|
if (gap >= PAUSE_SECONDS) {
|
|
2390
|
-
const span = { start:
|
|
1383
|
+
const span = { start: round2(ordered[i - 1].end), end: round2(ordered[i].start) };
|
|
2391
1384
|
pauses.push({ ...span, recordingDb: Math.round(levelOf(span)) });
|
|
2392
1385
|
}
|
|
2393
1386
|
}
|
|
2394
|
-
return { source: "transcript", unit, ...summary(sentences, pauses,
|
|
1387
|
+
return { source: "transcript", unit, ...summary(sentences, pauses, track) };
|
|
2395
1388
|
}
|
|
2396
1389
|
var ACTIVITY_HOP = 0.05;
|
|
2397
1390
|
var SHORTEST_SPEECH = 0.3;
|
|
2398
|
-
function voiceFromActivity(vocals, sampleRate,
|
|
1391
|
+
function voiceFromActivity(vocals, sampleRate, track, levelOf) {
|
|
2399
1392
|
const db = levels(vocals, sampleRate, ACTIVITY_HOP);
|
|
2400
1393
|
const threshold = Math.max(-45, quantile(db, 0.9) - 30);
|
|
2401
1394
|
const spans = [];
|
|
@@ -2420,41 +1413,41 @@ function voiceFromActivity(vocals, sampleRate, track2, levelOf) {
|
|
|
2420
1413
|
spans.push({ start, end: quietSince ?? end });
|
|
2421
1414
|
const sentences = spans.map(
|
|
2422
1415
|
(s3) => ({
|
|
2423
|
-
start:
|
|
2424
|
-
end:
|
|
1416
|
+
start: round2(s3.start),
|
|
1417
|
+
end: round2(s3.end),
|
|
2425
1418
|
text: null,
|
|
2426
1419
|
rate: null,
|
|
2427
|
-
pitchHz: pitchOf(
|
|
2428
|
-
ending: ending(
|
|
1420
|
+
pitchHz: pitchOf(track, s3.start, s3.end),
|
|
1421
|
+
ending: ending(track, s3.start, s3.end),
|
|
2429
1422
|
againstMusic: null
|
|
2430
1423
|
})
|
|
2431
1424
|
);
|
|
2432
1425
|
const pauses = spans.slice(1).map((s3, i) => {
|
|
2433
|
-
const span = { start:
|
|
1426
|
+
const span = { start: round2(spans[i].end), end: round2(s3.start) };
|
|
2434
1427
|
return { ...span, recordingDb: Math.round(levelOf(span)) };
|
|
2435
1428
|
});
|
|
2436
|
-
return { source: "activity", unit: "chars", ...summary(sentences, pauses,
|
|
1429
|
+
return { source: "activity", unit: "chars", ...summary(sentences, pauses, track) };
|
|
2437
1430
|
}
|
|
2438
1431
|
|
|
2439
1432
|
// src/audio/read/read.ts
|
|
2440
1433
|
async function sha256(path) {
|
|
2441
|
-
const hash =
|
|
1434
|
+
const hash = createHash("sha256");
|
|
2442
1435
|
for await (const chunk of createReadStream(path)) hash.update(chunk);
|
|
2443
1436
|
return hash.digest("hex");
|
|
2444
1437
|
}
|
|
2445
1438
|
function transcriptFor(path, given) {
|
|
2446
1439
|
if (given) return given;
|
|
2447
1440
|
const sidecar = `${path}.transcript.json`;
|
|
2448
|
-
return
|
|
1441
|
+
return existsSync2(sidecar) ? sidecar : null;
|
|
2449
1442
|
}
|
|
2450
1443
|
function wordsOf(transcript) {
|
|
2451
1444
|
return loadTranscript(transcript).words.map(({ text, start, end }) => ({ text, start, end }));
|
|
2452
1445
|
}
|
|
2453
|
-
var fingerprint = (path) => path ?
|
|
1446
|
+
var fingerprint = (path) => path ? createHash("sha256").update(readFileSync2(path)).digest("hex").slice(0, 16) : "none";
|
|
2454
1447
|
function writeAtomic(path, content) {
|
|
2455
1448
|
const temporary = `${path}.${process.pid}.tmp`;
|
|
2456
|
-
|
|
2457
|
-
|
|
1449
|
+
writeFileSync2(temporary, content);
|
|
1450
|
+
renameSync(temporary, path);
|
|
2458
1451
|
}
|
|
2459
1452
|
async function stemsFor(path, dir, quality, warnings) {
|
|
2460
1453
|
const cached = cachedStems(dir);
|
|
@@ -2465,13 +1458,13 @@ async function stemsFor(path, dir, quality, warnings) {
|
|
|
2465
1458
|
);
|
|
2466
1459
|
return null;
|
|
2467
1460
|
}
|
|
2468
|
-
const
|
|
2469
|
-
if (typeof
|
|
2470
|
-
warnings.push(`not separated into stems: ${
|
|
1461
|
+
const access = await stemsAccess();
|
|
1462
|
+
if (typeof access === "string") {
|
|
1463
|
+
warnings.push(`not separated into stems: ${access}`);
|
|
2471
1464
|
return null;
|
|
2472
1465
|
}
|
|
2473
1466
|
try {
|
|
2474
|
-
return await fetchStems(path, dir,
|
|
1467
|
+
return await fetchStems(path, dir, access);
|
|
2475
1468
|
} catch (error) {
|
|
2476
1469
|
warnings.push(`not separated into stems: ${error instanceof Error ? error.message : error}`);
|
|
2477
1470
|
return null;
|
|
@@ -2553,7 +1546,7 @@ async function analyze(path, file, sha, transcript, stemDir, quality) {
|
|
|
2553
1546
|
const words = transcript ? wordsOf(transcript) : [];
|
|
2554
1547
|
const voicePath = stemPaths?.[VOICE_STEM] ?? path;
|
|
2555
1548
|
const voiceSamples = await decodeMono(voicePath);
|
|
2556
|
-
const about = base(file, sha,
|
|
1549
|
+
const about = base(file, sha, round2(voiceSamples.length / READ_RATE, 3), stemPaths, transcript);
|
|
2557
1550
|
if (!stemPaths && !words.length) {
|
|
2558
1551
|
warnings.push(
|
|
2559
1552
|
`no transcript and no stems: voice and effects are not read, because the mix alone does not tell speech from music; ${transcribeHint(file)}`
|
|
@@ -2596,12 +1589,12 @@ async function readAudio(path, file, options) {
|
|
|
2596
1589
|
const transcript = transcriptFor(path, options.transcript);
|
|
2597
1590
|
const transcriptKey = fingerprint(transcript);
|
|
2598
1591
|
const stem = `${basename(file, extname(file)).replace(/[^\w.-]/g, "_")}-${sha.slice(0, 12)}`;
|
|
2599
|
-
|
|
2600
|
-
const jsonPath =
|
|
2601
|
-
const textPath =
|
|
2602
|
-
const stemDir =
|
|
2603
|
-
if (
|
|
2604
|
-
const entry = JSON.parse(
|
|
1592
|
+
mkdirSync2(options.cacheDir, { recursive: true });
|
|
1593
|
+
const jsonPath = join3(options.cacheDir, `${stem}.json`);
|
|
1594
|
+
const textPath = join3(options.cacheDir, `${stem}.txt`);
|
|
1595
|
+
const stemDir = join3(options.cacheDir, "stems", sha.slice(0, 12));
|
|
1596
|
+
if (existsSync2(jsonPath) && existsSync2(textPath)) {
|
|
1597
|
+
const entry = JSON.parse(readFileSync2(jsonPath, "utf8"));
|
|
2605
1598
|
const stemsNowPossible = entry.analysis.separation === "mix" && quality === "best" && (cachedStems(stemDir) !== null || typeof await stemsAccess() !== "string");
|
|
2606
1599
|
if ((entry.analysis.separation !== "stems" || cachedStems(stemDir) !== null) && entry.analysis.version === READ_VERSION && entry.transcriptKey === transcriptKey && !stemsNowPossible)
|
|
2607
1600
|
return { analysis: entry.analysis, textPath, jsonPath, cached: true };
|
|
@@ -2742,7 +1735,7 @@ async function read(files, flags) {
|
|
|
2742
1735
|
const quality = readQuality(files, flags);
|
|
2743
1736
|
const range = pair("range", flags.range);
|
|
2744
1737
|
const result = await readAudio(resolve2(process.cwd(), files[0]), files[0], {
|
|
2745
|
-
cacheDir:
|
|
1738
|
+
cacheDir: join4(resolve2(flags.dir ?? process.cwd()), ".hyperframes", "read-audio"),
|
|
2746
1739
|
transcript: flags.transcript ? resolve2(process.cwd(), flags.transcript) : void 0,
|
|
2747
1740
|
quality
|
|
2748
1741
|
});
|
|
@@ -2832,7 +1825,7 @@ var audio_default = defineCommand({
|
|
|
2832
1825
|
targets,
|
|
2833
1826
|
analyzeRequest(flags),
|
|
2834
1827
|
Boolean(args.full),
|
|
2835
|
-
|
|
1828
|
+
join4(resolve2(flags.dir ?? process.cwd()), ".hyperframes", "audio-kind")
|
|
2836
1829
|
);
|
|
2837
1830
|
console.log(args.json ? JSON.stringify(withMeta(report)) : formatReport(report));
|
|
2838
1831
|
}
|