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