dsh-video-insight 0.8.1 → 0.8.5
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/README.md +24 -8
- package/client/client.js +80 -44
- package/lib/asr.js +162 -45
- package/lib/assets.js +60 -40
- package/lib/budget.js +84 -0
- package/lib/frames.js +41 -23
- package/lib/index.js +14 -9
- package/lib/media.js +5 -2
- package/lib/ocr.js +19 -3
- package/lib/storyboard.js +136 -60
- package/lib/vision.js +50 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](LICENSE)
|
|
4
4
|
[](https://github.com/deepseek-ai)
|
|
5
5
|
[](#已知限制)
|
|
6
|
-
[](package.json)
|
|
7
7
|
|
|
8
8
|

|
|
9
9
|
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
| 原文 | 字幕逐段列表(`[mm:ss] 文本`),可搜索过滤、点单条复制、一键复制全文;「双语」开关把每段翻译成中文/英文(`POST /translate`,按批送模型、结果按视频缓存),开启「跟随」后播放器播到哪、对应段落就高亮滚到视野里(时间轴同步由播放器外壳每秒回传) |
|
|
31
31
|
| 思维导图 | 模型把字幕整理成 3 层树状大纲(`GET /mindmap`,带缓存),面板渲染成 **SVG 图形化横向树**(节点卡片 + 贝塞尔连线、按分支配色),点节点折叠/展开,支持全部展开/收起、缩放、重新生成;节点上带可点的时间徽标(模型按字幕定位),点一下跳到视频对应位置 |
|
|
32
32
|
| 关键画面 | 关键画面总览(PPT 模式):与章节共用同一份大纲(`GET /outline`),一屏看到每章的代表画面;点「生成画面描述」让视觉模型一次性看完这套画面并给每章写一句描述(`POST /outline/visuals`,拼图后只发一张图),描述按视频缓存,章节页签也复用;点一张跳到那个画面并继续播放 |
|
|
33
|
-
| 分镜 |
|
|
33
|
+
| 分镜 | 按镜头切点抽帧、拼成**分镜拼图**(`POST /storyboard`,3 列;**帧数与张数按视频时长和剪辑密度自动定**:默认约每 20 秒一帧,一张最多 24 格,超过自动分成 2 张),每格左上角标时间;点任意一格跳到那个画面并继续播放。可选「附画面描述」让视觉模型逐张给每格写一句描述(悬停格子可见)。图片按视频缓存在 `~/.dsh/video-storyboards/`,切回页签秒开;低清视频和镜头切点也按视频缓存在 `~/.dsh/video-assets/`,转写、画面理解、分镜共用同一份,第二次打开页签不再重新下载 |
|
|
34
34
|
| 追问 | 左栏下方对话框:基于转写稿的 RAG 多轮问答(检索相关段落后再回答),回答带 `[mm:ss]`,下方「依据」chip 可点击跳转;对话按视频缓存。空态先给固定三句,再给 **AI 根据本视频总结生成的 3 条建议追问**(虚线 chip,点一下直接问) |
|
|
35
35
|
| 设置 | 填 B 站 Cookie(SESSDATA),保存到 `~/.dsh/video-credentials.json`(0600);可清除 |
|
|
36
36
|
| 历史 | 最近 100 条解析/分析记录(可搜索、可收藏星标),存在 `~/.dsh/video-history.json`(跨浏览器、跨重启都在),点击重新打开,可单条删除或清空 |
|
|
@@ -90,7 +90,7 @@ curl -L -o ggml-large-v3-turbo-q5_0.bin \
|
|
|
90
90
|
1. yt-dlp 下载 480p 以内的视频;
|
|
91
91
|
2. **按镜头切点抽帧**(`frameSampling: cuts`,默认):先扫一遍画面找剪辑点,一个镜头取一张,再按时间轴等分补齐(镜头太少时退化成均匀铺满);切分失败会自动退回「每 `ocrIntervalSeconds` 秒抽一帧」(`frameSampling: uniform`)。阈值 `cutThreshold` 默认 27,越高只抓越明显的转场;扫描只多一次 64×36 解码(实测 10 分钟片子约 4 秒),抽帧按时间点精确定位;
|
|
92
92
|
3. **本机 OCR**:用 macOS 自带的 Vision 框架离线识别中英文文字(首次使用会把一个小工具编译到 `~/.dsh/video-tools/ocr/`,约 10-20 秒,之后复用),完全不出本机;
|
|
93
|
-
4.
|
|
93
|
+
4. **画面理解(可选)**:把抽样的若干帧(帧数按时长自动定,默认约每 20 秒一帧、最多 96 帧;每 24 帧拼一张,可放多张)**拼成一张分镜图**(`visionPack: sheet`,默认 3 列、行数按帧数自动算)再交给支持图片输入的模型,让它按「第几格 = 第几秒」逐格描述场景、人物/物体、动作和画面文字;拼图失败会自动回落到逐帧发送(`visionPack: frames`)。默认 `frameMode: auto` 时,只有 OCR 平均每帧不足 4 字(比如纯动画、vlog)才追加这一轮;
|
|
94
94
|
5. 合并成带时间戳的文字稿:有画面描述时 `source: frame-vision`(视觉模型),只有本机文字时 `source: frame-ocr`;后续总结、章节、思维导图、追问都能用。
|
|
95
95
|
|
|
96
96
|
**为什么拼成一张图**:逐帧发时 12 帧就是 3 次请求、24 帧是 6 次,每张图都单独占一份图片 token;拼图后 24 帧只用 1 次请求、1 张图。实测同一段素材(Big Buck Bunny,24 帧):输入 token 13,312 → 1,905(−86%),耗时 66.0s → 26.9s(−59%),描述覆盖度与逐帧基本一致;12 帧时也分别是 −73% 和 −38%。
|
|
@@ -153,13 +153,13 @@ host 半零外部依赖(只用 Node 内置 `fetch`/`crypto`),不写锁文
|
|
|
153
153
|
| GET | `/dsh-video/api/status` | `{ok,value:{version,model,bilibili:{cookie},platforms,transcriptLimitChars,asr:{enabled,ready,engine,activeEngine,engineLabel,downloadReady}}}` |
|
|
154
154
|
| GET | `/dsh-video/api/resolve?url=&force=1` | 解析链接 → `VideoDoc`(失败也是 HTTP 200 + `{ok:false,code,error}`) |
|
|
155
155
|
| GET | `/dsh-video/api/asr/status?fresh=1` | 本地转写组件/引擎/模型状态 + `ocr`(画面文字识别)+ `vision`(画面理解/视觉模型能力)+ `privacy` 文案 + `hints` |
|
|
156
|
-
| POST | `/dsh-video/api/asr/config` | `{enabled?,engine?,threads?,maxSeconds?,keepAudio?,autoTranscribe?,ocrFallback?,ocrIntervalSeconds?,ocrMaxFrames?,frameSampling?:cuts\|uniform,cutThreshold?,frameMode?:auto\|ocr\|vision,visionModel?,visionMaxFrames?,visionPack?:sheet\|frames,sheetCols?}` → 新状态 |
|
|
156
|
+
| POST | `/dsh-video/api/asr/config` | `{enabled?,engine?,threads?,maxSeconds?,keepAudio?,autoTranscribe?,crossCheck?,ocrFallback?,ocrIntervalSeconds?,ocrMaxFrames?,frameSampling?:cuts\|uniform,cutThreshold?,frameMode?:auto\|ocr\|vision,visionModel?,visionMaxFrames?,visionPack?:sheet\|frames,sheetCols?}` → 新状态 |
|
|
157
157
|
| POST | `/dsh-video/api/transcribe` | SSE:`{url?/docId?, force?}`,帧 `phase` / `progress{percent,stage}` / `done{docId,transcript,cached?}` / `error{code,message}`;无语音时自动兜底 OCR / 画面理解(stage 含 `vision`) |
|
|
158
158
|
| POST | `/dsh-video/api/analyze` | SSE:`{mode:'summary'\|'ask', url?/docId?, question?, history?}`,帧 `phase` / `delta` / `done` / `error` |
|
|
159
159
|
| POST | `/dsh-video/api/chapters` | `{url?/docId?}` → `{ok,value:{chapters:[{start,title,gist}],duration}}` |
|
|
160
|
-
| GET | `/dsh-video/api/storyboard?docId=` | 取缓存的分镜:`{ok,value:{docId,url,title,platform,duration,generatedAt,tookMs,frameSampling,cuts,frames,cols,rows,cellWidth,cellHeight,described,cells:[{index,row,col,seconds,description?}]}}\|null` |
|
|
161
|
-
| GET | `/dsh-video/api/storyboard/image?docId=` |
|
|
162
|
-
| POST | `/dsh-video/api/storyboard` | SSE:`{docId?/url?, frames?:
|
|
160
|
+
| GET | `/dsh-video/api/storyboard?docId=` | 取缓存的分镜:`{ok,value:{docId,url,title,platform,duration,generatedAt,tookMs,frameSampling,cuts,frames,budget?,cols,rows,cellWidth,cellHeight,sheets:[{index,cols,rows,cellWidth,cellHeight,cells}],described,cells:[{index,sheet,row,col,seconds,description?}]}}\|null` |
|
|
161
|
+
| GET | `/dsh-video/api/storyboard/image?docId=&sheet=` | 第 N 张分镜拼图(`sheet` 从 0 开始,默认 0)`image/jpeg`(`no-store`);没生成过返回 `{code:'not-found'}` |
|
|
162
|
+
| POST | `/dsh-video/api/storyboard` | SSE:`{docId?/url?, frames?:0, cols?:3, describe?:boolean, force?:boolean}`(`frames: 0/缺省` = 按时长自动预算),帧 `phase` / `progress{stage:download\|scan\|frames,percent}` / `done{cached,docId,storyboard}` / `error{code,message}` |
|
|
163
163
|
| POST | `/dsh-video/api/storyboard/clear` | `{docId}` 删掉该视频的分镜(json + jpg) |
|
|
164
164
|
| POST | `/dsh-video/api/history/favorite` | `{docId, favorite}` 历史列表星标:返回 `{ok,value:{items}}`(重新解析不会冲掉) |
|
|
165
165
|
| GET | `/dsh-video/api/outline?docId=` | 章节/关键画面共用的大纲:`{ok,value:{docId,duration,source:'mindmap'\|'chapters'\|'uniform',signature,visuals,items:[{seconds,title,detail,description}]}}`;`visuals` 是已缓存的画面描述(没有则 null) |
|
|
@@ -214,6 +214,7 @@ host 半零外部依赖(只用 Node 内置 `fetch`/`crypto`),不写锁文
|
|
|
214
214
|
enabled: true
|
|
215
215
|
engine: auto # auto | whisper | sensevoice
|
|
216
216
|
autoTranscribe: true # 解析到无字幕视频时自动本地转写
|
|
217
|
+
crossCheck: true # 语音与画面两路并行分析、结果互相印证(默认 true)
|
|
217
218
|
ocrFallback: true # 连语音都没有时,抽帧做画面文字识别(OCR)
|
|
218
219
|
frameSampling: cuts # cuts=按镜头切点抽帧(默认)| uniform=固定间隔
|
|
219
220
|
cutThreshold: 27 # 镜头切点阈值(6-40),越高越只抓明显转场
|
|
@@ -236,11 +237,26 @@ host 半零外部依赖(只用 Node 内置 `fetch`/`crypto`),不写锁文
|
|
|
236
237
|
- YouTube 字幕是定时文本,标点/语气词可能有噪声;滚动字幕的重复窗口已做去重。
|
|
237
238
|
- B 站字幕只有「有 Cookie + 该视频确有 AI 字幕」才拿得到,不是每个视频都有。
|
|
238
239
|
- 按镜头抽帧时,画面文字段的「结束时间」按相邻帧间隔的中位数估算(各帧自身的秒数是准的),时间轴粗一点但不会串行;
|
|
240
|
+
- 语音转写与画面分析**并行**:`crossCheck` 默认开启,`POST /transcribe` 一开始就同时下载音频和低清视频、跑 whisper 与抽帧识别,两路结果合并成一份稿子(画面描述带「画面:」前缀)互相印证;显式设 `crossCheck: false` 才回到「先语音、没有语音再看画面」的顺序。
|
|
239
241
|
- 画面文字识别:只在 macOS 可用(依赖系统 Vision 框架);识别质量取决于画面文字是否清晰,滚动弹幕/花哨字体容易出错;抽帧默认按镜头切点(找不到切点时均匀铺满),因此长视频的覆盖密度取决于镜头数量而不是固定间隔。
|
|
242
|
+
### 帧数是怎么定的
|
|
243
|
+
|
|
244
|
+
不再固定 24 帧。`lib/budget.js` 按「时长 + 剪辑密度」算预算(参考 dsh-video-storyboard 的窗口思路):
|
|
245
|
+
|
|
246
|
+
| 情况 | 密度 | 例 |
|
|
247
|
+
|---|---|---|
|
|
248
|
+
| 常规节奏 | 每 20 秒 1 帧 | 20 分钟 → 60 帧(分 3 张拼图,受上限裁到 48 帧 / 2 张) |
|
|
249
|
+
| 剪辑密集(平均 <8 秒一个镜头) | 每 12 秒 1 帧 | 3.5 分钟 MV → 28 帧 / 2 张 |
|
|
250
|
+
| 长镜头 / 口播(平均 >45 秒一个镜头) | 每 30 秒 1 帧 | 1 小时讲座 → 96 帧(上限) |
|
|
251
|
+
|
|
252
|
+
- 下限 6 帧、上限 `visionMaxFrames`(默认 96,可调到 240);
|
|
253
|
+
- 镜头数也参与:至少接近「一镜半帧」,碎剪的片子不会因为时长预算被削平;
|
|
254
|
+
- 一张拼图最多 24 格,超出的自动分第二张,视觉模型逐张描述后合并。
|
|
255
|
+
|
|
240
256
|
- 画面理解:需要当前(或设置里指定的)模型声明 `image` 输入能力;会把拼好的分镜图发给模型(与 OCR 的本机离线不同);默认一张图装 9–24 格,所以按「张」而不是按「帧」计费(比逐帧省很多),单次生成仍要 15–30s;画面里既没字也没可描述内容时仍会得到 `asr-empty`。
|
|
241
257
|
- 本地转写:Whisper 首次加载 574MB 模型约 6–12 秒(每次调用固定成本,长视频占比可忽略);SenseVoice 段级时间戳是按标点聚合的近似值;`threads: 0` 交给引擎自己决定(whisper.cpp 默认 4)。
|
|
242
258
|
- 双语对照:翻译按批调用当前模型(40 段 / 3200 字一批),长视频要十几批、每批几秒;译文质量和模型相关;「跟随播放」高亮依赖播放器外壳回传时间,目前只有 YouTube 内嵌播放器会发,B 站播放器拿不到播放进度(不报错、不高亮)。
|
|
243
|
-
-
|
|
259
|
+
- 分镜:最多 2 张拼图 / 48 格(20 分钟片子约 46 格),第一次生成要下 480p + 跑一遍切点扫描(10 分钟片子约 10–20 秒);低清视频与切点会按视频缓存(`~/.dsh/video-assets/`,最多 8 个 / 2GB / 30 天),之后转写、画面理解、分镜都复用,重新生成约 1 秒;「附画面描述」会调用视觉模型,图片会离开本机。
|
|
244
260
|
- 只支持单条链接,不做播放列表 / 合集递归。
|
|
245
261
|
|
|
246
262
|
## 开发与自测
|
package/client/client.js
CHANGED
|
@@ -64,6 +64,8 @@ window.__ModuleLoader__.load({
|
|
|
64
64
|
'local-whisper': '本地 Whisper', 'local-sensevoice': '本地 SenseVoice',
|
|
65
65
|
'frame-ocr': '画面文字(OCR)',
|
|
66
66
|
'frame-vision': '画面理解',
|
|
67
|
+
'audio+vision': '语音 + 画面',
|
|
68
|
+
'audio+ocr': '语音 + 画面文字',
|
|
67
69
|
};
|
|
68
70
|
const LANG_LABEL = {
|
|
69
71
|
zh: '中文', 'zh-cn': '中文', 'zh-hans': '中文', 'zh-tw': '繁體中文', 'zh-hant': '繁體中文',
|
|
@@ -1280,11 +1282,12 @@ window.__ModuleLoader__.load({
|
|
|
1280
1282
|
/* -------------------------------------------------------------- 分镜 */
|
|
1281
1283
|
|
|
1282
1284
|
/** 分镜图地址:优先 transport 的 http 起源,其次同源相对路径(与播放器外壳一致)。 */
|
|
1283
|
-
function storyboardImageSrc(storyboard, docId) {
|
|
1285
|
+
function storyboardImageSrc(storyboard, docId, sheetIndex) {
|
|
1284
1286
|
const id = String((storyboard && storyboard.docId) || docId || '').trim();
|
|
1285
1287
|
if (!id) return '';
|
|
1286
1288
|
const version = storyboard && storyboard.generatedAt ? String(storyboard.generatedAt) : '';
|
|
1287
1289
|
let path = `/dsh-video/api/storyboard/image?docId=${encodeURIComponent(id)}`;
|
|
1290
|
+
if (sheetIndex !== undefined && sheetIndex !== null) path += `&sheet=${Math.max(0, Math.floor(Number(sheetIndex) || 0))}`;
|
|
1288
1291
|
if (version) path += `&v=${encodeURIComponent(version)}`;
|
|
1289
1292
|
const transport = playerTransportBase();
|
|
1290
1293
|
return transport ? `${transport}${path}` : path;
|
|
@@ -1604,22 +1607,32 @@ window.__ModuleLoader__.load({
|
|
|
1604
1607
|
|
|
1605
1608
|
/* -------------------------------------------------------------- 分镜 */
|
|
1606
1609
|
|
|
1607
|
-
/** 分镜页签:host
|
|
1610
|
+
/** 分镜页签:host 拼好的分镜图(可能多张)+ 每格时间戳覆盖层(点击 seek)。 */
|
|
1608
1611
|
function StoryboardTab({ doc, storyboard, describe, onDescribe, onGenerate, onCancel, onSeek }) {
|
|
1609
|
-
const [
|
|
1612
|
+
const [brokenSheets, setBrokenSheets] = useState({});
|
|
1610
1613
|
const data = storyboard ? storyboard.data : null;
|
|
1611
1614
|
const loading = Boolean(storyboard && storyboard.loading);
|
|
1612
1615
|
const error = storyboard ? storyboard.error : '';
|
|
1613
|
-
useEffect(() => {
|
|
1616
|
+
useEffect(() => { setBrokenSheets({}); }, [data && data.generatedAt]);
|
|
1614
1617
|
if (!doc) {
|
|
1615
1618
|
return h('div', { className: 'dvv-tabpane dvv-sb-tab' },
|
|
1616
1619
|
h('div', { className: 'dvv-empty-note' }, '先解析一个视频,再来看它的分镜。'));
|
|
1617
1620
|
}
|
|
1621
|
+
const budget = data && data.budget ? data.budget : null;
|
|
1622
|
+
const sheets = data
|
|
1623
|
+
? (Array.isArray(data.sheets) && data.sheets.length ? data.sheets : [{ index: 0, cols: data.cols, rows: data.rows }])
|
|
1624
|
+
: [];
|
|
1625
|
+
const sheetCount = sheets.length || 1;
|
|
1626
|
+
const secondsPerFrame = budget ? Number(budget.secondsPerFrame) : 0;
|
|
1627
|
+
const budgetReason = budget && budget.reason ? String(budget.reason) : '';
|
|
1618
1628
|
const toolbar = h('div', { key: 'bar', className: 'dvv-sb-toolbar' }, [
|
|
1619
1629
|
data ? h('span', { key: 'cached', className: 'dvv-mini' },
|
|
1620
1630
|
storyboard.cached === false ? '刚刚生成' : `已缓存${data.generatedAt ? ` · ${fmtRelative(data.generatedAt)}` : ''}`) : null,
|
|
1621
1631
|
data && data.described ? h('span', { key: 'described', className: 'dvv-mini', 'data-ok': 'true' }, '含描述') : null,
|
|
1622
|
-
data && data.frames ? h('span', {
|
|
1632
|
+
data && data.frames ? h('span', {
|
|
1633
|
+
key: 'count', className: 'dvv-sb-meta',
|
|
1634
|
+
title: budgetReason || undefined,
|
|
1635
|
+
}, `${data.frames} 帧 · ${sheetCount} 张${secondsPerFrame > 0 ? ` · 每 ${secondsPerFrame}s 一帧` : ''}`) : null,
|
|
1623
1636
|
data && data.frames ? h('span', { key: 'sampling', className: 'dvv-sb-meta' },
|
|
1624
1637
|
data.frameSampling === 'interval' ? '按间隔抽帧' : '按镜头切点抽帧') : null,
|
|
1625
1638
|
h('span', { key: 'spacer', className: 'dvv-sb-spacer' }),
|
|
@@ -1632,7 +1645,7 @@ window.__ModuleLoader__.load({
|
|
|
1632
1645
|
]),
|
|
1633
1646
|
data ? h('a', {
|
|
1634
1647
|
key: 'big', className: 'dvv-btn dvv-link-btn',
|
|
1635
|
-
href: storyboardImageSrc(data, doc.docId), target: '_blank', rel: 'noreferrer',
|
|
1648
|
+
href: storyboardImageSrc(data, doc.docId, 0), target: '_blank', rel: 'noreferrer',
|
|
1636
1649
|
}, '打开大图') : null,
|
|
1637
1650
|
h('button', {
|
|
1638
1651
|
key: 'generate', type: 'button', className: 'dvv-btn', disabled: loading,
|
|
@@ -1656,40 +1669,52 @@ window.__ModuleLoader__.load({
|
|
|
1656
1669
|
body = h('div', { key: 'empty', className: 'dvv-empty-note' },
|
|
1657
1670
|
'这个视频还没有分镜。点「生成分镜」,把整段视频的画面拼成一张图。');
|
|
1658
1671
|
} else {
|
|
1659
|
-
const
|
|
1660
|
-
const
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
h('
|
|
1671
|
-
key: '
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
}
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1672
|
+
const allCells = Array.isArray(data.cells) ? data.cells : [];
|
|
1673
|
+
const sheetNodes = sheets.map((sheet, index) => {
|
|
1674
|
+
const sheetIndex = Number.isFinite(Number(sheet.index)) ? Math.max(0, Math.floor(Number(sheet.index))) : index;
|
|
1675
|
+
const own = Array.isArray(sheet.cells) && sheet.cells.length
|
|
1676
|
+
? sheet.cells
|
|
1677
|
+
: allCells.filter((cell) => Math.max(0, Math.floor(Number(cell.sheet) || 0)) === sheetIndex);
|
|
1678
|
+
const cols = Math.max(1, Number(sheet.cols) || Number(data.cols) || 1);
|
|
1679
|
+
const rows = Math.max(1, Number(sheet.rows) || Number(data.rows) || 1);
|
|
1680
|
+
const broken = Boolean(brokenSheets[sheetIndex]);
|
|
1681
|
+
return h('div', { key: `sheet-${sheetIndex}`, className: 'dvv-sb-sheet', 'data-sheet': String(sheetIndex) }, [
|
|
1682
|
+
broken
|
|
1683
|
+
? h('div', { key: 'broken', className: 'dvv-sb-broken' }, [
|
|
1684
|
+
h('div', { key: 'title', className: 'dvv-sb-broken-title' }, '分镜图加载失败'),
|
|
1685
|
+
h('button', { key: 'retry', type: 'button', className: 'dvv-btn', onClick: () => onGenerate() }, '重新生成'),
|
|
1686
|
+
])
|
|
1687
|
+
: h('div', { key: 'sb', className: 'dvv-sb' }, [
|
|
1688
|
+
h('img', {
|
|
1689
|
+
key: 'img', className: 'dvv-sb-img',
|
|
1690
|
+
src: storyboardImageSrc(data, doc.docId, sheetIndex),
|
|
1691
|
+
alt: `${doc.title || '视频'} 的分镜图(第 ${index + 1} 张)`, loading: 'lazy',
|
|
1692
|
+
onError: () => setBrokenSheets((prev) => ({ ...prev, [sheetIndex]: true })),
|
|
1693
|
+
}),
|
|
1694
|
+
...own.map((cell) => {
|
|
1695
|
+
const col = Math.max(0, Number(cell.col) || 0);
|
|
1696
|
+
const row = Math.max(0, Number(cell.row) || 0);
|
|
1697
|
+
const label = formatClock(cell.seconds);
|
|
1698
|
+
return h('button', {
|
|
1699
|
+
key: `cell-${sheetIndex}-${cell.index}-${row}-${col}`, type: 'button', className: 'dvv-sb-cell',
|
|
1700
|
+
style: {
|
|
1701
|
+
left: `${(col / cols) * 100}%`,
|
|
1702
|
+
top: `${(row / rows) * 100}%`,
|
|
1703
|
+
width: `${100 / cols}%`,
|
|
1704
|
+
height: `${100 / rows}%`,
|
|
1705
|
+
},
|
|
1706
|
+
title: cell.description || `跳到 ${label}`,
|
|
1707
|
+
'data-seconds': String(cell.seconds),
|
|
1708
|
+
'data-sheet': String(sheetIndex),
|
|
1709
|
+
onClick: () => onSeek(cell.seconds),
|
|
1710
|
+
}, h('span', { key: 'clock', className: 'dvv-sb-clock' }, label));
|
|
1711
|
+
}),
|
|
1712
|
+
]),
|
|
1713
|
+
h('div', { key: 'cap', className: 'dvv-sb-cap' }, `第 ${index + 1}/${sheetCount} 张 · ${cols}×${rows} 格`),
|
|
1714
|
+
]);
|
|
1715
|
+
});
|
|
1716
|
+
body = h('div', { key: 'sheets', className: 'dvv-sb-wrap' }, [
|
|
1717
|
+
...sheetNodes,
|
|
1693
1718
|
data.described ? h('div', { key: 'note', className: 'dvv-sb-note' },
|
|
1694
1719
|
'把鼠标放到格子上可以看到画面描述;点击格子会跳到对应画面。') : null,
|
|
1695
1720
|
].filter(Boolean));
|
|
@@ -1719,7 +1744,7 @@ window.__ModuleLoader__.load({
|
|
|
1719
1744
|
]);
|
|
1720
1745
|
}
|
|
1721
1746
|
|
|
1722
|
-
/* ---------------------------------------------------------- 历史列表 / 抽屉 */
|
|
1747
|
+
/* ---------------------------------------------------------- 历史列表 / 抽屉 */
|
|
1723
1748
|
|
|
1724
1749
|
/** 封面缩略图:没有 cover 或加载失败时用纯色占位。 */
|
|
1725
1750
|
function HistoryCover({ src, alt }) {
|
|
@@ -1805,7 +1830,7 @@ window.__ModuleLoader__.load({
|
|
|
1805
1830
|
.map((value) => String(value ?? '')).join(' ').toLowerCase();
|
|
1806
1831
|
return hay.includes(needle);
|
|
1807
1832
|
});
|
|
1808
|
-
return h('div', { className: 'dvv-overlay', onClick: onClose }, h('div', {
|
|
1833
|
+
return h('div', { className: 'dvv-overlay', 'data-quiet': 'true', onClick: onClose }, h('div', {
|
|
1809
1834
|
key: 'drawer', className: 'dvv-drawer', onClick: (event) => { if (event && typeof event.stopPropagation === 'function') event.stopPropagation(); },
|
|
1810
1835
|
}, [
|
|
1811
1836
|
h('div', { key: 'head', className: 'dvv-drawer-head' }, [
|
|
@@ -1944,6 +1969,14 @@ window.__ModuleLoader__.load({
|
|
|
1944
1969
|
}),
|
|
1945
1970
|
h('span', { key: 't' }, '无字幕视频自动转写(解析到没有字幕的视频时自动在本地跑一次转写,长视频可能要等一会儿)'),
|
|
1946
1971
|
]));
|
|
1972
|
+
rows.push(h('label', { key: 'cross', className: 'dvv-check' }, [
|
|
1973
|
+
h('input', {
|
|
1974
|
+
key: 'c', type: 'checkbox', checked: config.crossCheck !== false,
|
|
1975
|
+
onChange: () => onConfig({ crossCheck: config.crossCheck === false }),
|
|
1976
|
+
}),
|
|
1977
|
+
h('span', { key: 't' }, '语音与画面并行分析'),
|
|
1978
|
+
]));
|
|
1979
|
+
rows.push(h('div', { key: 'cross-note', className: 'dvv-note' }, '和语音转写同时跑画面分析,两路结果互相印证(多花一次视觉模型调用)。'));
|
|
1947
1980
|
const ocr = asr.ocr || {};
|
|
1948
1981
|
rows.push(h('label', { key: 'ocr', className: 'dvv-check' }, [
|
|
1949
1982
|
h('input', {
|
|
@@ -3602,7 +3635,8 @@ a.dvv-toolbar-title:hover{color:var(--dsw-alias-brand-primary)}
|
|
|
3602
3635
|
.dvv-textarea{flex:1;min-width:0;font:inherit;font-size:13px;line-height:21px;min-height:42px;max-height:140px;padding:8px 12px;border-radius:10px;border:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.14));background:var(--dsw-alias-bg-layer-1,transparent);color:inherit;outline:none;resize:vertical}
|
|
3603
3636
|
.dvv-textarea:focus{border-color:var(--dsw-alias-brand-primary)}
|
|
3604
3637
|
.dvv-overlay{position:absolute;inset:0;z-index:20;display:flex;justify-content:flex-end;background:var(--dsw-alias-bg-overlay,rgba(0,0,0,.32))}
|
|
3605
|
-
.dvv-
|
|
3638
|
+
.dvv-overlay[data-quiet="true"]{background:transparent}
|
|
3639
|
+
.dvv-drawer{display:flex;flex-direction:column;width:min(420px,92%);height:100%;background:var(--dsw-alias-bg-layer-1,Canvas);border-left:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.12));box-shadow:-10px 0 32px rgba(0,0,0,.18)}
|
|
3606
3640
|
.dvv-modal{display:flex;flex-direction:column;width:min(600px,94%);max-height:88%;margin:auto;background:var(--dsw-alias-bg-layer-1,Canvas);border:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.12));border-radius:14px;box-shadow:0 18px 48px rgba(0,0,0,.24);overflow:hidden}
|
|
3607
3641
|
.dvv-drawer-head{display:flex;align-items:center;gap:8px;padding:12px 16px;border-bottom:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.1));background:var(--dsw-specific-sidebar-fill,transparent)}
|
|
3608
3642
|
.dvv-drawer-title{flex:1;min-width:0;font-size:14px;line-height:21px;font-weight:600}
|
|
@@ -3727,7 +3761,9 @@ a.dvv-toolbar-title:hover{color:var(--dsw-alias-brand-primary)}
|
|
|
3727
3761
|
.dvv-sb-meta{font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}
|
|
3728
3762
|
.dvv-sb-check{display:flex;align-items:center;gap:4px;font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary);cursor:pointer}
|
|
3729
3763
|
.dvv-sb-progress{display:flex;flex-direction:column;gap:8px;padding:12px 0}
|
|
3730
|
-
.dvv-sb-wrap{display:flex;flex-direction:column;gap:
|
|
3764
|
+
.dvv-sb-wrap{display:flex;flex-direction:column;gap:14px}
|
|
3765
|
+
.dvv-sb-sheet{display:flex;flex-direction:column;gap:4px;min-width:0}
|
|
3766
|
+
.dvv-sb-cap{font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}
|
|
3731
3767
|
.dvv-sb{position:relative;width:100%;border-radius:12px;overflow:hidden;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2)}
|
|
3732
3768
|
.dvv-sb-img{display:block;width:100%;height:auto}
|
|
3733
3769
|
.dvv-sb-cell{position:absolute;appearance:none;margin:0;padding:0;border:0;background:transparent;cursor:pointer;outline:none}
|
package/lib/asr.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* 这样 analyze.js / 面板都不用区分来源。
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
13
|
+
import { mkdir, readFile, rm, unlink, writeFile } from 'node:fs/promises';
|
|
14
14
|
import { homedir } from 'node:os';
|
|
15
15
|
import { join } from 'node:path';
|
|
16
16
|
|
|
@@ -37,6 +37,8 @@ export const ASR_DEFAULTS = {
|
|
|
37
37
|
maxSeconds: 0,
|
|
38
38
|
keepAudio: false,
|
|
39
39
|
autoTranscribe: true,
|
|
40
|
+
// 并行管线:语音转写与画面理解同时跑,结果合并互相印证(默认开)。
|
|
41
|
+
crossCheck: true,
|
|
40
42
|
// 纯无声视频(没有配音也没有字幕)的兜底:抽帧做画面文字识别(OCR)。
|
|
41
43
|
ocrFallback: true,
|
|
42
44
|
ocrIntervalSeconds: 8,
|
|
@@ -45,7 +47,7 @@ export const ASR_DEFAULTS = {
|
|
|
45
47
|
// frameMode: auto(先 OCR,文字太少再用视觉模型)/ ocr(只用本机 OCR)/ vision(直接看画面)。
|
|
46
48
|
frameMode: 'auto',
|
|
47
49
|
visionModel: '',
|
|
48
|
-
visionMaxFrames:
|
|
50
|
+
visionMaxFrames: 96,
|
|
49
51
|
// 喂图方式:sheet = 多帧拼成一张分镜图(默认,省图省时)/ frames = 逐帧发。
|
|
50
52
|
visionPack: 'sheet',
|
|
51
53
|
sheetCols: 3,
|
|
@@ -80,6 +82,12 @@ export async function readLocalTranscript(docId) {
|
|
|
80
82
|
try {
|
|
81
83
|
const data = JSON.parse(await readFile(transcriptFile(docId), 'utf8'));
|
|
82
84
|
if (data && data.available === true && Array.isArray(data.segments) && data.segments.length > 0) {
|
|
85
|
+
// 旧版本可能把 whisper 的幻听结果写进了缓存:整段重复同一句话时当作没有,
|
|
86
|
+
// 顺手把坏缓存删掉,下次会重新走转写/画面分析。
|
|
87
|
+
if (isDegenerateTranscript(data.segments)) {
|
|
88
|
+
await unlink(transcriptFile(docId)).catch(() => {});
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
83
91
|
return { ...data, cached: true };
|
|
84
92
|
}
|
|
85
93
|
} catch { /* 没有缓存或坏了:当作没转写过 */ }
|
|
@@ -111,6 +119,7 @@ export function asrSettings(settings) {
|
|
|
111
119
|
maxSeconds: Math.min(Math.max(Number(raw.maxSeconds) || 0, 0), 4 * 60 * 60),
|
|
112
120
|
keepAudio: Boolean(raw.keepAudio),
|
|
113
121
|
autoTranscribe: raw.autoTranscribe !== false,
|
|
122
|
+
crossCheck: raw.crossCheck !== false,
|
|
114
123
|
ocrFallback: raw.ocrFallback !== false,
|
|
115
124
|
ocrIntervalSeconds: Math.min(Math.max(Math.round(Number(raw.ocrIntervalSeconds) || 8), 3), 60),
|
|
116
125
|
ocrMaxFrames: Math.min(Math.max(Math.round(Number(raw.ocrMaxFrames) || 120), 20), 240),
|
|
@@ -129,6 +138,31 @@ function formatBytes(bytes) {
|
|
|
129
138
|
}
|
|
130
139
|
|
|
131
140
|
/** 去掉 *music* / [Applause] / (音乐) 这类非语音标注后,真正说出来的字数。 */
|
|
141
|
+
/** 去掉标点/空白,用于「同一句话」比较。 */
|
|
142
|
+
function normalizeSegmentText(text) {
|
|
143
|
+
return String(text ?? '')
|
|
144
|
+
.toLowerCase()
|
|
145
|
+
.replace(/[\s♪♫.,,。!?!?、…"'“”‘’()()\-—–::;;]/g, '');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* whisper 对纯音乐/无对白视频常见的退化输出:同一句话重复几十上百遍。
|
|
150
|
+
* 这种稿子当成「没有语音」处理,才能让画面理解兜底。
|
|
151
|
+
*/
|
|
152
|
+
export function isDegenerateTranscript(segments) {
|
|
153
|
+
const list = Array.isArray(segments) ? segments : [];
|
|
154
|
+
const usable = list.filter((segment) => normalizeSegmentText(segment?.text).length >= 4);
|
|
155
|
+
if (usable.length < 12) return false;
|
|
156
|
+
const counts = new Map();
|
|
157
|
+
for (const segment of usable) {
|
|
158
|
+
const key = normalizeSegmentText(segment.text);
|
|
159
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
160
|
+
}
|
|
161
|
+
let top = 0;
|
|
162
|
+
for (const count of counts.values()) top = Math.max(top, count);
|
|
163
|
+
return top / usable.length >= 0.45;
|
|
164
|
+
}
|
|
165
|
+
|
|
132
166
|
function spokenChars(segments) {
|
|
133
167
|
let chars = 0;
|
|
134
168
|
for (const segment of Array.isArray(segments) ? segments : []) {
|
|
@@ -261,6 +295,7 @@ export async function asrStatus(settings, { fresh = false, ai = null, attachment
|
|
|
261
295
|
maxSeconds: asr.maxSeconds,
|
|
262
296
|
keepAudio: asr.keepAudio,
|
|
263
297
|
autoTranscribe: asr.autoTranscribe,
|
|
298
|
+
crossCheck: asr.crossCheck,
|
|
264
299
|
ocrFallback: asr.ocrFallback,
|
|
265
300
|
ocrIntervalSeconds: asr.ocrIntervalSeconds,
|
|
266
301
|
ocrMaxFrames: asr.ocrMaxFrames,
|
|
@@ -396,6 +431,46 @@ async function transcribeSenseVoice({ engine, wav, workdir, asr, signal }) {
|
|
|
396
431
|
|
|
397
432
|
/* --------------------------------- public ---------------------------------- */
|
|
398
433
|
|
|
434
|
+
const MERGED_VISUAL_LIMIT = 24;
|
|
435
|
+
|
|
436
|
+
/** 把语音稿和画面描述合并成一份带时间戳的稿子:语音段原样、画面段加「画面:」前缀。 */
|
|
437
|
+
export function mergeTranscripts(audioTranscript, visualTranscript) {
|
|
438
|
+
const audioSegments = Array.isArray(audioTranscript?.segments) ? audioTranscript.segments : [];
|
|
439
|
+
const visualSegments = Array.isArray(visualTranscript?.segments) ? visualTranscript.segments : [];
|
|
440
|
+
const segments = audioSegments.map((segment) => ({
|
|
441
|
+
start: Number(segment.start) || 0,
|
|
442
|
+
end: Math.max(Number(segment.end) || 0, Number(segment.start) || 0 + 0.5),
|
|
443
|
+
text: String(segment.text ?? '').trim(),
|
|
444
|
+
}));
|
|
445
|
+
for (const segment of visualSegments.slice(0, MERGED_VISUAL_LIMIT)) {
|
|
446
|
+
const text = String(segment.text ?? '').trim();
|
|
447
|
+
if (!text) continue;
|
|
448
|
+
const start = Number(segment.start) || 0;
|
|
449
|
+
segments.push({ start, end: Math.max(Number(segment.end) || start, start + 0.5), text: `画面:${text}` });
|
|
450
|
+
}
|
|
451
|
+
segments.sort((left, right) => left.start - right.start);
|
|
452
|
+
const chars = segments.reduce((sum, segment) => sum + segment.text.length, 0);
|
|
453
|
+
const visualSource = String(visualTranscript?.source ?? '');
|
|
454
|
+
const ocrOnly = visualSource === 'frame-ocr';
|
|
455
|
+
return {
|
|
456
|
+
available: true,
|
|
457
|
+
source: ocrOnly ? 'audio+ocr' : 'audio+vision',
|
|
458
|
+
engine: `${audioTranscript?.engine ?? 'asr'}+${ocrOnly ? 'vision-ocr' : 'vision'}`,
|
|
459
|
+
engineLabel: `${audioTranscript?.engineLabel ?? '语音识别'} + ${ocrOnly ? '画面文字识别' : '画面理解'}`,
|
|
460
|
+
lang: audioTranscript?.lang ?? 'auto',
|
|
461
|
+
chars,
|
|
462
|
+
segments: segments.slice(0, MAX_TRANSCRIPT_SEGMENTS * 2),
|
|
463
|
+
tookMs: Math.max(Number(audioTranscript?.tookMs) || 0, Number(visualTranscript?.tookMs) || 0),
|
|
464
|
+
crossChecked: true,
|
|
465
|
+
visual: {
|
|
466
|
+
source: visualTranscript?.source ?? '',
|
|
467
|
+
engine: visualTranscript?.engine ?? '',
|
|
468
|
+
engineLabel: visualTranscript?.engineLabel ?? '',
|
|
469
|
+
describedFrames: visualTranscript?.describedFrames ?? null,
|
|
470
|
+
},
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
|
|
399
474
|
/**
|
|
400
475
|
* 把视频音轨转成带时间戳的文字稿。调用方负责 SSE 进度帧与缓存更新。
|
|
401
476
|
* 返回的 transcript 与平台字幕同构,额外带 `engine` / `tookMs` 供面板展示。
|
|
@@ -424,12 +499,12 @@ export async function transcribeVideo({ doc, settings, ai = null, attachments =
|
|
|
424
499
|
}
|
|
425
500
|
|
|
426
501
|
const workdir = await createWorkdir();
|
|
502
|
+
const frameWorkdir = await createWorkdir();
|
|
427
503
|
let keep = false;
|
|
428
504
|
try {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
if (engine) {
|
|
505
|
+
/* 音频一路:下载音轨 → 16kHz wav → whisper / SenseVoice。 */
|
|
506
|
+
const runAudio = async () => {
|
|
507
|
+
if (!engine) return { skip: true };
|
|
433
508
|
try {
|
|
434
509
|
onPhase?.('正在下载音频…');
|
|
435
510
|
const audio = await downloadAudio({
|
|
@@ -458,11 +533,13 @@ export async function transcribeVideo({ doc, settings, ai = null, attachments =
|
|
|
458
533
|
const segments = result.segments.slice(0, MAX_TRANSCRIPT_SEGMENTS);
|
|
459
534
|
const chars = segments.reduce((sum, item) => sum + item.text.length, 0);
|
|
460
535
|
// whisper 对纯音乐/无对白视频会输出 "*music*" 之类的占位标签,这不算有语音内容,
|
|
461
|
-
//
|
|
536
|
+
// 或者整段重复同一句话(幻听),都当作没有语音,让画面那一路顶上。
|
|
537
|
+
if (isDegenerateTranscript(segments)) {
|
|
538
|
+
throw new VideoError('asr-empty', '识别结果几乎都是同一句话(多半是纯音乐 / 无对白),改走画面分析');
|
|
539
|
+
}
|
|
462
540
|
if (!segments.length || spokenChars(segments) < 8) {
|
|
463
541
|
throw new VideoError('asr-empty', '没有识别出可用的语音(可能是纯音乐 / 无对白视频)');
|
|
464
542
|
}
|
|
465
|
-
// 长视频只截断返回给模型的量;面板仍能拿到完整段落。
|
|
466
543
|
onProgress?.({ percent: 100, stage: 'transcribe' });
|
|
467
544
|
onPhase?.(`识别完成:${segments.length} 段 / ${chars} 字,用时 ${(tookMs / 1000).toFixed(1)}s`);
|
|
468
545
|
|
|
@@ -471,59 +548,99 @@ export async function transcribeVideo({ doc, settings, ai = null, attachments =
|
|
|
471
548
|
await keepAudioCopy(audio.file).catch(() => '');
|
|
472
549
|
}
|
|
473
550
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
551
|
+
return {
|
|
552
|
+
transcript: {
|
|
553
|
+
available: true,
|
|
554
|
+
source: engine.source,
|
|
555
|
+
engine: engine.id,
|
|
556
|
+
engineLabel: engine.label,
|
|
557
|
+
lang: result.lang,
|
|
558
|
+
chars,
|
|
559
|
+
segments,
|
|
560
|
+
tookMs,
|
|
561
|
+
},
|
|
483
562
|
};
|
|
484
563
|
} catch (error) {
|
|
485
|
-
// 下载不到音轨、或者整段没有语音(纯音乐/无声视频)时,不直接失败:
|
|
486
|
-
// 退到「画面文字识别」,让这类视频也有可用的文字稿。
|
|
487
564
|
if (signal?.aborted || error?.code === 'aborted') throw error;
|
|
488
|
-
|
|
565
|
+
return { error };
|
|
489
566
|
}
|
|
490
|
-
}
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
/* 画面一路:低清视频 → 镜头切点 → 抽帧 → 本机 OCR →(视觉模型描述画面)。 */
|
|
570
|
+
const runFrames = async () => {
|
|
571
|
+
if (!frameUsable) return { skip: true };
|
|
572
|
+
try {
|
|
573
|
+
const transcript = await frameTranscript({
|
|
574
|
+
// 和语音那一路并行时,画面也交给视觉模型看一遍:两路结果互相印证。
|
|
575
|
+
preferVision: asr.frameMode !== 'ocr',
|
|
576
|
+
doc,
|
|
577
|
+
settings,
|
|
578
|
+
workdir: frameWorkdir,
|
|
579
|
+
tools,
|
|
580
|
+
asr,
|
|
581
|
+
ai,
|
|
582
|
+
attachments,
|
|
583
|
+
onPhase: (text) => onPhase?.(`画面:${text}`),
|
|
584
|
+
onProgress: (event) => onProgress?.({ ...event, stage: 'frames' }),
|
|
585
|
+
signal,
|
|
586
|
+
});
|
|
587
|
+
return { transcript };
|
|
588
|
+
} catch (error) {
|
|
589
|
+
if (signal?.aborted || error?.code === 'aborted') throw error;
|
|
590
|
+
return { error };
|
|
591
|
+
}
|
|
592
|
+
};
|
|
491
593
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
594
|
+
const parallel = asr.crossCheck !== false && Boolean(engine) && frameUsable;
|
|
595
|
+
let audioResult = { skip: true };
|
|
596
|
+
let frameResult = { skip: true };
|
|
597
|
+
|
|
598
|
+
if (parallel) {
|
|
599
|
+
onPhase?.('语音转写与画面理解同时进行(两路并行,结果互相印证)…');
|
|
600
|
+
[audioResult, frameResult] = await Promise.all([runAudio(), runFrames()]);
|
|
601
|
+
} else {
|
|
602
|
+
audioResult = await runAudio();
|
|
603
|
+
if (audioResult?.error) {
|
|
604
|
+
const reason = audioResult.error.code === 'asr-empty' ? '没有识别出语音' : '拿不到音频';
|
|
605
|
+
onPhase?.(
|
|
606
|
+
asr.frameMode === 'ocr'
|
|
607
|
+
? `${reason},改为抽取画面文字(视频不会离开这台电脑)…`
|
|
608
|
+
: `${reason},改为识别画面内容…`,
|
|
609
|
+
);
|
|
499
610
|
}
|
|
500
|
-
transcript = await
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
611
|
+
if (!audioResult?.transcript && frameUsable) frameResult = await runFrames();
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
let transcript = audioResult?.transcript ?? null;
|
|
615
|
+
const audioError = audioResult?.error ?? null;
|
|
616
|
+
const visual = frameResult?.transcript ?? null;
|
|
617
|
+
const visualError = frameResult?.error ?? null;
|
|
618
|
+
const visualSegments = Array.isArray(visual?.segments)
|
|
619
|
+
? visual.segments.filter((segment) => String(segment?.text ?? '').trim())
|
|
620
|
+
: [];
|
|
621
|
+
|
|
622
|
+
if (transcript && visualSegments.length) {
|
|
623
|
+
// 两路都有内容:合并成一份稿子,摘要/思维导图/追问都能同时参考「说了什么」和「画面是什么」。
|
|
624
|
+
const audioSegments = Array.isArray(transcript.segments) ? transcript.segments.length : 0;
|
|
625
|
+
const merged = mergeTranscripts(transcript, visual);
|
|
626
|
+
onPhase?.(`语音稿 ${audioSegments} 段 + 画面描述 ${visualSegments.length} 段,已合并互相印证。`);
|
|
627
|
+
transcript = merged;
|
|
628
|
+
} else if (!transcript && visual?.available) {
|
|
629
|
+
transcript = visual;
|
|
512
630
|
}
|
|
513
631
|
|
|
514
632
|
if (!transcript) {
|
|
633
|
+
if (audioError && audioError.code !== 'asr-empty') throw audioError;
|
|
634
|
+
if (visualError) throw visualError;
|
|
515
635
|
if (audioError) throw audioError;
|
|
516
|
-
|
|
517
|
-
throw new VideoError(
|
|
518
|
-
'asr-unavailable',
|
|
519
|
-
`本机还没有可用的语音识别引擎。${hints.length ? `\n${hints.join('\n')}` : ''}`,
|
|
520
|
-
);
|
|
636
|
+
throw new VideoError('asr-failed', '转写失败:语音识别和画面分析都没有拿到内容。');
|
|
521
637
|
}
|
|
522
638
|
|
|
523
639
|
await writeLocalTranscript(doc.docId, transcript);
|
|
524
640
|
return transcript;
|
|
525
641
|
} finally {
|
|
526
642
|
if (!keep) await cleanupWorkdir(workdir);
|
|
643
|
+
await cleanupWorkdir(frameWorkdir).catch(() => {});
|
|
527
644
|
}
|
|
528
645
|
}
|
|
529
646
|
|