dsh-chat-comprehension 0.2.0 → 0.3.1
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/NOTICE.md +20 -0
- package/README.md +20 -9
- package/client.js +41 -9
- package/lib/engines.mjs +136 -0
- package/lib/index.js +54 -4
- package/lib/qqbot-0.5.3-patches.json +75 -70
- package/lib/qqbot-patch.mjs +12 -7
- package/lib/video.mjs +11 -2
- package/package.json +7 -23
- package/vendor/dsh-agent-md/LICENSE +21 -0
- package/vendor/dsh-agent-md/cordis.patch.yml +8 -0
- package/vendor/dsh-agent-md/lib/index.js +775 -0
- package/vendor/dsh-agent-md/lib/persona.js +634 -0
- package/vendor/dsh-agent-md/lib/qq.js +527 -0
- package/vendor/dsh-agent-md/package.json +50 -0
- package/vendor/dsh-bili-scroll/LICENSE +21 -0
- package/vendor/dsh-bili-scroll/NOTICE.md +18 -0
- package/vendor/dsh-bili-scroll/cordis.patch.yml +20 -0
- package/vendor/dsh-bili-scroll/index.js +3293 -0
- package/vendor/dsh-bili-scroll/lib/asr.py +141 -0
- package/vendor/dsh-bili-scroll/lib/diagnose.mjs +95 -0
- package/vendor/dsh-bili-scroll/lib/dm.mjs +110 -0
- package/vendor/dsh-bili-scroll/lib/favops.py +90 -0
- package/vendor/dsh-bili-scroll/lib/hostdeps.mjs +148 -0
- package/vendor/dsh-bili-scroll/lib/login.mjs +141 -0
- package/vendor/dsh-bili-scroll/lib/mcp.mjs +144 -0
- package/vendor/dsh-bili-scroll/lib/state.mjs +236 -0
- package/vendor/dsh-bili-scroll/lib/uid.mjs +61 -0
- package/vendor/dsh-bili-scroll/lib/uvfetch.mjs +217 -0
- package/vendor/dsh-bili-scroll/lib/verify.mjs +184 -0
- package/vendor/dsh-bili-scroll/package.json +84 -0
- package/vendor/dsh-bili-scroll/profile-template/bili-duty/cordis.patch.yml +116 -0
- package/vendor/dsh-bili-scroll/profile-template/bili-duty/cordis.yml +4 -0
- package/vendor/dsh-bili-scroll/profile-template/bili-duty/package.json +13 -0
- package/vendor/dsh-bili-scroll/prompts/duty.md +296 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/LICENSE +21 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/README.md +176 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/mcp_server.py +2015 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/requirements.txt +10 -0
- package/vendor/dsh-meme/.dsh/skills/dsh-meme-maintenance/SKILL.md +50 -0
- package/vendor/dsh-meme/LICENSE +21 -0
- package/vendor/dsh-meme/anim.js +588 -0
- package/vendor/dsh-meme/cordis.patch.yml +13 -0
- package/vendor/dsh-meme/icon.jpg +0 -0
- package/vendor/dsh-meme/index.js +2616 -0
- package/vendor/dsh-meme/locale/en.json +6 -0
- package/vendor/dsh-meme/locale/zh.json +6 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/index.db +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/manifest.json +13 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/angry/shengqi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/baka/xianqi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/color/huachi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/confused/jiazai.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/confused/wenhao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/cpu/jiaban.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/daily/ganfan.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/fool/buyao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/givemoney/yaoqian.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/deyi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/ok.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/piaole.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/like/bixin.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/meow/maozhua.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/morning/zaoshanghao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sad/qiurao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sad/yun.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/see/zhenjing.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/shy/haixiu.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/shy/toukan.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sigh/wuyu.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sleep/shuijiao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/surprised/xia.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/work/tangping.jpg +0 -0
- package/vendor/dsh-meme/memes.js +998 -0
- package/vendor/dsh-meme/package.json +67 -0
- package/vendor/dsh-meme/panel.html +210 -0
- package/vendor/dsh-video-storyboard/LICENSE +21 -0
- package/vendor/dsh-video-storyboard/NOTICE +12 -0
- package/vendor/dsh-video-storyboard/bin/_args.mjs +16 -0
- package/vendor/dsh-video-storyboard/bin/asr-check.mjs +85 -0
- package/vendor/dsh-video-storyboard/bin/scan-stats.mjs +43 -0
- package/vendor/dsh-video-storyboard/bin/scan-video.mjs +38 -0
- package/vendor/dsh-video-storyboard/bin/storyboard.mjs +195 -0
- package/vendor/dsh-video-storyboard/cordis.patch.yml +3 -0
- package/vendor/dsh-video-storyboard/dsh.plugin.json +12 -0
- package/vendor/dsh-video-storyboard/package.json +88 -0
- package/vendor/dsh-video-storyboard/scripts/check-syntax.mjs +56 -0
- package/vendor/dsh-video-storyboard/scripts/install-dev.mjs +104 -0
- package/vendor/dsh-video-storyboard/src/flicker.js +104 -0
- package/vendor/dsh-video-storyboard/src/index.js +82 -0
- package/vendor/dsh-video-storyboard/src/ocr_bridge.py +103 -0
- package/vendor/dsh-video-storyboard/src/storyboard/asr-lifecycle.js +262 -0
- package/vendor/dsh-video-storyboard/src/storyboard/asr.js +488 -0
- package/vendor/dsh-video-storyboard/src/storyboard/audio.js +168 -0
- package/vendor/dsh-video-storyboard/src/storyboard/binaries.js +69 -0
- package/vendor/dsh-video-storyboard/src/storyboard/board.js +121 -0
- package/vendor/dsh-video-storyboard/src/storyboard/browser-time.js +504 -0
- package/vendor/dsh-video-storyboard/src/storyboard/cache.js +143 -0
- package/vendor/dsh-video-storyboard/src/storyboard/cells.js +70 -0
- package/vendor/dsh-video-storyboard/src/storyboard/density.js +545 -0
- package/vendor/dsh-video-storyboard/src/storyboard/direct-url.js +130 -0
- package/vendor/dsh-video-storyboard/src/storyboard/fetch.js +373 -0
- package/vendor/dsh-video-storyboard/src/storyboard/flash.js +180 -0
- package/vendor/dsh-video-storyboard/src/storyboard/format.js +573 -0
- package/vendor/dsh-video-storyboard/src/storyboard/frames.js +212 -0
- package/vendor/dsh-video-storyboard/src/storyboard/index.js +32 -0
- package/vendor/dsh-video-storyboard/src/storyboard/injection.js +76 -0
- package/vendor/dsh-video-storyboard/src/storyboard/layout-order.js +176 -0
- package/vendor/dsh-video-storyboard/src/storyboard/locate.js +113 -0
- package/vendor/dsh-video-storyboard/src/storyboard/media-store.js +106 -0
- package/vendor/dsh-video-storyboard/src/storyboard/memory.js +94 -0
- package/vendor/dsh-video-storyboard/src/storyboard/ocr-subs.js +107 -0
- package/vendor/dsh-video-storyboard/src/storyboard/ocr.js +167 -0
- package/vendor/dsh-video-storyboard/src/storyboard/pipeline.js +853 -0
- package/vendor/dsh-video-storyboard/src/storyboard/plan.js +400 -0
- package/vendor/dsh-video-storyboard/src/storyboard/probe.js +132 -0
- package/vendor/dsh-video-storyboard/src/storyboard/provenance.js +44 -0
- package/vendor/dsh-video-storyboard/src/storyboard/python.js +84 -0
- package/vendor/dsh-video-storyboard/src/storyboard/register.js +32 -0
- package/vendor/dsh-video-storyboard/src/storyboard/scan.js +486 -0
- package/vendor/dsh-video-storyboard/src/storyboard/segments.js +117 -0
- package/vendor/dsh-video-storyboard/src/storyboard/sheet.js +507 -0
- package/vendor/dsh-video-storyboard/src/storyboard/storage.js +93 -0
- package/vendor/dsh-video-storyboard/src/storyboard/subtitles.js +181 -0
- package/vendor/dsh-video-storyboard/src/storyboard/tool-spec.js +544 -0
- package/vendor/dsh-video-storyboard/src/storyboard/transcript-file.js +146 -0
- package/vendor/dsh-video-storyboard/src/storyboard/url.js +69 -0
- package/vendor/dsh-video-storyboard/src/storyboard/ytdlp.js +289 -0
- package/vendor/dsh-video-storyboard/src/tool-spec.js +17 -0
- package/vendor/dsh-video-storyboard/src/tools/locate.js +39 -0
- package/vendor/dsh-video-storyboard/src/tools/probe.js +23 -0
- package/vendor/dsh-video-storyboard/src/tools/shared.js +39 -0
- package/vendor/dsh-video-storyboard/src/tools/storyboard.js +20 -0
- package/vendor/dsh-video-storyboard/src/tools/zoom.js +56 -0
- package/vendor/dsh-world/LICENSE +21 -0
- package/vendor/dsh-world/assets/qq-card.png +0 -0
- package/vendor/dsh-world/cordis.patch.yml +6 -0
- package/vendor/dsh-world/lib/archive.d.ts +6 -0
- package/vendor/dsh-world/lib/archive.js +49 -0
- package/vendor/dsh-world/lib/archiveSelection.d.ts +8 -0
- package/vendor/dsh-world/lib/archiveSelection.js +20 -0
- package/vendor/dsh-world/lib/compaction.d.ts +124 -0
- package/vendor/dsh-world/lib/compaction.js +273 -0
- package/vendor/dsh-world/lib/compactionRegion.d.ts +42 -0
- package/vendor/dsh-world/lib/compactionRegion.js +210 -0
- package/vendor/dsh-world/lib/console/routes.d.ts +57 -0
- package/vendor/dsh-world/lib/console/routes.js +129 -0
- package/vendor/dsh-world/lib/console/snapshot.d.ts +39 -0
- package/vendor/dsh-world/lib/console/snapshot.js +51 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/bridge.d.ts +36 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/bridge.js +140 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/route.d.ts +9 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/route.js +46 -0
- package/vendor/dsh-world/lib/ecosystem/qq/bridge.d.ts +123 -0
- package/vendor/dsh-world/lib/ecosystem/qq/bridge.js +380 -0
- package/vendor/dsh-world/lib/ecosystem/qq/panel.d.ts +75 -0
- package/vendor/dsh-world/lib/ecosystem/qq/panel.js +187 -0
- package/vendor/dsh-world/lib/ecosystem/qq/route.d.ts +32 -0
- package/vendor/dsh-world/lib/ecosystem/qq/route.js +134 -0
- package/vendor/dsh-world/lib/ecosystem/qq/supervisor.d.ts +57 -0
- package/vendor/dsh-world/lib/ecosystem/qq/supervisor.js +188 -0
- package/vendor/dsh-world/lib/ecosystem/shared/context.d.ts +14 -0
- package/vendor/dsh-world/lib/ecosystem/shared/context.js +42 -0
- package/vendor/dsh-world/lib/ecosystem/shared/identity.d.ts +15 -0
- package/vendor/dsh-world/lib/ecosystem/shared/identity.js +36 -0
- package/vendor/dsh-world/lib/ecosystem/shared/outlets.d.ts +43 -0
- package/vendor/dsh-world/lib/ecosystem/shared/outlets.js +70 -0
- package/vendor/dsh-world/lib/ecosystem/shared/sessions.d.ts +16 -0
- package/vendor/dsh-world/lib/ecosystem/shared/sessions.js +52 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/archive.d.ts +24 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/archive.js +62 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/home.d.ts +21 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/home.js +111 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/images.d.ts +5 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/images.js +43 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/index.d.ts +41 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/index.js +166 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/messages.d.ts +24 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/messages.js +35 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/sending.d.ts +30 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/sending.js +216 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/supervisor.d.ts +39 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/supervisor.js +138 -0
- package/vendor/dsh-world/lib/faults.d.ts +10 -0
- package/vendor/dsh-world/lib/faults.js +13 -0
- package/vendor/dsh-world/lib/history.d.ts +16 -0
- package/vendor/dsh-world/lib/history.js +80 -0
- package/vendor/dsh-world/lib/hostContract.d.ts +19 -0
- package/vendor/dsh-world/lib/hostContract.js +1 -0
- package/vendor/dsh-world/lib/http.d.ts +18 -0
- package/vendor/dsh-world/lib/http.js +39 -0
- package/vendor/dsh-world/lib/index.d.ts +108 -0
- package/vendor/dsh-world/lib/index.js +356 -0
- package/vendor/dsh-world/lib/life/activity.d.ts +14 -0
- package/vendor/dsh-world/lib/life/activity.js +58 -0
- package/vendor/dsh-world/lib/life/alarm.d.ts +39 -0
- package/vendor/dsh-world/lib/life/alarm.js +132 -0
- package/vendor/dsh-world/lib/life/alarmTimer.d.ts +22 -0
- package/vendor/dsh-world/lib/life/alarmTimer.js +49 -0
- package/vendor/dsh-world/lib/life/diary.d.ts +4 -0
- package/vendor/dsh-world/lib/life/diary.js +9 -0
- package/vendor/dsh-world/lib/life/earlyStop.d.ts +19 -0
- package/vendor/dsh-world/lib/life/earlyStop.js +25 -0
- package/vendor/dsh-world/lib/life/home.d.ts +34 -0
- package/vendor/dsh-world/lib/life/home.js +91 -0
- package/vendor/dsh-world/lib/life/host.d.ts +22 -0
- package/vendor/dsh-world/lib/life/host.js +24 -0
- package/vendor/dsh-world/lib/life/journal.d.ts +20 -0
- package/vendor/dsh-world/lib/life/journal.js +59 -0
- package/vendor/dsh-world/lib/life/lifeStore.d.ts +16 -0
- package/vendor/dsh-world/lib/life/lifeStore.js +105 -0
- package/vendor/dsh-world/lib/life/messages.d.ts +17 -0
- package/vendor/dsh-world/lib/life/messages.js +53 -0
- package/vendor/dsh-world/lib/life/notify.d.ts +15 -0
- package/vendor/dsh-world/lib/life/notify.js +40 -0
- package/vendor/dsh-world/lib/life/pricing.d.ts +4 -0
- package/vendor/dsh-world/lib/life/pricing.js +30 -0
- package/vendor/dsh-world/lib/life/runtime.d.ts +52 -0
- package/vendor/dsh-world/lib/life/runtime.js +376 -0
- package/vendor/dsh-world/lib/life/toolRegistry.d.ts +22 -0
- package/vendor/dsh-world/lib/life/toolRegistry.js +64 -0
- package/vendor/dsh-world/lib/life/tools.d.ts +24 -0
- package/vendor/dsh-world/lib/life/tools.js +47 -0
- package/vendor/dsh-world/lib/life/types.d.ts +67 -0
- package/vendor/dsh-world/lib/life/types.js +1 -0
- package/vendor/dsh-world/lib/persona.d.ts +10 -0
- package/vendor/dsh-world/lib/persona.js +29 -0
- package/vendor/dsh-world/lib/promptSection.d.ts +30 -0
- package/vendor/dsh-world/lib/promptSection.js +81 -0
- package/vendor/dsh-world/lib/qqScope.d.ts +11 -0
- package/vendor/dsh-world/lib/qqScope.js +39 -0
- package/vendor/dsh-world/lib/runtime.d.ts +23 -0
- package/vendor/dsh-world/lib/runtime.js +206 -0
- package/vendor/dsh-world/lib/self.d.ts +10 -0
- package/vendor/dsh-world/lib/self.js +36 -0
- package/vendor/dsh-world/lib/sourceArchive.d.ts +28 -0
- package/vendor/dsh-world/lib/sourceArchive.js +156 -0
- package/vendor/dsh-world/lib/store.d.ts +30 -0
- package/vendor/dsh-world/lib/store.js +191 -0
- package/vendor/dsh-world/lib/timeContext.d.ts +3 -0
- package/vendor/dsh-world/lib/timeContext.js +13 -0
- package/vendor/dsh-world/lib/types.d.ts +118 -0
- package/vendor/dsh-world/lib/types.js +1 -0
- package/vendor/dsh-world/lib/worldPrompt.d.ts +47 -0
- package/vendor/dsh-world/lib/worldPrompt.js +49 -0
- package/vendor/dsh-world/lib/worldSwitch.d.ts +44 -0
- package/vendor/dsh-world/lib/worldSwitch.js +78 -0
- package/vendor/dsh-world/package-lock.json +1088 -0
- package/vendor/dsh-world/package.json +88 -0
- package/vendor/dsh-world/scripts/enable-tool-free-compaction.ps1 +33 -0
- package/vendor/dsh-world/src/archive.ts +45 -0
- package/vendor/dsh-world/src/archiveSelection.ts +27 -0
- package/vendor/dsh-world/src/compaction.ts +260 -0
- package/vendor/dsh-world/src/compactionRegion.ts +172 -0
- package/vendor/dsh-world/src/console/routes.ts +125 -0
- package/vendor/dsh-world/src/console/snapshot.ts +84 -0
- package/vendor/dsh-world/src/ecosystem/README.md +14 -0
- package/vendor/dsh-world/src/ecosystem/bridge/bridge.ts +121 -0
- package/vendor/dsh-world/src/ecosystem/bridge/route.ts +35 -0
- package/vendor/dsh-world/src/ecosystem/qq/bridge.ts +456 -0
- package/vendor/dsh-world/src/ecosystem/qq/panel.ts +178 -0
- package/vendor/dsh-world/src/ecosystem/qq/route.ts +130 -0
- package/vendor/dsh-world/src/ecosystem/qq/supervisor.ts +262 -0
- package/vendor/dsh-world/src/ecosystem/shared/context.ts +38 -0
- package/vendor/dsh-world/src/ecosystem/shared/identity.ts +42 -0
- package/vendor/dsh-world/src/ecosystem/shared/outlets.ts +75 -0
- package/vendor/dsh-world/src/ecosystem/shared/sessions.ts +47 -0
- package/vendor/dsh-world/src/ecosystem/wechat/archive.ts +66 -0
- package/vendor/dsh-world/src/ecosystem/wechat/home.ts +94 -0
- package/vendor/dsh-world/src/ecosystem/wechat/images.ts +38 -0
- package/vendor/dsh-world/src/ecosystem/wechat/index.ts +101 -0
- package/vendor/dsh-world/src/ecosystem/wechat/messages.ts +43 -0
- package/vendor/dsh-world/src/ecosystem/wechat/sending.ts +177 -0
- package/vendor/dsh-world/src/ecosystem/wechat/supervisor.ts +116 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/README.md +117 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/adapter.py +572 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/binding.py +52 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/LICENSE +43 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/NOTICE.md +10 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/bridge.cpp +229 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/build.ps1 +19 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/profile.json +28 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/groups.py +42 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/incoming.py +157 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/native.py +168 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/outgoing.py +95 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/requirements.txt +1 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/sender.py +157 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/snapshot.py +32 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/stickers.py +60 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/wechat.ps1 +75 -0
- package/vendor/dsh-world/src/faults.ts +12 -0
- package/vendor/dsh-world/src/history.ts +77 -0
- package/vendor/dsh-world/src/hostContract.ts +9 -0
- package/vendor/dsh-world/src/http.ts +34 -0
- package/vendor/dsh-world/src/index.ts +286 -0
- package/vendor/dsh-world/src/life/activity.ts +48 -0
- package/vendor/dsh-world/src/life/alarm.ts +119 -0
- package/vendor/dsh-world/src/life/alarmTimer.ts +45 -0
- package/vendor/dsh-world/src/life/diary.ts +10 -0
- package/vendor/dsh-world/src/life/earlyStop.ts +27 -0
- package/vendor/dsh-world/src/life/home.ts +85 -0
- package/vendor/dsh-world/src/life/host.ts +50 -0
- package/vendor/dsh-world/src/life/journal.ts +44 -0
- package/vendor/dsh-world/src/life/lifeStore.ts +70 -0
- package/vendor/dsh-world/src/life/messages.ts +44 -0
- package/vendor/dsh-world/src/life/notify.ts +47 -0
- package/vendor/dsh-world/src/life/pricing.ts +37 -0
- package/vendor/dsh-world/src/life/runtime.ts +318 -0
- package/vendor/dsh-world/src/life/toolRegistry.ts +48 -0
- package/vendor/dsh-world/src/life/tools.ts +61 -0
- package/vendor/dsh-world/src/life/types.ts +19 -0
- package/vendor/dsh-world/src/persona.ts +26 -0
- package/vendor/dsh-world/src/promptSection.ts +71 -0
- package/vendor/dsh-world/src/qqScope.ts +51 -0
- package/vendor/dsh-world/src/runtime.ts +172 -0
- package/vendor/dsh-world/src/self.ts +32 -0
- package/vendor/dsh-world/src/sourceArchive.ts +132 -0
- package/vendor/dsh-world/src/store.ts +170 -0
- package/vendor/dsh-world/src/timeContext.ts +13 -0
- package/vendor/dsh-world/src/types.ts +112 -0
- package/vendor/dsh-world/src/worldPrompt.ts +64 -0
- package/vendor/dsh-world/src/worldSwitch.ts +82 -0
- package/vendor/dsh-world/templates/alarm.md +49 -0
- package/vendor/dsh-world/templates/world-prompt.md +7 -0
- package/vendor/dsh-world/tests/archive.test.ts +57 -0
- package/vendor/dsh-world/tests/archiveScope.test.ts +86 -0
- package/vendor/dsh-world/tests/bridge.test.ts +211 -0
- package/vendor/dsh-world/tests/channelSessions.test.ts +79 -0
- package/vendor/dsh-world/tests/clientHooks.test.ts +103 -0
- package/vendor/dsh-world/tests/compaction.test.ts +141 -0
- package/vendor/dsh-world/tests/console.test.ts +202 -0
- package/vendor/dsh-world/tests/consoleClient.test.ts +101 -0
- package/vendor/dsh-world/tests/enableCompaction.test.ts +19 -0
- package/vendor/dsh-world/tests/fixtures.ts +6 -0
- package/vendor/dsh-world/tests/history.test.ts +100 -0
- package/vendor/dsh-world/tests/hostFixture.ts +46 -0
- package/vendor/dsh-world/tests/lifeActivity.test.ts +70 -0
- package/vendor/dsh-world/tests/lifeAlarm.test.ts +87 -0
- package/vendor/dsh-world/tests/lifeDiary.test.ts +33 -0
- package/vendor/dsh-world/tests/lifeMessages.test.ts +61 -0
- package/vendor/dsh-world/tests/lifeNotify.test.ts +46 -0
- package/vendor/dsh-world/tests/lifeParts.test.ts +45 -0
- package/vendor/dsh-world/tests/lifeRuntime.test.ts +660 -0
- package/vendor/dsh-world/tests/lifeStore.test.ts +90 -0
- package/vendor/dsh-world/tests/lifeTools.test.ts +53 -0
- package/vendor/dsh-world/tests/outlets.test.ts +85 -0
- package/vendor/dsh-world/tests/panel.test.ts +85 -0
- package/vendor/dsh-world/tests/plugin.test.ts +614 -0
- package/vendor/dsh-world/tests/pricing.test.ts +21 -0
- package/vendor/dsh-world/tests/qq.test.ts +121 -0
- package/vendor/dsh-world/tests/qqSessionMode.test.ts +97 -0
- package/vendor/dsh-world/tests/qqSupervisor.test.ts +149 -0
- package/vendor/dsh-world/tests/sourceArchive.test.ts +58 -0
- package/vendor/dsh-world/tests/store.test.ts +82 -0
- package/vendor/dsh-world/tests/storeWriter.ts +5 -0
- package/vendor/dsh-world/tests/timeContext.test.ts +15 -0
- package/vendor/dsh-world/tests/wechat.test.ts +254 -0
- package/vendor/dsh-world/tests/wechatImages.test.ts +130 -0
- package/vendor/dsh-world/tests/wechatSending.test.ts +142 -0
- package/vendor/dsh-world/tests/wechatSupervisor.test.ts +91 -0
- package/vendor/dsh-world/tests/worldPrompt.test.ts +201 -0
- package/vendor/dsh-world/tsconfig.build.json +5 -0
- package/vendor/dsh-world/tsconfig.json +8 -0
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* asr.js — 台词层。三级降级(学 dsh-video-lens 的"additive"原则):
|
|
3
|
+
*
|
|
4
|
+
* 1. 视频自带字幕轨 → 直接抽(零成本、最准)
|
|
5
|
+
* 2. 用户配置了 OpenAI 兼容的 /audio/transcriptions → 调它(默认 SenseVoiceSmall)
|
|
6
|
+
* 3. 都没有 → 返回 null,**绝不让整个分镜失败**
|
|
7
|
+
*
|
|
8
|
+
* 注意:ASR 只解释"人说了什么",对纯音乐无能为力,也可能对音乐段落产生幻觉歌词。
|
|
9
|
+
* 所以 transcribe 会跳过明显的非语音段(由静音检测给出)。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { execFile } from 'node:child_process';
|
|
13
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
14
|
+
import { homedir } from 'node:os';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
import { promisify } from 'node:util';
|
|
17
|
+
|
|
18
|
+
import { DEFAULT_FFMPEG } from './probe.js';
|
|
19
|
+
|
|
20
|
+
const run = promisify(execFile);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 桌面版 DSH 的进程 env 由启动器决定:用户 setx 之后宿主进程里仍然没有 DSH_ASR_KEY
|
|
24
|
+
* (实测 `ops_bash` 子进程继承了宿主的 DSH_* 变量,唯独没有这两个)。所以再给一条
|
|
25
|
+
* 不依赖 env 的路 —— 读 $DSH_HOME/asr.json:
|
|
26
|
+
*
|
|
27
|
+
* { "baseUrl": "http://127.0.0.1:8000/v1", "key": "local-key", "model": "...", "language": "zh" }
|
|
28
|
+
*
|
|
29
|
+
* 优先级:环境变量 > $DSH_HOME/asr.json > 内置默认(SiliconFlow)。
|
|
30
|
+
*/
|
|
31
|
+
function readConfigFile(env) {
|
|
32
|
+
// DSH_HOME 一旦显式给了,就**只认它**:否则"指到一个空目录"会和"没指"完全等价,
|
|
33
|
+
// 测试里想隔离本机配置根本做不到(实测:设了空 DSH_HOME 仍然读到了 ~/.dsh/asr.json)。
|
|
34
|
+
const candidates = env.DSH_HOME
|
|
35
|
+
? [join(env.DSH_HOME, 'asr.json')]
|
|
36
|
+
: [join(homedir(), '.dsh', 'asr.json')];
|
|
37
|
+
for (const path of candidates) {
|
|
38
|
+
if (!existsSync(path)) continue;
|
|
39
|
+
// 文件存在但坏了:直接当成"没有配置",不要再穿透到下一个候选,
|
|
40
|
+
// 否则 $DSH_HOME 里的坏配置会被 ~/.dsh 的那份悄悄顶替掉,排查时看不出问题。
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(readFileSync(path, 'utf8'));
|
|
43
|
+
if (parsed && typeof parsed === 'object') return { ...parsed, path };
|
|
44
|
+
} catch {
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 解析 ASR 配置。优先级:**环境变量 > $DSH_HOME/asr.json > 内置默认**。
|
|
54
|
+
*
|
|
55
|
+
* 为什么要读文件:桌面版 DSH 的进程 env 由启动器决定,用户 setx 之后宿主进程里
|
|
56
|
+
* 仍然读不到 `DSH_ASR_KEY`(实测 `ops_bash` 子进程继承了 DSH_* 变量,唯独没有这两个)。
|
|
57
|
+
* 文件路径不依赖 env 传播,是更可靠的一层。
|
|
58
|
+
*
|
|
59
|
+
* @returns {{baseUrl:string, model:string, keyEnv:string, language:string, fileKey?:string, source:'env'|'file'|'default', configPath?:string}}
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* env 里的值可能带着引号。真实事故:Windows 上 `setx DSH_ASR_BASE_URL "http://127.0.0.1:8000/v1"`
|
|
63
|
+
* 经过某些 shell 转发后,注册表里存的是 `"http://127.0.0.1:8000/v1"`(**引号是值的一部分**),
|
|
64
|
+
* 于是 `fetch('"http://..."' + '/audio/transcriptions')` 直接
|
|
65
|
+
* `ERR_INVALID_URL: Invalid URL`。这种错误看起来像"配置没生效",其实是配置生效了但值坏了一点点。
|
|
66
|
+
* 所以读 env 时统一剥掉首尾成对的引号与空白。
|
|
67
|
+
*/
|
|
68
|
+
/** baseUrl 指向本机时,ASR 不需要 key */
|
|
69
|
+
export function isLoopback(baseUrl) {
|
|
70
|
+
try {
|
|
71
|
+
const h = new URL(String(baseUrl)).hostname.toLowerCase().replace(/^\[|\]$/g, '');
|
|
72
|
+
return h === '127.0.0.1' || h === 'localhost' || h === '::1' || h === '0.0.0.0';
|
|
73
|
+
} catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function cleanEnvValue(v) {
|
|
79
|
+
if (typeof v !== 'string') return v;
|
|
80
|
+
const t = v.trim();
|
|
81
|
+
if (t.length >= 2 && /^(["']).*\1$/.test(t)) return t.slice(1, -1).trim();
|
|
82
|
+
return t;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** 云端(非本机)且没给 key —— 这一种情况才必然跳过。`transcribe()` 的门就是这一句。 */
|
|
86
|
+
export function needsCloudKey(baseUrl, key) {
|
|
87
|
+
return !key && !isLoopback(baseUrl);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** 这次调用实际会用的 key:undefined = 走 env / asr.json;显式值(含 null / '')= 调用方说了算。 */
|
|
91
|
+
export function effectiveAsrKey(cfg = ASR_DEFAULTS, apiKey) {
|
|
92
|
+
return apiKey === undefined
|
|
93
|
+
? cleanEnvValue(process.env[cfg.keyEnv]) || cfg.fileKey
|
|
94
|
+
: apiKey;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 这次调用会不会真的转写。
|
|
99
|
+
*
|
|
100
|
+
* 判据不能只看"有没有 key":0.4.1 起本机服务(127.0.0.1 / localhost / [::1] / 0.0.0.0)按设计
|
|
101
|
+
* **不需要 key**,只看 key 就会把"本机 ASR 正在跑"误判成"没配 → 不会转写"。所以必须和
|
|
102
|
+
* `transcribe()` 的门用同一句话,否则清单与实际行为会朝反方向偏差。
|
|
103
|
+
*/
|
|
104
|
+
export function canTranscribe(cfg = ASR_DEFAULTS, apiKey) {
|
|
105
|
+
return !needsCloudKey(cfg.baseUrl, effectiveAsrKey(cfg, apiKey));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function resolveAsrConfig(env = process.env) {
|
|
109
|
+
const file = readConfigFile(env);
|
|
110
|
+
const envBaseUrl = cleanEnvValue(env.DSH_ASR_BASE_URL);
|
|
111
|
+
const envModel = cleanEnvValue(env.DSH_ASR_MODEL);
|
|
112
|
+
const envLanguage = cleanEnvValue(env.DSH_ASR_LANG);
|
|
113
|
+
const keyEnv = cleanEnvValue(env.DSH_ASR_KEY_ENV) || 'DSH_ASR_KEY';
|
|
114
|
+
const fromEnv = Boolean(envBaseUrl || env[keyEnv]);
|
|
115
|
+
return {
|
|
116
|
+
baseUrl: envBaseUrl || file.baseUrl || 'https://api.siliconflow.cn/v1',
|
|
117
|
+
model: envModel || file.model || 'FunAudioLLM/SenseVoiceSmall',
|
|
118
|
+
keyEnv,
|
|
119
|
+
language: envLanguage || file.language || 'zh',
|
|
120
|
+
fileKey: typeof file.key === 'string' && file.key ? file.key : undefined,
|
|
121
|
+
source: fromEnv ? 'env' : (file.baseUrl || file.key ? 'file' : 'default'),
|
|
122
|
+
// 术语校正表:错误写法 → 正确写法
|
|
123
|
+
terms: file.terms && typeof file.terms === 'object' ? file.terms : undefined,
|
|
124
|
+
// 热词:空格分隔的一串词,交给 seaco_paraformer 解码时偏置
|
|
125
|
+
hotwords: typeof file.hotwords === 'string' && file.hotwords.trim() ? file.hotwords.trim() : '',
|
|
126
|
+
terms: file.terms && typeof file.terms === 'object' ? file.terms : undefined,
|
|
127
|
+
// 生命周期托管:{ start, stop?, idleMs?, waitMs? } —— 见 asr-lifecycle.js
|
|
128
|
+
manage: file.manage && typeof file.manage === 'object' ? file.manage : undefined,
|
|
129
|
+
...(file.path ? { configPath: file.path } : {}),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const ASR_DEFAULTS = resolveAsrConfig();
|
|
134
|
+
|
|
135
|
+
/** 一句话说明"我们在往哪儿发请求",用于把错误信息变得可定位(永远不含 key) */
|
|
136
|
+
export function describeAsrTarget(cfg = ASR_DEFAULTS) {
|
|
137
|
+
const where = cfg.source === 'file' && cfg.configPath ? `${cfg.source} (${cfg.configPath})` : cfg.source;
|
|
138
|
+
return `${cfg.baseUrl} · model ${cfg.model} · config ${where}`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** 把 Node 的 fetch 错误展开成可读原因(fetch failed 本身什么都不说) */
|
|
142
|
+
export function explainFetchError(error) {
|
|
143
|
+
const parts = [String(error?.message ?? error)];
|
|
144
|
+
const cause = error?.cause;
|
|
145
|
+
if (cause) {
|
|
146
|
+
const code = cause.code || cause.errno || '';
|
|
147
|
+
const msg = cause.message || String(cause);
|
|
148
|
+
if (msg && msg !== parts[0]) parts.push(`${code ? `${code}: ` : ''}${msg}`.trim());
|
|
149
|
+
}
|
|
150
|
+
return parts.join(' — ');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const SRT_RE = /(\d+)\s*\n(\d{2}):(\d{2}):(\d{2})[,.](\d{3})\s*-->\s*(\d{2}):(\d{2}):(\d{2})[,.](\d{3})\s*\n([\s\S]*?)(?=\n\s*\n|\s*$)/g;
|
|
154
|
+
|
|
155
|
+
/** 解析 SRT 文本 → [{from,to,text}] */
|
|
156
|
+
export function parseSrt(text) {
|
|
157
|
+
const out = [];
|
|
158
|
+
const src = String(text).replace(/\r\n/g, '\n').trim();
|
|
159
|
+
for (const m of src.matchAll(SRT_RE)) {
|
|
160
|
+
const toSec = (h, mi, s, ms) => (+h) * 3600 + (+mi) * 60 + (+s) + (+ms) / 1000;
|
|
161
|
+
const from = toSec(m[2], m[3], m[4], m[5]);
|
|
162
|
+
const to = toSec(m[6], m[7], m[8], m[9]);
|
|
163
|
+
const body = m[10].split('\n').map((l) => l.trim()).filter(Boolean).join(' ');
|
|
164
|
+
if (body) out.push({ from, to, text: body });
|
|
165
|
+
}
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** 从容器里抽字幕轨(有就直接用,比 ASR 准且免费) */
|
|
170
|
+
export async function extractSubtitleTrack({ input, ffmpegPath = DEFAULT_FFMPEG, timeoutMs = 60_000 } = {}) {
|
|
171
|
+
try {
|
|
172
|
+
const { stdout } = await run(ffmpegPath, [
|
|
173
|
+
'-hide_banner', '-v', 'error', '-nostdin', '-i', input,
|
|
174
|
+
'-map', '0:s:0', '-f', 'srt', '-',
|
|
175
|
+
], { encoding: 'utf8', maxBuffer: 32 * 1024 * 1024, timeout: timeoutMs });
|
|
176
|
+
const segments = parseSrt(stdout);
|
|
177
|
+
return segments.length > 0 ? segments : null;
|
|
178
|
+
} catch {
|
|
179
|
+
return null; // 没有字幕轨就是常态,不算错误
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* 调 OpenAI 兼容的转写接口。
|
|
185
|
+
* @returns {Promise<{segments:Array<{from:number,to:number,text:string}>, model:string, language?:string}|null>}
|
|
186
|
+
*/
|
|
187
|
+
export async function transcribe({
|
|
188
|
+
input, ffmpegPath = DEFAULT_FFMPEG, start = 0, end,
|
|
189
|
+
baseUrl = ASR_DEFAULTS.baseUrl, model = ASR_DEFAULTS.model,
|
|
190
|
+
hotwords = resolveAsrConfig().hotwords,
|
|
191
|
+
apiKey,
|
|
192
|
+
language = ASR_DEFAULTS.language,
|
|
193
|
+
timeoutMs = 180_000,
|
|
194
|
+
} = {}) {
|
|
195
|
+
// undefined = 走 env/文件;显式传 null 或 '' = 明确不要 key(测试与"关掉 ASR"都用这个)
|
|
196
|
+
const key = effectiveAsrKey(ASR_DEFAULTS, apiKey);
|
|
197
|
+
// **本机服务不该强制要 key**:自己跑的 FunASR / whisper.cpp / faster-whisper 服务
|
|
198
|
+
// 通常不校验 Authorization,逼用户填一个假 key 只会让"能不能用"取决于文档写没写清。
|
|
199
|
+
// 云端才必须 key(没有它必然 401)。
|
|
200
|
+
if (needsCloudKey(baseUrl, key)) return null; // 云端没配 key:跳过,不报错
|
|
201
|
+
|
|
202
|
+
// 抽成 16k 单声道 wav(16k 是 ASR 的通用采样率,体积也可控)
|
|
203
|
+
const args = [ffmpegPath, '-hide_banner', '-v', 'error', '-nostdin'];
|
|
204
|
+
if (start > 0) args.push('-ss', String(start));
|
|
205
|
+
if (end !== undefined) args.push('-t', String(Math.max(0.1, end - start)));
|
|
206
|
+
args.push('-i', input, '-vn', '-ac', '1', '-ar', '16000', '-f', 'wav', '-');
|
|
207
|
+
const { stdout } = await run(args[0], args.slice(1), {
|
|
208
|
+
encoding: 'buffer', maxBuffer: 256 * 1024 * 1024, timeout: timeoutMs,
|
|
209
|
+
});
|
|
210
|
+
if (stdout.length < 1024) return null;
|
|
211
|
+
|
|
212
|
+
const form = new FormData();
|
|
213
|
+
form.append('file', new Blob([stdout], { type: 'audio/wav' }), 'audio.wav');
|
|
214
|
+
form.append('model', model);
|
|
215
|
+
form.append('response_format', 'verbose_json');
|
|
216
|
+
// 热词:专治同音字(实测"像差"会被识别成"相差")。服务端不认识这个字段时会忽略,不会报错。
|
|
217
|
+
if (hotwords) form.append('hotword', hotwords);
|
|
218
|
+
if (language) form.append('language', language);
|
|
219
|
+
|
|
220
|
+
const res = await fetch(`${baseUrl.replace(/\/$/, '')}/audio/transcriptions`, {
|
|
221
|
+
method: 'POST',
|
|
222
|
+
headers: key ? { Authorization: `Bearer ${key}` } : {},
|
|
223
|
+
body: form,
|
|
224
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
225
|
+
});
|
|
226
|
+
if (!res.ok) {
|
|
227
|
+
const body = await res.text().catch(() => '');
|
|
228
|
+
throw new Error(`ASR ${res.status}: ${body.slice(0, 200)}`);
|
|
229
|
+
}
|
|
230
|
+
const json = await res.json();
|
|
231
|
+
const actualModel = typeof json.model === 'string' && json.model ? json.model : model;
|
|
232
|
+
const raw = Array.isArray(json.segments) ? json.segments : [];
|
|
233
|
+
const segments = raw.map((s) => ({
|
|
234
|
+
from: +(Number(s.start) + start).toFixed(3),
|
|
235
|
+
to: +(Number(s.end) + start).toFixed(3),
|
|
236
|
+
text: String(s.text ?? '').trim(),
|
|
237
|
+
})).filter((s) => s.text);
|
|
238
|
+
|
|
239
|
+
if (segments.length === 0 && json.text) {
|
|
240
|
+
// 没有分段信息:退化成"整段一句",至少能放在对应的格子里
|
|
241
|
+
return {
|
|
242
|
+
segments: [{ from: start, to: end ?? start + 1, text: String(json.text).trim() }],
|
|
243
|
+
model: actualModel, language: json.language ?? language,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
return { segments, model: actualModel, language: json.language ?? language };
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* 把台词按时间重叠贴到每一格上。
|
|
251
|
+
* 一句跨两格时两边都保留(宁可重复,也别让某一格"没话说")。
|
|
252
|
+
*/
|
|
253
|
+
/** `10:09.4` —— 内联时间戳用,比 `00:10:09.40` 省一半字符 */
|
|
254
|
+
export function shortStamp(seconds) {
|
|
255
|
+
const t = Math.max(0, Number(seconds) || 0);
|
|
256
|
+
const m = Math.floor(t / 60);
|
|
257
|
+
const s = t - m * 60;
|
|
258
|
+
return `${m}:${s.toFixed(1).padStart(4, '0')}`;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** 相邻两句之间出现这么长的静默,就认为格内存在一个"断点",值得标出来 */
|
|
262
|
+
export const CELL_BREAK_GAP = 1.0;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* 把台词贴到格子上。
|
|
266
|
+
*
|
|
267
|
+
* **不再是简单 join。** 一格常常跨两三句,而 `join(' ')` 抹掉了每句自己的起点 ——
|
|
268
|
+
* 模型只能拿 `cell.from` 当整段的锚点,结果整段被提前几十秒(实测被错位 30s)。
|
|
269
|
+
*
|
|
270
|
+
* 折中做法:只在**真有断点**的地方插内联时间戳(相邻句间隔 ≥ CELL_BREAK_GAP),
|
|
271
|
+
* 而不是每句都插 —— 每句都插会让 120 字的台词预算被 `[10:09.4]` 吃掉四分之一。
|
|
272
|
+
* 同时把 `lines`(每条带自己的 from/to)留给渲染层,将来要"一格多行"不必再改这里。
|
|
273
|
+
*/
|
|
274
|
+
export function alignCells(cells, segments) {
|
|
275
|
+
return cells.map((cell) => {
|
|
276
|
+
const hits = segments.filter((s) => s.to > cell.from && s.from < cell.to);
|
|
277
|
+
const parts = [];
|
|
278
|
+
for (let i = 0; i < hits.length; i++) {
|
|
279
|
+
if (i > 0 && hits[i].from - hits[i - 1].to >= CELL_BREAK_GAP) {
|
|
280
|
+
parts.push(`[${shortStamp(hits[i].from)}]`);
|
|
281
|
+
}
|
|
282
|
+
parts.push(hits[i].text);
|
|
283
|
+
}
|
|
284
|
+
const text = parts.join(' ').trim();
|
|
285
|
+
const dur = Math.max(0.1, cell.to - cell.from);
|
|
286
|
+
return {
|
|
287
|
+
text,
|
|
288
|
+
chars: text.length,
|
|
289
|
+
charsPerSec: +(text.length / dur).toFixed(2),
|
|
290
|
+
segments: hits.length,
|
|
291
|
+
// 每句自己的时间轴:信息本来就有,之前被 join 丢掉了
|
|
292
|
+
lines: hits.map((s) => ({
|
|
293
|
+
from: +Number(s.from).toFixed(2),
|
|
294
|
+
to: +Number(s.to).toFixed(2),
|
|
295
|
+
text: s.text,
|
|
296
|
+
})),
|
|
297
|
+
// 格内存在断点时为 true —— 渲染层可以据此提示"这一格跨了两件事"
|
|
298
|
+
broken: hits.length > 1 && hits.some((s, i) => i > 0 && s.from - hits[i - 1].to >= CELL_BREAK_GAP),
|
|
299
|
+
};
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* 把 [start, end] 切成若干不超过 maxChunk 秒的请求窗口,**切点优先落在静音中间**。
|
|
305
|
+
*
|
|
306
|
+
* 为什么客户端也要切:实测 SEACO-Paraformer 单次请求 299s 会把时间码压早 13s
|
|
307
|
+
* (约 4.5% 压缩,像是把停顿吃掉了)。这个行为和"服务端实现"无关,任何不认识的后端
|
|
308
|
+
* 都可能这样,所以必须在**调用侧**给上限。
|
|
309
|
+
*
|
|
310
|
+
* 为什么切在静音而不是固定 45s:固定切会把词劈成两半(实测多出 2 个碎段),
|
|
311
|
+
* 而静音处切开既不掉字,也不会让一句话跨请求。
|
|
312
|
+
*/
|
|
313
|
+
export function chunkWindows({ start, end, silences = [], maxChunk = 45, minChunk = 8 }) {
|
|
314
|
+
const from0 = Number(start) || 0;
|
|
315
|
+
const to0 = Number(end);
|
|
316
|
+
if (!(to0 > from0)) throw new RangeError('end must be greater than start');
|
|
317
|
+
const total = to0 - from0;
|
|
318
|
+
if (total <= maxChunk) return [{ from: from0, to: to0 }];
|
|
319
|
+
|
|
320
|
+
// 候选切点:静音中点;没有静音就用固定步长
|
|
321
|
+
const mids = silences
|
|
322
|
+
.map((s) => (Math.max(from0, s.from) + Math.min(to0, s.to)) / 2)
|
|
323
|
+
.filter((m) => m > from0 && m < to0)
|
|
324
|
+
.sort((a, b) => a - b);
|
|
325
|
+
|
|
326
|
+
const windows = [];
|
|
327
|
+
let cursor = from0;
|
|
328
|
+
while (to0 - cursor > maxChunk) {
|
|
329
|
+
const ideal = cursor + maxChunk;
|
|
330
|
+
const lower = cursor + Math.max(minChunk, maxChunk * 0.5);
|
|
331
|
+
const candidate = mids
|
|
332
|
+
.filter((m) => m > lower && m <= ideal)
|
|
333
|
+
.at(-1);
|
|
334
|
+
const cut = candidate ?? ideal;
|
|
335
|
+
windows.push({ from: cursor, to: cut });
|
|
336
|
+
cursor = cut;
|
|
337
|
+
}
|
|
338
|
+
windows.push({ from: cursor, to: to0 });
|
|
339
|
+
return windows;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** 合并相邻段:同一个词被两次请求各识别一次时只留一个 */
|
|
343
|
+
export function mergeSegments(segments, { gap = 0.5 } = {}) {
|
|
344
|
+
const sorted = [...segments].sort((a, b) => a.from - b.from || a.to - b.to);
|
|
345
|
+
const out = [];
|
|
346
|
+
for (const seg of sorted) {
|
|
347
|
+
const last = out.at(-1);
|
|
348
|
+
// 跨片重复:同一句在上一片的尾巴和这一片的开头各出现一次 → 合并成一条
|
|
349
|
+
if (last && last.text === seg.text && seg.from <= last.to + gap) {
|
|
350
|
+
last.to = Math.max(last.to, seg.to);
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
out.push({ ...seg });
|
|
354
|
+
}
|
|
355
|
+
return out;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* 长音频转写:按 ≤maxChunk 秒切片、逐片调用、把片偏移加回去。
|
|
360
|
+
* 片与片之间用静音对齐,所以不需要重叠(重叠还得去重,反而更容易出错)。
|
|
361
|
+
*/
|
|
362
|
+
export async function transcribeLong(options = {}) {
|
|
363
|
+
const { start = 0, end, silences = [], maxChunk = 45, ...rest } = options;
|
|
364
|
+
if (!(end > start)) throw new RangeError('end must be greater than start');
|
|
365
|
+
const windows = chunkWindows({ start, end, silences, maxChunk });
|
|
366
|
+
// 单窗口:transcribe 自己是 null 就 null,是空段就空段 —— 下面统一补 `empty` 标记
|
|
367
|
+
if (windows.length === 1) {
|
|
368
|
+
const only = await transcribe({ ...rest, start, end });
|
|
369
|
+
return only ? { ...only, empty: only.segments.length === 0 } : null;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const all = [];
|
|
373
|
+
let model = null;
|
|
374
|
+
let language = null;
|
|
375
|
+
let ran = 0; // 真正跑起来的片数(云端没配 key 时会是 0)
|
|
376
|
+
for (const win of windows) {
|
|
377
|
+
const part = await transcribe({ ...rest, start: win.from, end: win.to });
|
|
378
|
+
if (!part) continue;
|
|
379
|
+
ran += 1;
|
|
380
|
+
model = part.model ?? model;
|
|
381
|
+
language = part.language ?? language;
|
|
382
|
+
all.push(...part.segments);
|
|
383
|
+
}
|
|
384
|
+
// 一片都没跑起来 → 分两种,不能混为一谈:
|
|
385
|
+
// - 云端没配 key:ASR 根本没发生过 → null,上层走"没跑"分支;
|
|
386
|
+
// - 配了 key(或本机服务)却没听到任何字:那是**真的**"跑了但没结果" → 交给 `empty`,
|
|
387
|
+
// 上层会写 asr-empty。绝不能反过来把"没跑"写成"跑了没听到话"(0.4.2 之前就是这么写的)。
|
|
388
|
+
// 判据用**这次实际要发的地址**:调用方可以显式给 baseUrl(本机服务走这条路)。
|
|
389
|
+
const target = { ...ASR_DEFAULTS, baseUrl: rest.baseUrl ?? ASR_DEFAULTS.baseUrl };
|
|
390
|
+
if (ran === 0 && !canTranscribe(target, rest.apiKey)) return null;
|
|
391
|
+
const merged = mergeSegments(all);
|
|
392
|
+
return { segments: merged, model, language, chunks: windows.length, empty: merged.length === 0 };
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* 过滤"疑似音乐段幻觉"。
|
|
397
|
+
*
|
|
398
|
+
* 背景(实测):概念 PV 只有一句真台词,但 ASR 在纯音乐段吐出一条
|
|
399
|
+
* `45.35–74.33`(29 秒、9 个字)的假句子。`alignCells` 按时间重叠贴,
|
|
400
|
+
* 这一条会命中 5 个格子,把同一句垃圾复制五遍——比直接丢掉更糟。
|
|
401
|
+
*
|
|
402
|
+
* 两条判据:
|
|
403
|
+
* - **长时段 + 极低字/秒**:正常口播 2–6 字/秒(实测三条素材:5.60 / 2.07 / 0.32),
|
|
404
|
+
* 超过 8 秒却不到 0.8 字/秒,几乎必然是音乐/噪声被"翻译"成了字;
|
|
405
|
+
* - **没有实义字符**:只剩标点或空白的段直接丢。
|
|
406
|
+
*
|
|
407
|
+
* 丢掉的段不贴到格子,但会在清单里报出来——过滤不能变成静默丢数据。
|
|
408
|
+
*/
|
|
409
|
+
export function filterSuspectSegments(segments, { minDur = 8, minCharsPerSec = 0.8 } = {}) {
|
|
410
|
+
const kept = [];
|
|
411
|
+
const dropped = [];
|
|
412
|
+
for (const seg of segments ?? []) {
|
|
413
|
+
const dur = Math.max(0.1, seg.to - seg.from);
|
|
414
|
+
const text = String(seg.text ?? '').trim();
|
|
415
|
+
const meaningful = text.replace(/[\s\p{P}\p{S}]/gu, '').length;
|
|
416
|
+
if (meaningful === 0) {
|
|
417
|
+
dropped.push({ ...seg, reason: 'punctuation-only', charsPerSec: 0 });
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
const cps = meaningful / dur;
|
|
421
|
+
if (dur > minDur && cps < minCharsPerSec) {
|
|
422
|
+
dropped.push({ ...seg, reason: 'music-like', charsPerSec: +cps.toFixed(2) });
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
kept.push(seg);
|
|
426
|
+
}
|
|
427
|
+
return { kept, dropped };
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* 术语校正表。
|
|
432
|
+
*
|
|
433
|
+
* 实测 ASR 对专业名词必错(`彗差→绘插`、`八羽怪→巴与怪`、`沧野→苍野`、`收光圈→烧光圈`)。
|
|
434
|
+
* 与其让模型自己猜,不如给一份用户词典做**确定性替换**,并把替换次数报出来(不静默改写原文)。
|
|
435
|
+
*
|
|
436
|
+
* 长词优先匹配,避免 `像散` 被 `像` 抢先替换掉。
|
|
437
|
+
*
|
|
438
|
+
* @param {Array<{text:string}>} segments
|
|
439
|
+
* @param {Record<string,string>} terms 错误写法 → 正确写法
|
|
440
|
+
* @returns {{segments:Array, replaced:number, touched:number}}
|
|
441
|
+
*/
|
|
442
|
+
export function applyTermMap(segments, terms) {
|
|
443
|
+
const entries = Object.entries(terms ?? {})
|
|
444
|
+
.filter(([from, to]) => typeof from === 'string' && from && typeof to === 'string');
|
|
445
|
+
if (entries.length === 0) return { segments: segments ?? [], replaced: 0, touched: 0 };
|
|
446
|
+
|
|
447
|
+
// 一次扫描、单遍替换:用"长词优先"的交替式正则,避免替换出来的新文本被后面的短词二次命中
|
|
448
|
+
// (踩过:像散→像散(AST) 之后,"像"又把新文本里的"像"替换掉)
|
|
449
|
+
const map = new Map(entries);
|
|
450
|
+
const pattern = entries
|
|
451
|
+
.map(([from]) => from)
|
|
452
|
+
.sort((a, b) => b.length - a.length)
|
|
453
|
+
.map((k) => k.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
|
|
454
|
+
.join('|');
|
|
455
|
+
const re = new RegExp(pattern, 'g');
|
|
456
|
+
|
|
457
|
+
let replaced = 0;
|
|
458
|
+
let touched = 0;
|
|
459
|
+
const out = (segments ?? []).map((seg) => {
|
|
460
|
+
const text = String(seg.text ?? '');
|
|
461
|
+
let hit = false;
|
|
462
|
+
const next = text.replace(re, (m) => {
|
|
463
|
+
replaced += 1;
|
|
464
|
+
hit = true;
|
|
465
|
+
return map.get(m) ?? m;
|
|
466
|
+
});
|
|
467
|
+
if (!hit) return seg;
|
|
468
|
+
touched += 1;
|
|
469
|
+
return { ...seg, text: next };
|
|
470
|
+
});
|
|
471
|
+
return { segments: out, replaced, touched };
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/** 语音密度曲线:每秒字数,按 bin 采样(供 planCellRanges 当第三条密度信号) */
|
|
475
|
+
export function speechCurve(segments, { duration, bin = 0.1 }) {
|
|
476
|
+
const bins = Math.max(1, Math.ceil(duration / bin));
|
|
477
|
+
const out = new Float64Array(bins);
|
|
478
|
+
if (!segments?.length) return { bins, curve: out, mean: 0 };
|
|
479
|
+
for (const s of segments) {
|
|
480
|
+
const a = Math.max(0, Math.floor(s.from / bin));
|
|
481
|
+
const b = Math.min(bins, Math.ceil(s.to / bin));
|
|
482
|
+
const len = Math.max(1, b - a);
|
|
483
|
+
const per = s.text.length / len;
|
|
484
|
+
for (let i = a; i < b; i++) out[i] += per;
|
|
485
|
+
}
|
|
486
|
+
const mean = out.reduce((x, y) => x + y, 0) / bins;
|
|
487
|
+
return { bins, curve: out, mean };
|
|
488
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* audio.js — 音频侧的"测量层"。零模型:只用 ffmpeg 的 ebur128 与 silencedetect。
|
|
3
|
+
*
|
|
4
|
+
* 目的是给画面配一条**同时间轴的**参考线:哪里响、哪里静。它回答"哪里在响",
|
|
5
|
+
* 不回答"为什么响"——后者是音乐理解,得靠模型(见设计方案 §12)。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { spawn } from 'node:child_process';
|
|
9
|
+
|
|
10
|
+
import { DEFAULT_FFMPEG } from './probe.js';
|
|
11
|
+
|
|
12
|
+
export const LUFS_FLOOR = -70; // 低于这个值当静音(ebur128 静音输出 -120 左右)
|
|
13
|
+
export const SILENCE_DB = -40;
|
|
14
|
+
export const SILENCE_MIN = 0.6;
|
|
15
|
+
|
|
16
|
+
/** 跑一次 ffmpeg,收集 stderr(ebur128 / silencedetect 都往 stderr 打) */
|
|
17
|
+
function runAudioFilter({ input, ffmpegPath, filter, start, end, timeoutMs = 180_000 }) {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const args = [ffmpegPath, '-hide_banner', '-nostdin', '-v', 'info'];
|
|
20
|
+
if (start > 0) args.push('-ss', String(start));
|
|
21
|
+
if (end !== undefined) args.push('-t', String(Math.max(0.1, end - start)));
|
|
22
|
+
args.push('-i', input, '-vn', '-sn', '-dn', '-af', filter, '-f', 'null', '-');
|
|
23
|
+
const child = spawn(args[0], args.slice(1), { stdio: ['ignore', 'ignore', 'pipe'] });
|
|
24
|
+
let err = '';
|
|
25
|
+
const timer = setTimeout(() => child.kill('SIGKILL'), timeoutMs);
|
|
26
|
+
child.stderr.on('data', (d) => { err += d.toString(); });
|
|
27
|
+
child.on('error', (e) => { clearTimeout(timer); reject(e); });
|
|
28
|
+
child.on('close', (code) => {
|
|
29
|
+
clearTimeout(timer);
|
|
30
|
+
if (code === 0) return resolve(err);
|
|
31
|
+
const tail = err.trim().split('\n').slice(-2).join(' | ');
|
|
32
|
+
reject(new Error(`ffmpeg audio filter exited ${code}${tail ? `: ${tail}` : ''}`));
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const M_RE = /lavfi\.r128\.M=(-?[0-9.]+)/g;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 瞬时响度曲线(EBU R128 momentary,约每 100ms 一个点)。
|
|
41
|
+
* @returns {Promise<{series:number[], step:number, mean:number, peak:number, dynamic:number, samples:number}>}
|
|
42
|
+
*/
|
|
43
|
+
export async function measureLoudness({ input, ffmpegPath = DEFAULT_FFMPEG, start = 0, end } = {}) {
|
|
44
|
+
const stderr = await runAudioFilter({
|
|
45
|
+
input, ffmpegPath, start, end,
|
|
46
|
+
filter: 'ebur128=metadata=1,ametadata=mode=print:key=lavfi.r128.M',
|
|
47
|
+
});
|
|
48
|
+
const series = [];
|
|
49
|
+
for (const m of stderr.matchAll(M_RE)) {
|
|
50
|
+
const v = Number(m[1]);
|
|
51
|
+
if (Number.isFinite(v)) series.push(v);
|
|
52
|
+
}
|
|
53
|
+
const audible = series.filter((v) => v > LUFS_FLOOR);
|
|
54
|
+
const mean = audible.length ? audible.reduce((s, v) => s + v, 0) / audible.length : LUFS_FLOOR;
|
|
55
|
+
const peak = audible.length ? Math.max(...audible) : LUFS_FLOOR;
|
|
56
|
+
return {
|
|
57
|
+
series,
|
|
58
|
+
step: 0.1,
|
|
59
|
+
mean: +mean.toFixed(1),
|
|
60
|
+
peak: +peak.toFixed(1),
|
|
61
|
+
dynamic: +(peak - (audible.length ? Math.min(...audible) : LUFS_FLOOR)).toFixed(1),
|
|
62
|
+
samples: series.length,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const SS_RE = /silence_start: (-?[0-9.]+)/g;
|
|
67
|
+
const SE_RE = /silence_end: (-?[0-9.]+)/g;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 静音段(默认 -40dB 持续 0.6s 以上)。人声停顿与 BGM 间隙都在这里。
|
|
71
|
+
* @returns {Promise<Array<{from:number,to:number}>>}
|
|
72
|
+
*/
|
|
73
|
+
export async function detectSilence({
|
|
74
|
+
input, ffmpegPath = DEFAULT_FFMPEG, start = 0, end,
|
|
75
|
+
noise = SILENCE_DB, minDur = SILENCE_MIN,
|
|
76
|
+
} = {}) {
|
|
77
|
+
const stderr = await runAudioFilter({
|
|
78
|
+
input, ffmpegPath, start, end,
|
|
79
|
+
filter: `silencedetect=noise=${noise}dB:d=${minDur}`,
|
|
80
|
+
});
|
|
81
|
+
// ffmpeg 输出的是相对本次输入的时间;加上 start 还原成绝对时间
|
|
82
|
+
const starts = [...stderr.matchAll(SS_RE)].map((m) => Number(m[1]));
|
|
83
|
+
const ends = [...stderr.matchAll(SE_RE)].map((m) => Number(m[1]));
|
|
84
|
+
const out = [];
|
|
85
|
+
for (let i = 0; i < starts.length; i++) {
|
|
86
|
+
const from = starts[i] + start;
|
|
87
|
+
const to = (ends[i] ?? (end !== undefined ? end - start : from + minDur)) + start;
|
|
88
|
+
if (to > from) out.push({ from: +from.toFixed(2), to: +to.toFixed(2) });
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 一次调用同时拿响度与静音(省一遍音频解码)。
|
|
95
|
+
*/
|
|
96
|
+
export async function analyzeAudio({ input, ffmpegPath, start = 0, end } = {}) {
|
|
97
|
+
// 音频分析是**增量**信息:任何一项失败都不能让分镜整体失败
|
|
98
|
+
const safe = async (fn, fallback) => {
|
|
99
|
+
try {
|
|
100
|
+
return await fn();
|
|
101
|
+
} catch {
|
|
102
|
+
try { return await fn(); } catch { return fallback; } // 并发时偶发的失败,重试一次
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const [loudness, silences] = await Promise.all([
|
|
106
|
+
safe(() => measureLoudness({ input, ffmpegPath, start, end }), null),
|
|
107
|
+
safe(() => detectSilence({ input, ffmpegPath, start, end }), []),
|
|
108
|
+
]);
|
|
109
|
+
if (!loudness || loudness.samples === 0) {
|
|
110
|
+
// 拿不到响度但有静音信息时,仍然把静音交出去(ASR 切片要用)
|
|
111
|
+
return silences.length > 0 ? { series: [], step: 0.1, mean: NaN, peak: NaN, dynamic: NaN, samples: 0, silences, source: 'silencedetect' } : null;
|
|
112
|
+
}
|
|
113
|
+
return { ...loudness, silences, source: 'ebur128' };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 声音事件检测:突然变响 / 突然安静。
|
|
118
|
+
*
|
|
119
|
+
* 为什么需要(社区反馈里最有用的一条):帧差只能看见"画面变了"。人说话忽然提高音量、
|
|
120
|
+
* 突然一片死寂、观众爆笑的那一刻——画面可能一动不动,但事情全在声音里。
|
|
121
|
+
*
|
|
122
|
+
* 判据(都对瞬时响度序列做,不引入模型):
|
|
123
|
+
* - **rise**:0.5 秒内上升 > 6 dB(一句台词突然激动、音乐进副歌)
|
|
124
|
+
* - **drop**:从有声跌到静音区,跌幅 > 12 dB(突然安静、话说完、留白)
|
|
125
|
+
* 相邻事件至少间隔 `minGap` 秒,避免把一段渐强拆成一串。
|
|
126
|
+
*
|
|
127
|
+
* @param {{series:number[], step:number, silences?:Array}} loudness
|
|
128
|
+
* @returns {Array<{t:number, kind:'rise'|'drop', delta:number}>}
|
|
129
|
+
*/
|
|
130
|
+
export function detectOnsets(loudness, {
|
|
131
|
+
riseDb = 8, dropDb = 15, windowSec = 0.5, minGap = 1.5, maxDelta = 30,
|
|
132
|
+
} = {}) {
|
|
133
|
+
const series = loudness?.series ?? [];
|
|
134
|
+
const step = loudness?.step ?? 0.1;
|
|
135
|
+
if (series.length === 0) return [];
|
|
136
|
+
const win = Math.max(1, Math.round(windowSec / step));
|
|
137
|
+
const out = [];
|
|
138
|
+
const push = (t, kind, delta) => {
|
|
139
|
+
const prev = out.at(-1);
|
|
140
|
+
if (prev && t - prev.t < minGap) {
|
|
141
|
+
if (Math.abs(delta) > Math.abs(prev.delta)) out[out.length - 1] = { t, kind, delta };
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
out.push({ t, kind, delta });
|
|
145
|
+
};
|
|
146
|
+
for (let i = win; i < series.length; i++) {
|
|
147
|
+
const now = series[i];
|
|
148
|
+
const before = series[i - win];
|
|
149
|
+
if (now <= LUFS_FLOOR && before <= LUFS_FLOOR) continue;
|
|
150
|
+
const raw = now - before;
|
|
151
|
+
// 数字静音(-120 LUFS)里起声会算出 100dB 以上的假落差,截断到 maxDelta,
|
|
152
|
+
// 免得它把"真正的大事"挤出排行榜。
|
|
153
|
+
const delta = Math.max(-maxDelta, Math.min(maxDelta, raw));
|
|
154
|
+
if (delta > riseDb) push(+(i * step).toFixed(2), 'rise', +delta.toFixed(1));
|
|
155
|
+
else if (delta < -dropDb) push(+(i * step).toFixed(2), 'drop', +delta.toFixed(1));
|
|
156
|
+
}
|
|
157
|
+
return out;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** 给文本清单用的一句话事实(明确区分"测出来的"和"看出来的") */
|
|
161
|
+
export function describeAudio(audio, window) {
|
|
162
|
+
if (!audio) return 'no audio track';
|
|
163
|
+
if (audio.samples === 0) return `${audio.silences.length} silence gaps (loudness unavailable)`;
|
|
164
|
+
const quiet = audio.silences.length;
|
|
165
|
+
const quietTime = audio.silences.reduce((s, r) => s + (r.to - r.from), 0);
|
|
166
|
+
return `mean ${audio.mean} LUFS, peak ${audio.peak} LUFS, ` +
|
|
167
|
+
`${audio.dynamic} dB dynamic range, ${quiet} silence gaps (${quietTime.toFixed(1)}s of ${window.toFixed(0)}s)`;
|
|
168
|
+
}
|