deep-read-summarize 0.3.4 → 0.3.6
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/CHANGELOG.md +14 -1
- package/README.md +62 -5
- package/package.json +1 -1
- package/parsers/video.js +35 -12
- package/scripts/transcribe.ps1 +68 -0
- package/skills/deep-read-summarize/SKILL.md +10 -2
- package/workflow.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,20 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/).
|
|
5
5
|
|
|
6
|
-
## [0.3.
|
|
6
|
+
## [0.3.6] — 2026-08-28
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
- **统一视频转写工具 `scripts/transcribe.ps1`(关键)**:自举 faster-whisper(`uv` 建 Python 3.11 环境 + 清华镜像安装 + `HF_ENDPOINT=https://hf-mirror.com` 下模型并缓存),small/int8/VAD;**本机与用户使用一致**(只依赖环境变量与标准路径),无需单独 ffmpeg(faster-whisper 内置 PyAV 解码)。
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
- **视频解析器 yt-dlp 防卡死**:未装 yt-dlp 时**绝不下载 exe 二进制**(GitHub 直连易卡死),改用 `winget install yt-dlp.yt-dlp` 或 `pip install -U yt-dlp -i 镜像`;并加 `--socket-timeout 15 --retries 3` 防超时。
|
|
13
|
+
- **workflow 精读防超时中止**:`maxChunks` 默认 6→4、`maxRetries` 默认 1→0;波次2「并行精读」改为**分批并行**(每批 3 个块),降低子代理数与单次调用时长。
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- **`parsers/video.js` 统一流水线(去三档)**:目标 = 拿到**完整逐字稿**再精读。① 有平台字幕(B站 AI 字幕 / YouTube CC / yt-dlp CC)→ 直接用字幕(快、零依赖);② 无公开字幕 → 用 `scripts/transcribe.ps1` 转写得到全文;③ 都不行 → 降级提示人工转写文本,或退回 desc 作背景;**绝不阻塞、绝不自动装重依赖**。
|
|
17
|
+
- **`options.transcribe` 默认 true**(无字幕自动走本地转写),`false` 则跳过转写。
|
|
18
|
+
- **textSource** 标注实际来源:`subtitle / transcription / desc / manual`;来源信息**透出在运行日志 `[source] …` 与返回结果 `textSource`,不写进笔记**(保持笔记美观)。
|
|
19
|
+
- `SKILL.md` / `README.md` 同步为「完整逐字稿(字幕优先,无字幕自动转写)」策略与效果预估。
|
|
7
20
|
|
|
8
21
|
### Fixed
|
|
9
22
|
- **DSH rc7(Cordis)兼容修复**:插件入口改为标准 Cordis 插件契约(导出 `name` + `inject: ['skills']` + `apply(ctx)`),apply 时将自带 SKILL.md 注册为运行时技能(含 workflow meta + 自包含 script + args 示例),修复 0.3.3 在 rc7 上「invalid plugin / 插件树加载失败 / harness 无法启动」的问题(旧入口只导出 load/workflow/parsers/schemas,无 apply)。
|
package/README.md
CHANGED
|
@@ -7,17 +7,21 @@
|
|
|
7
7
|
|
|
8
8
|
> **Disclaimer**: This is an **unofficial third-party tool**. It is not affiliated with, endorsed by, or sponsored by DeepSeek or the DeepSeek Harness project. "DeepSeek" and "DeepSeek Harness" are trademarks of their respective owners. This project only orchestrates the workflow tool available in your DSH environment; it does not redistribute any DeepSeek software.
|
|
9
9
|
|
|
10
|
+
> **⚠️ 最重要:本工具是「辅助精读」工具,不能代替自主学习。** 它帮你快速提取、归纳、结构化阅读内容,但**真正的理解、思考与批判仍需你自己完成**;请始终以原文为准,不要把它当作学习成果本身。
|
|
11
|
+
|
|
10
12
|
给 DSH(DeepSeek Harness)写的一个精读工作流:输入一本书、一篇论文、一个视频链接或网页,输出一份结构化的 Obsidian 笔记。
|
|
11
13
|
|
|
12
14
|
内容会被拆成若干块,由多个子代理并行精读,再合并成一篇带 YAML frontmatter 的 Markdown。关键结论附原文出处,成稿前有一道质量校验。
|
|
13
15
|
|
|
16
|
+
> 使用中遇到问题、或觉得哪里能更好,**欢迎随时在 GitHub issue 反馈**。
|
|
17
|
+
|
|
14
18
|
> 注意:DSH 目前是 developer preview,接口可能变化。本仓库针对特定版本的 workflow 工具语义编写,见下文[兼容性](#兼容性)。
|
|
15
19
|
|
|
16
20
|
---
|
|
17
21
|
|
|
18
22
|
## 能做什么
|
|
19
23
|
|
|
20
|
-
- 书籍(PDF/EPUB/MOBI)、论文(arXiv/PDF/HTML
|
|
24
|
+
- 书籍(PDF/EPUB/MOBI)、论文(arXiv/PDF/HTML)、视频(**字幕优先,无字幕自动转写**,出品完整逐字稿精读)、网页
|
|
21
25
|
- 长内容分块后由并行子代理精读,再合并
|
|
22
26
|
- 各子任务的输出用 JSON Schema 约束,不合格自动重试
|
|
23
27
|
- 关键引用必须标注页码/章节/段落,降低编造风险
|
|
@@ -53,7 +57,7 @@ Obsidian 笔记
|
|
|
53
57
|
parsers/ 各输入类型的解析器,按类型分发
|
|
54
58
|
book.js 书籍:PDF/EPUB/MOBI 文本提取、章节分块
|
|
55
59
|
paper.js 论文:arXiv/PDF/HTML 结构识别
|
|
56
|
-
video.js
|
|
60
|
+
video.js 视频:完整逐字稿(字幕优先,无字幕自动转写,走 scripts/transcribe.ps1)
|
|
57
61
|
web.js 网页:正文提取
|
|
58
62
|
index.js 注册表:解析器发现与回退
|
|
59
63
|
schemas/ 子任务输出的 JSON Schema
|
|
@@ -83,7 +87,7 @@ deep-read-summarize 是 DSH 插件,可通过 npm、dsh.so 生态或本地安
|
|
|
83
87
|
npm install deep-read-summarize
|
|
84
88
|
|
|
85
89
|
# 或本地安装(dsh profile 目录)
|
|
86
|
-
pnpm add ./deep-read-summarize-0.3.
|
|
90
|
+
pnpm add ./deep-read-summarize-0.3.6.tgz
|
|
87
91
|
# 然后在 dsh 配置的 dsh.profile.bundles 追加:
|
|
88
92
|
# - deep-read-summarize
|
|
89
93
|
# 重启 dsh web 即可(POST /dsh-market/restart)
|
|
@@ -152,7 +156,8 @@ parsers: book, paper, video, web
|
|
|
152
156
|
"options": {
|
|
153
157
|
"minWords": 2500,
|
|
154
158
|
"fastMode": false, // true 时跳过 5-7 节,速度快一些
|
|
155
|
-
"maxChunks":
|
|
159
|
+
"maxChunks": 4, // 分块上限,1-12(默认调低,控制子代理数与耗时)
|
|
160
|
+
"transcribe": true, // 视频:无字幕时自动本地转写(faster-whisper);false 则跳过转写,见「视频」节
|
|
156
161
|
"requireCitations": true, // 关键结论是否必须标注出处
|
|
157
162
|
"includeTimestamps": false,
|
|
158
163
|
"outputDir": "./output", // 笔记输出目录(可指向 Obsidian 仓库)
|
|
@@ -172,7 +177,58 @@ parsers: book, paper, video, web
|
|
|
172
177
|
|
|
173
178
|
笔记写到 `options.outputDir` 指定的目录(默认 `./output`,可指向你的 Obsidian 仓库),文件名取自内容标题。
|
|
174
179
|
|
|
175
|
-
|
|
180
|
+
### 视频:完整逐字稿(字幕优先,无字幕自动转写)
|
|
181
|
+
|
|
182
|
+
视频取文本是**统一流水线**(已去掉「三档」):目标 = 拿到**完整逐字稿**再精读。
|
|
183
|
+
|
|
184
|
+
> **⚠️ 为保证精读质量,处理时间可能略长(刻意取舍,不是卡死)**:**无字幕**视频会先做一次转写(CPU 上约为视频时长的 0.5–2×)再精读,所以这类视频整体会**明显比有字幕视频慢**;换来的是**完整逐字稿 + 真正的精读**。**有字幕**视频仍是秒级。请勿把转写的较慢误判为卡死。
|
|
185
|
+
|
|
186
|
+
1. **有平台字幕**(B站官方 API 的 AI 字幕 / YouTube CC)→ **直接用字幕**(=全文,最快、零依赖)。
|
|
187
|
+
2. **无公开字幕** → 用插件自带转写 `scripts/transcribe.ps1`(faster-whisper small / int8 / VAD / 中文)得到全文。
|
|
188
|
+
3. 都不行 → **降级**:提示手动提供转写文本,或退回 `desc` 作背景;**绝不阻塞**。
|
|
189
|
+
|
|
190
|
+
`options.transcribe`:**默认 `true`**(无字幕自动转写);设为 `false` 则跳过转写(只用字幕/desc 或降级)。
|
|
191
|
+
|
|
192
|
+
**转写工具链(本机/用户一致)**:脚本**自举**——用 `uv` 建 **Python 3.12** 环境 + **清华镜像**装 `faster-whisper` + `HF_ENDPOINT=https://hf-mirror.com` 下模型并**缓存复用**;faster-whisper 内置 PyAV 解码音频,**无需单独 ffmpeg**;**版本已锁定**(Python 3.12 / faster-whisper / uv),保证本机与用户环境一致。
|
|
193
|
+
|
|
194
|
+
> ⚠️ **首次转写会先下载模型(small 约 484MB,走 hf-mirror,非 GitHub),可能需要几分钟**,请耐心等待;**本机只下这一次**,之后所有视频转写用缓存、秒开。**只有「无字幕」视频才会触发转写**(有字幕的视频直接用字幕,不触发、不下载)。
|
|
195
|
+
|
|
196
|
+
**质量/速度**:`small` + `int8` 量化 + `VAD` 静音过滤,中文质量可用且 CPU 友好。**有字幕的视频不转写(快)**;无字幕视频转写,CPU 上约为视频时长的 0.5–2×。
|
|
197
|
+
|
|
198
|
+
**失败处理**:安装/下载失败则**明确报错并降级**(提示手动提供转写文本),不静默、不长期阻塞。此时可用 `options.transcribe: false` 跳过转写。
|
|
199
|
+
|
|
200
|
+
**怎么知道本次用了什么来源**:来源信息**不写进笔记**(保证笔记干净),透出在:① 运行日志的 `[source] <值> -> <标签>` 行;② 返回结果里的 `textSource` 字段(`subtitle / transcription / desc / manual`)。
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## 差异与影响因素(时长与内容为何可能不同)
|
|
205
|
+
|
|
206
|
+
**输出时长与内容会因「模型」和「输入」不同而有明显差异,属正常现象**,请知悉:
|
|
207
|
+
|
|
208
|
+
### 模型
|
|
209
|
+
- **ASR 模型档位**:`small`(默认,中文可用)→ `base`(更快、质量略降)→ `medium`(更好、更慢)。可用 `options.whisperModel` 调整;下载量与速度随模型变大而增长。
|
|
210
|
+
- **语言/口音**:中/英/混合语言、方言、口音、重音 → 转写**准确度与耗时不同**;纯英文视频可设 `language: "en"`。
|
|
211
|
+
- **精读 LLM**:用宿主 DSH 的模型,不同上下文/推理模型 → 输出**质量、篇幅、速度**不同。
|
|
212
|
+
- **非确定性**:LLM 与 ASR 均带随机性,**同一输入重复跑可能得到略有差异**的结果(内容/篇幅)。
|
|
213
|
+
|
|
214
|
+
### 输入
|
|
215
|
+
- **视频**:
|
|
216
|
+
- 有无**公开字幕**是最大差异点——有公开字幕 = 秒级;只有登录态 AI 字幕/无字幕 = 触发转写,**明显变慢**。
|
|
217
|
+
- **时长**:越长转写越久(CPU 约 0.5–2× 视频时长)。
|
|
218
|
+
- **音质/噪杂/低音量/纯 BGM/无人声**:转写易错或**结果空**,此时请手动提供转写文本。
|
|
219
|
+
- **论文/书籍/网页**:
|
|
220
|
+
- 格式:PDF/EPUB/MOBI/HTML/arXiv;**扫描版 OCR、坏 PDF、公式/图表密集** → 提取质量与耗时不同。
|
|
221
|
+
- **术语密度/篇幅** → 分块数与精读深度不同。
|
|
222
|
+
- **分块结构**:不同类型分块方式不同(章节/主题/段落),影响**输出结构**与覆盖。
|
|
223
|
+
|
|
224
|
+
### 硬件
|
|
225
|
+
- **GPU vs CPU**:GPU 转写可比 CPU 快一个数量级(`device='auto'` 自动选)。CPU 上无字幕视频约 0.5–2× 时长。
|
|
226
|
+
|
|
227
|
+
### 其他
|
|
228
|
+
- **首次 vs 复用**:首次要下模型(约 484MB),之后缓存复用。
|
|
229
|
+
- **Token/成本**:分块数/篇幅/引证决定 token 消耗;`fastMode`/`maxChunks` 可省。
|
|
230
|
+
- **引用/编造**:转写或 OCR 的错词可能被当作「原文」引用,**关键引用请复核**。
|
|
231
|
+
- **边界**:纯 BGM、失真音频 → 转写空/差;无字幕且转写不可用 → 降级提示人工提供转写文本。
|
|
176
232
|
|
|
177
233
|
---
|
|
178
234
|
|
|
@@ -195,6 +251,7 @@ parsers: book, paper, video, web
|
|
|
195
251
|
|
|
196
252
|
- 抓取视频/网页会发起外部请求,由子代理在 DSH 的沙箱和审批策略下执行;不要让模型无人值守地跑任意脚本。
|
|
197
253
|
- 子代理写文件需要相应权限;如果权限不够,workflow 会把内容返回,由主代理负责落盘。
|
|
254
|
+
- **本地转写**:视频转写(faster-whisper)在**本机**运行,音频/字幕**不出本地**;抓取视频元数据/字幕/音频时才会向对应平台发起网络请求。
|
|
198
255
|
- 这个仓库只有流程本身:workflow 定义、解析器代码、提示词模板、schema。**不含任何受版权保护内容的提取结果。** 测试用的 fixture 是自写的公共领域寓言。用本工作流处理有版权的材料时,产出物的使用责任在你。
|
|
199
256
|
|
|
200
257
|
---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deep-read-summarize",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Deep reading & summarization for DSH: books/papers/videos/web → structured Obsidian notes. Plugin parsers, MapReduce deep-read, JSON Schema output, idempotent cache.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "index.js",
|
package/parsers/video.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
// ============================================================================
|
|
2
|
-
// Parser plugin: video (YouTube
|
|
2
|
+
// Parser plugin: video (Bilibili/Douyin/YouTube → transcript & metadata)
|
|
3
3
|
// ============================================================================
|
|
4
|
-
//
|
|
5
|
-
//
|
|
4
|
+
// 统一流水线(去掉三档):目标 = 拿到完整逐字稿再精读。
|
|
5
|
+
// ① 有平台字幕(B站 AI 字幕 / YouTube CC)→ 直接用字幕(=全文,最快、零依赖)
|
|
6
|
+
// ② 无公开字幕 → 用插件自带转写(faster-whisper small/int8/VAD,镜像+缓存)得到全文
|
|
7
|
+
// ③ 都不行 → 降级(提示人工提供转写文本,或退回 desc 作背景)。
|
|
8
|
+
// 本机/用户使用一致:只依赖环境变量 + 相对/标准路径,不写死本机绝对路径。
|
|
9
|
+
// 提示词骨架复用 parsers/_prompt.js,此处只提供差异化配置。
|
|
6
10
|
// ============================================================================
|
|
7
11
|
|
|
8
12
|
const prompt = require("./_prompt");
|
|
@@ -10,22 +14,41 @@ const prompt = require("./_prompt");
|
|
|
10
14
|
module.exports = {
|
|
11
15
|
name: "video",
|
|
12
16
|
types: ["video"],
|
|
13
|
-
description: "视频解析器(YouTube
|
|
17
|
+
description: "视频解析器(B站/抖音/YouTube → 完整逐字稿,字幕优先,无字幕自动转写)",
|
|
14
18
|
|
|
15
19
|
buildPrompt: function (input, opts) {
|
|
16
20
|
const tempDir = (opts && opts.tempDir) || "./.tmp";
|
|
21
|
+
const wantTranscribe = opts.transcribe !== false; // 默认 true:无字幕时自动走本地转写
|
|
22
|
+
const degradeMsg = "需要人工提供转写文本或视频文案";
|
|
23
|
+
const steps = [
|
|
24
|
+
"记录文本来源(metadata.textSource):subtitle(平台字幕)/ transcription(本地转写)/ desc(仅简介,作为降级/背景)/ manual(用户提供)。",
|
|
25
|
+
"统一流程:① 先取视频字幕(B站 AI 字幕 / YouTube yt-dlp CC);② 若**无公开字幕**,用插件自带 faster-whisper 转写得到全文;③ 仍不可行才降级(提示人工提供转写文本 或 退回 desc 作背景)。",
|
|
26
|
+
"若输入是 B 站链接(bilibili.com / b23.tv,短链先用 curl -L 跟随重定向提取 BV 号):用 curl(Windows 自带,零安装)调官方公开 API:\n" +
|
|
27
|
+
" 1) 元数据+简介:curl 'https://api.bilibili.com/x/web-interface/view?bvid=<BV>' → 取 title / desc(简介仅作背景/补充,不满一篇精读)/ owner.name / duration / aid / cid\n" +
|
|
28
|
+
" 2) 字幕(**优先,最快**):curl 'https://api.bilibili.com/x/player/v2?aid=<aid>&cid=<cid>' 取 subtitle 列表;若有则下载转文本(textSource=subtitle)——这已是完整逐字稿,直接使用\n" +
|
|
29
|
+
" 3) 无公开字幕时(textSource=transcription):按下方「转写执行」用 faster-whisper 转写整段音频,得到完整全文。",
|
|
30
|
+
|
|
31
|
+
"若输入是抖音链接/分享口令(douyin.com / v.douyin.com):用户分享时复制的文字本身就是该视频的文案(desc)。desc 较完整时可直接作为文本(textSource=desc);若 desc 太短,仍按下方「转写执行」转写(textSource=transcription)。",
|
|
32
|
+
"若输入是 YouTube 等其他平台:先探测是否已装 yt-dlp(pwsh 运行 `yt-dlp --version`)。若未安装:绝对不要去下载 yt-dlp 二进制(GitHub 直连在部分网络下极慢且易中断,会卡死整个流程);先试 `winget install yt-dlp.yt-dlp`,再试 `pip install -U yt-dlp -i https://pypi.tuna.tsinghua.edu.cn/simple`;仍不可用则按下方「转写执行」直接转写或降级。已安装时用 yt-dlp 抓字幕(CC)转文本;无 CC 则转写。",
|
|
33
|
+
|
|
34
|
+
"转写执行(faster-whisper small/int8/中文,镜像+缓存,保证本机与用户一致):",
|
|
35
|
+
" ① 先取音频:B站用 playurl(curl 'https://api.bilibili.com/x/player/playurl?avid=<aid>&cid=<cid>&fnval=16&fourk=1' 的 dash.audio[0].baseUrl)或 yt-dlp,下载存到 '" + tempDir + "/audio.m4a';\n" +
|
|
36
|
+
" ② 定位插件转写脚本:用 Get-ChildItem -Path $env:USERPROFILE/.dsh -Recurse -Filter transcribe.ps1(或 glob 搜 *transcribe.ps1)找到 <脚本路径>;\n" +
|
|
37
|
+
" ③ 运行:pwsh <脚本路径> -Audio '" + tempDir + "/audio.m4a' -Out '" + tempDir + "/transcript.txt' -Model small -Language zh;\n" +
|
|
38
|
+
" ④ 转写可能较慢:用 pwsh(run_in_background: true)启动后,轮询输出文件 '" + tempDir + "/transcript.txt' 是否写出内容(非空且稳定),或日志出现 DONE;设合理超时,超时/失败则降级;\n" +
|
|
39
|
+
" ⑤ 成功后读取 transcript.txt 作为全文(textSource=transcription)。脚本自举:uv 建 Python 3.12 环境 + 镜像装 faster-whisper + hf-mirror 下模型并缓存。**⚠️ 首次转写会先下载 small 模型(约 484MB,hf-mirror)并较慢——先向用户说明这是正常的一次性下载,勿当成卡死;之后缓存复用、秒开。**",
|
|
40
|
+
|
|
41
|
+
"若以上均不可用或抓取失败:输出 { \"saved\": false, \"message\": \"" + degradeMsg + "\" }。"
|
|
42
|
+
];
|
|
43
|
+
|
|
17
44
|
return prompt.buildFetchPrompt({
|
|
18
45
|
input: input,
|
|
19
46
|
opts: opts,
|
|
20
|
-
fetchTarget: "
|
|
47
|
+
fetchTarget: "视频完整逐字稿(字幕优先,无字幕自动转写)",
|
|
21
48
|
kindLabel: "视频(video)",
|
|
22
|
-
steps:
|
|
23
|
-
"用 pwsh 运行 yt-dlp 抓字幕,命令示例:\n yt-dlp --skip-download --write-auto-sub --write-subs --sub-langs 'zh,en' --sub-format vtt/srt -o '" + tempDir + "/sub.%(ext)s' <URL>",
|
|
24
|
-
"读取字幕文件(vtt/srt),去除时间戳与 HTML 标签,转为纯文本写入目标文件。",
|
|
25
|
-
"若 yt-dlp 不可用或抓取失败:输出 { \"saved\": false, \"message\": \"需要人工提供转写文本\" }。"
|
|
26
|
-
],
|
|
49
|
+
steps: steps,
|
|
27
50
|
chunkRule: "主题脉络(而非时间)",
|
|
28
|
-
jsonExample: '{ "kind": "video", "saved": true, "totalLines": N, "metadata": { "title": "", "author": "", "year": "", "language": "zh|en" }, "chunkPlan": [ { "id": 1, "topic": "主题段", "startLine": 1, "endLine": 200 } ] }'
|
|
51
|
+
jsonExample: '{ "kind": "video", "saved": true, "totalLines": N, "metadata": { "title": "", "author": "", "year": "", "language": "zh|en", "textSource": "subtitle|transcription|desc|manual" }, "chunkPlan": [ { "id": 1, "topic": "主题段", "startLine": 1, "endLine": 200 } ] }'
|
|
29
52
|
});
|
|
30
53
|
}
|
|
31
|
-
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# transcribe.ps1 - faster-whisper transcription bootstrap (plugin-internal, self-bootstrapping)
|
|
2
|
+
# Usage: pwsh transcribe.ps1 -Audio <file> -Out <txt> [-Model small] [-Language zh]
|
|
3
|
+
# Deterministic per-user cache so behavior is identical on dev & user machines.
|
|
4
|
+
param(
|
|
5
|
+
[Parameter(Mandatory=$true)][string]$Audio,
|
|
6
|
+
[Parameter(Mandatory=$true)][string]$Out,
|
|
7
|
+
[string]$Model = 'small',
|
|
8
|
+
[string]$Language = 'zh'
|
|
9
|
+
)
|
|
10
|
+
$ErrorActionPreference = 'Stop'
|
|
11
|
+
|
|
12
|
+
$cacheRoot = Join-Path $env:LOCALAPPDATA 'deep-read-summarize'
|
|
13
|
+
$venvDir = Join-Path $cacheRoot 'venv'
|
|
14
|
+
$venvPy = Join-Path $venvDir 'Scripts/python.exe'
|
|
15
|
+
$hfHome = Join-Path $cacheRoot 'hf'
|
|
16
|
+
$pyScript = Join-Path $cacheRoot 'transcribe_run.py'
|
|
17
|
+
|
|
18
|
+
New-Item -ItemType Directory -Force -Path $cacheRoot | Out-Null
|
|
19
|
+
|
|
20
|
+
$uv = $null
|
|
21
|
+
$uvCmd = Get-Command uv -ErrorAction SilentlyContinue
|
|
22
|
+
if ($uvCmd) { $uv = $uvCmd.Source }
|
|
23
|
+
else { $alt = Join-Path $HOME '.local/bin/uv.exe'; if (Test-Path $alt) { $uv = $alt } }
|
|
24
|
+
if (-not $uv) { throw 'uv not found. Please install uv (winget install astral-sh.uv) or ensure it is on PATH.' }
|
|
25
|
+
|
|
26
|
+
# Use a China mirror for CPython download (uv pulls python-build-standalone from GitHub, slow in CN),
|
|
27
|
+
# and prefer an already-installed 3.12 (avoids the download entirely on many machines).
|
|
28
|
+
$env:UV_PYTHON_INSTALL_MIRROR = 'https://ghproxy.com/https://github.com/astral-sh/python-build-standalone/releases/download'
|
|
29
|
+
|
|
30
|
+
if (-not (Test-Path $venvPy)) {
|
|
31
|
+
# reuse an existing python 3.12 if present; else uv installs 3.12 (via mirror)
|
|
32
|
+
$usePy = (py -0p 2>$null | Select-String '3.12' | Select-Object -First 1)
|
|
33
|
+
if ($usePy) { $pyArg = '3.12' } else { $pyArg = '3.12' }
|
|
34
|
+
& $uv venv --python $pyArg $venvDir
|
|
35
|
+
if ($LASTEXITCODE -ne 0) { throw 'uv venv creation failed.' }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
& $venvPy -c 'import faster_whisper' 2>$null
|
|
39
|
+
if ($LASTEXITCODE -ne 0) {
|
|
40
|
+
& $uv pip install --python $venvPy faster-whisper -i https://pypi.tuna.tsinghua.edu.cn/simple
|
|
41
|
+
if ($LASTEXITCODE -ne 0) { throw 'faster-whisper install failed (mirror unreachable?).' }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
$env:HF_ENDPOINT = 'https://hf-mirror.com'
|
|
45
|
+
$env:HF_HOME = $hfHome
|
|
46
|
+
# Disable the hf-xet backend: it bypasses the mirror (cas-server.xethub.hf.co) and 401s; the mirror works over plain HTTP.
|
|
47
|
+
$env:HF_HUB_DISABLE_XET = '1'
|
|
48
|
+
$env:HF_HUB_DISABLE_SYMLINKS_WARNING = '1'
|
|
49
|
+
$env:DRS_AUDIO = $Audio
|
|
50
|
+
$env:DRS_OUT = $Out
|
|
51
|
+
$env:DRS_MODEL = $Model
|
|
52
|
+
$env:DRS_LANG = $Language
|
|
53
|
+
|
|
54
|
+
$py = @'
|
|
55
|
+
import os
|
|
56
|
+
from faster_whisper import WhisperModel
|
|
57
|
+
m = WhisperModel(os.environ['DRS_MODEL'], device='auto', compute_type='int8')
|
|
58
|
+
segs, info = m.transcribe(os.environ['DRS_AUDIO'], vad_filter=True, language=(os.environ.get('DRS_LANG') or None))
|
|
59
|
+
with open(os.environ['DRS_OUT'], 'w', encoding='utf-8') as f:
|
|
60
|
+
for s in segs:
|
|
61
|
+
f.write(s.text.strip() + ' ')
|
|
62
|
+
print('DONE', info.language, round(info.duration, 1))
|
|
63
|
+
'@
|
|
64
|
+
[System.IO.File]::WriteAllText($pyScript, $py, (New-Object System.Text.UTF8Encoding($false)))
|
|
65
|
+
|
|
66
|
+
& $venvPy $pyScript
|
|
67
|
+
if ($LASTEXITCODE -ne 0) { throw 'transcription failed.' }
|
|
68
|
+
Write-Output ('TRANSCRIBED ' + (Get-Item $Out).Length + ' bytes to ' + $Out)
|
|
@@ -59,8 +59,16 @@ status: 已完成
|
|
|
59
59
|
|
|
60
60
|
## 视频说明
|
|
61
61
|
|
|
62
|
-
-
|
|
63
|
-
-
|
|
62
|
+
- **统一流水线(去三档)**:目标 = 拿到完整逐字稿再精读。
|
|
63
|
+
1. **有平台字幕**(B站 AI 字幕 / YouTube CC / yt-dlp CC)→ 直接用字幕(=全文,最快、零依赖)。
|
|
64
|
+
2. **无公开字幕** → 用插件自带转写(`scripts/transcribe.ps1`:faster-whisper small / int8 / VAD)得到全文。
|
|
65
|
+
3. 都不行 → 降级提示用户手动提供转写文本,或退回 desc 作背景;**绝不阻塞、绝不自动装重依赖**。
|
|
66
|
+
- `options.transcribe`:**默认 true**(无字幕自动转写);设为 `false` 则跳过转写(只用字幕/desc 或降级)。
|
|
67
|
+
- **转写工具链**:脚本自举,本机/用户一致——`uv` 建 Python 3.12 环境 + 清华镜像装 `faster-whisper` + `HF_ENDPOINT=https://hf-mirror.com` 下模型并缓存;faster-whisper 内置 PyAV 解码音频,**无需单独 ffmpeg**。
|
|
68
|
+
- **⚠️ 首次转写会先下载 small 模型(约 484MB,hf-mirror,非 GitHub),可能较慢**——执行转写前**先向用户说明**这是正常的一次性下载,之后缓存复用、秒开;不要当成卡死而中断。
|
|
69
|
+
- **质量/速度**:small/int8 + VAD 静音过滤,中文质量可用且 CPU 友好;有字幕视频不转写(快)。装不上/失败则降级,不静默。
|
|
70
|
+
- YouTube 用 yt-dlp 抓 CC;未装时**绝不下载 exe 二进制**(GitHub 直连易卡死),改用 winget/pip;仍不可用则转写或降级。
|
|
71
|
+
- 运行 yt-dlp 加 `--socket-timeout 15 --retries 3` 防超时。
|
|
64
72
|
- 默认不标时间戳(`options.includeTimestamps` 可开)
|
|
65
73
|
|
|
66
74
|
## 参考
|
package/workflow.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Version: 3.0.0
|
|
4
4
|
// ============================================================================
|
|
5
5
|
// 【用法】meta → workflow meta;script → workflow script;
|
|
6
|
-
// args: { "input": "<url|path>", "type": "auto", "options": { "minWords": 2500, "fastMode": false, "maxChunks":
|
|
6
|
+
// args: { "input": "<url|path>", "type": "auto", "options": { "minWords": 2500, "fastMode": false, "maxChunks": 4, "transcribe": true, "requireCitations": true, "includeTimestamps": false, "cache": true, "outputDir": "./output", "tempDir": "./.tmp" } }
|
|
7
7
|
// ============================================================================
|
|
8
8
|
|
|
9
9
|
const meta = {
|
|
@@ -35,7 +35,7 @@ const meta = {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
// ===== script(复制到 workflow 工具的 script 参数)=====
|
|
38
|
-
const RAW_SCRIPT = "// ========== deep-read-summarize v3.0 ==========\n// 3 波次:解析器获取分块 → 并行精读 → 成稿+质量校验\n// 特性:解析器插件化 / 失败纪律(fatal vs 降级) / 幂等 / 成本控制\n\n// ---------- 0. 配置校验(fatal 级错误:必须终止) ----------\nconst input = (args && args.input || \"\").trim();\nif (!input) throw new Error(\"[FATAL] args.input 缺失:请输入内容链接或文件路径\");\nconst forcedType = ((args && args.type) || \"auto\").toLowerCase();\nif ([\"auto\",\"book\",\"paper\",\"video\",\"web\"].indexOf(forcedType) === -1)\n throw new Error(\"[FATAL] args.type 非法:必须为 auto|book|paper|video|web\");\nconst options = (args && args.options) || {};\nconst minWords = options.minWords || 2500;\nconst fastMode = !!options.fastMode;\nconst maxChunks = Math.max(1, Math.min(options.maxChunks ||
|
|
38
|
+
const RAW_SCRIPT = "// ========== deep-read-summarize v3.0 ==========\n// 3 波次:解析器获取分块 → 并行精读 → 成稿+质量校验\n// 特性:解析器插件化 / 失败纪律(fatal vs 降级) / 幂等 / 成本控制\n\n// ---------- 0. 配置校验(fatal 级错误:必须终止) ----------\nconst input = (args && args.input || \"\").trim();\nif (!input) throw new Error(\"[FATAL] args.input 缺失:请输入内容链接或文件路径\");\nconst forcedType = ((args && args.type) || \"auto\").toLowerCase();\nif ([\"auto\",\"book\",\"paper\",\"video\",\"web\"].indexOf(forcedType) === -1)\n throw new Error(\"[FATAL] args.type 非法:必须为 auto|book|paper|video|web\");\nconst options = (args && args.options) || {};\nconst minWords = options.minWords || 2500;\nconst fastMode = !!options.fastMode;\nconst maxChunks = Math.max(1, Math.min(options.maxChunks || 4, 12));\nconst requireCitations = options.requireCitations !== false;\nconst includeTimestamps = !!options.includeTimestamps;\nconst maxRetries = options.maxRetries || 0;\nconst cacheEnabled = options.cache !== false;\nconst outputDir = options.outputDir || \"./output\";\nconst tempDir = options.tempDir || \"./.tmp\";\nconst tempFile = tempDir.replace(/[\\/]+$/, \"\") + \"/input.txt\";\n\n// ---------- 0.5 幂等检查:输入指纹缓存 ----------\nlet cacheHit = false;\nif (cacheEnabled && Array.isArray(args._processedKeys)) {\n const fpKey = input.trim().slice(0, 300);\n cacheHit = args._processedKeys.indexOf(fpKey) !== -1;\n if (cacheHit) log(\"幂等命中:该输入已处理过,跳过\");\n}\nif (cacheHit) {\n return { ok: true, cached: true, kind: forcedType, title: (args && args.title) || \"cached\", filePath: \"\", chunksCount: 0, fastMode: fastMode, qualityPassed: true, qualityIssues: [], failedChunks: 0, note: \"\" };\n}\n\n// ---------- 1. 解析器选择(由 args._parsers 注入) ----------\nphase(\"解析器选择\");\nconst parsers = args._parsers || {};\nconst kindNames = { book: \"书籍\", paper: \"学术论文\", video: \"视频\", web: \"网页/文章\" };\nconst kindFocus = {\n book: \"按章节主题展开核心论点、论证、关键例子、章节间关系,收集关键概念与可引用原文(含页码/章节)\",\n paper: \"四维精读:1)研究问题与方法 2)结论与贡献 3)局限与批判 4)与同类工作比较;收集术语与可引用原文(含章节/段落)\",\n video: \"按主题脉络组织,提取核心论点、证据、例子、可操作建议,收集关键概念与主讲人原话\" + (includeTimestamps ? \"(含时间戳定位)\" : \"(不标时间戳)\"),\n web: \"提取核心论点、结构拆解、关键概念、可引用原文\"\n};\n\n// ---------- 2. 波次1:解析器获取 + 分块 ----------\nphase(\"获取与分块\");\nconst fetchPrompt = (parsers[forcedType !== \"auto\" ? forcedType : \"web\"] || parsers.web || { buildPrompt: function() { return [\"未知解析器\"]; } })\n .buildPrompt(input, { tempDir: tempDir, tempFile: tempFile, maxChunks: maxChunks, transcribe: options.transcribe !== false });\nconst fetchSchema = {\n type: \"object\",\n properties: {\n kind: { type: \"string\" }, saved: { type: \"boolean\" }, message: { type: \"string\" }, totalLines: { type: \"number\" },\n metadata: { type: \"object\", properties: { title: { type: \"string\" }, author: { type: \"string\" }, year: { type: \"string\" }, language: { type: \"string\" } }, required: [], additionalProperties: true },\n chunkPlan: {\n type: \"array\",\n items: { type: \"object\", properties: { id: { type: \"number\" }, topic: { type: \"string\" }, startLine: { type: \"number\" }, endLine: { type: \"number\" } }, required: [\"id\",\"topic\",\"startLine\",\"endLine\"], additionalProperties: false }\n }\n },\n required: [\"saved\"], additionalProperties: false\n};\n\nconst fetched = await agent(fetchPrompt, { schema: fetchSchema, label: \"获取+分块\", phase: \"获取与分块\" });\n\n// 失败纪律:内容获取失败 = 可降级错误(返回失败结果,不抛 fatal)\nif (!fetched || !fetched.saved) {\n return { ok: false, stage: \"fetch\", fatal: false, message: (fetched && fetched.message) || \"获取失败(可降级:检查输入或手动提供文本)\" };\n}\nlet kind = (fetched.kind && forcedType === \"auto\") ? fetched.kind : forcedType;\nconst chunkPlan = (fetched && fetched.chunkPlan) || [];\nif (chunkPlan.length === 0) return { ok: false, stage: \"fetch\", fatal: false, message: \"分块计划为空\" };\nconst metadata = (fetched && fetched.metadata) || {};\nconst textSource = (metadata && metadata.textSource) || \"unknown\";\nconst srcLabels = { desc: \"视频简介/desc\", subtitle: \"平台字幕\", transcription: \"完整语音转写\", manual: \"用户提供转写文本\" };\nconst srcLabel = srcLabels[textSource] || textSource;\nlog(\"[source] \" + textSource + \" -> \" + srcLabel);\nlog(\"类型:\" + kind + \" 行数:\" + fetched.totalLines + \" 块数:\" + chunkPlan.length);\n\n// ---------- 3. 波次2:并行精读(Map) ----------\nphase(\"并行精读\");\nconst chunkPrompts = chunkPlan.map(function (c) {\n return [\n \"请深度精读以下内容块,输出结构化精读笔记。\",\n \"内容类型:\" + (kindNames[kind] || kind) + \" | 本块主题:\" + c.topic,\n \"精读侧重:\" + (kindFocus[kind] || kindFocus.web),\n \"用 read 工具读取 \" + tempFile + \" 第 \" + c.startLine + \" 到 \" + c.endLine + \" 行(offset=\" + c.startLine + \", limit=\" + (c.endLine - c.startLine + 1) + \"),然后输出:\",\n \"## 本块主题:\" + c.topic,\n \"### 要点(详细展开,保留数据/例子/论证)\",\n \"### 关键概念(术语+解释)\",\n \"### 关键引用(最多2句原文+位置)\" + (requireCitations ? \",必须标注页码/章节/段落位置\" : \"\"),\n \"### 批判观察(如有)\"\n ].join(\"\\n\");\n});\n\nconst reads = [];\nconst readBatch = 3;\nfor (let bi = 0; bi < chunkPrompts.length; bi += readBatch) {\n const batch = chunkPrompts.slice(bi, bi + readBatch);\n const batchReads = await parallel(batch.map(function (p) {\n return function () { return agent(p, { label: \"精读块\", phase: \"并行精读\" }); };\n }));\n for (let k = 0; k < batchReads.length; k++) reads.push(batchReads[k]);\n}\nconst validReads = reads.filter(function (r) { return r && r.trim && r.trim().length > 0; });\n\n// 失败纪律:某块精读失败 = 可降级(跳过该块,标记缺口继续)\nconst failedChunks = chunkPlan.length - validReads.length;\nif (validReads.length === 0) return { ok: false, stage: \"read\", fatal: false, message: \"所有分块精读均失败\" };\nif (failedChunks > 0) log(\"警告:\" + failedChunks + \" 块精读失败,标记缺口继续成稿\");\nlog(\"精读完成:\" + validReads.length + \"/\" + chunkPlan.length);\n\n// ---------- 4. 波次3:成稿 + 内嵌质量自检(Reduce) ----------\nphase(\"汇总成稿\");\nconst today = new Date().toISOString().slice(0, 10);\nconst finalTitle = metadata.title || \"未命名内容\";\nconst safeTitle = finalTitle.replace(/[\\\\/:*?\"<>|]/g, \" \").trim();\nconst mdPath = outputDir.replace(/\\\\$/, \"\") + \"/\" + safeTitle + \".md\";\n\nconst extraSections = fastMode ? [] : [\n \"\", \"## 5. 批判性分析(论证强处/弱处/可质疑之处)\", \"\",\n \"## 6. 个人思考与应用(与已有知识联系、如何应用、行动要点)\", \"\",\n \"## 7. 延伸阅读(相关主题/作者其他作品/参考文献)\", \"\"\n];\n\nconst draftPrompt = [\n \"将以下多块精读结果整合为完整 Obsidian 精读笔记,只输出 Markdown(含 YAML frontmatter)。\",\n \"模板:\", \"---\",\n 'title: \"《' + finalTitle + '》深度精读笔记\"',\n \"aliases: [\" + JSON.stringify(finalTitle) + \"]\",\n \"author: \" + (metadata.author || \"\"),\n \"year: \" + (metadata.year || \"\"),\n \"type: \" + kind,\n \"url: \" + (metadata.url || input),\n \"tags: [精读, \" + (kindNames[kind] || kind) + \"]\",\n \"created: \" + today,\n \"status: 已完成\",\n \"---\",\n \"# 《\" + finalTitle + \"》深度精读笔记\", \"\",\n \"> 一句话核心概括。\", \"\",\n \"## 1. 概述(约500字:主题/背景/核心问题/总体结论)\", \"\",\n \"## 2. 结构拆解(按主题组织,含详细要点;关键结论标注原文出处)\", \"\",\n \"## 3. 关键概念与术语表(表格)\", \"\",\n \"## 4. 关键引用(仅关键结论\" + (requireCitations ? \",必须标注页码/章节/段落\" : \"\") + \")\",\n].concat(extraSections, [\n \"---\",\n \"*笔记整理于 \" + today + \"*\", \"\",\n \"硬性要求:总篇幅≥\" + minWords + \"字;语言与原文一致;术语统一;引用必须真实;视频\" + (includeTimestamps ? \"标注时间戳\" : \"不标注时间戳\") + \"。\",\n \"输出前自检:1)覆盖所有块 2)frontmatter完整 3)各小节齐全 4)引用真实 5)篇幅达标 6)语言一致。\",\n \"\",\n \"各块精读结果:\",\n validReads.map(function (r, i) { return \"\\\\n===== 块 \" + (i + 1) + \" =====\\\\n\" + r; }).join(\"\\\\n\")\n]).join(\"\\n\");\n\nlet draft = await agent(draftPrompt, { label: \"汇总成稿\", phase: \"汇总成稿\" });\nif (!draft || !draft.trim) return { ok: false, stage: \"draft\", fatal: false, message: \"成稿失败\" };\n\n// ---------- 5. 质量校验(轻量重试) ----------\nphase(\"质量校验\");\nlet verified = draft;\nlet passed = false;\nlet issues = [];\nfor (let round = 0; round <= maxRetries; round++) {\n const checkPrompt = [\n \"请对总结笔记做质量校验,逐项检查并输出 JSON:\",\n \"1.coverage 2.citationsReal 3.terminologyConsistent 4.formatComplete 5.lengthMet(≥\" + minWords + \"字) 6.languageConsistent\",\n \"输出:{ \\\"pass\\\": true/false, \\\"issues\\\": [\\\"问题\\\"] },只输出 JSON。\",\n \"笔记:\", verified\n ].join(\"\\n\");\n const checkSchema = { type: \"object\", properties: { pass: { type: \"boolean\" }, issues: { type: \"array\", items: { type: \"string\" } } }, required: [\"pass\",\"issues\"], additionalProperties: false };\n const check = await agent(checkPrompt, { schema: checkSchema, label: \"质量校验\", phase: \"质量校验\" });\n passed = !!(check && check.pass);\n issues = (check && check.issues) || [];\n log(\"校验:\" + (passed ? \"通过\" : \"发现问题 \" + issues.length + \" 条\"));\n if (passed) break;\n if (round < maxRetries) {\n const fixPrompt = [\n \"修正以下笔记以解决校验问题,输出完整修正版:\",\n issues.map(function (s) { return \"- \" + s; }).join(\"\\n\"),\n \"当前笔记:\", verified\n ].join(\"\\n\");\n verified = await agent(fixPrompt, { label: \"修正笔记\", phase: \"质量校验\" });\n }\n}\n\n// ---------- 结果 ----------\nreturn {\n ok: true, kind: kind, title: finalTitle,\n filePath: mdPath, chunksCount: chunkPlan.length, fastMode: fastMode,\n qualityPassed: passed, qualityIssues: issues,\n failedChunks: failedChunks,\n textSource: textSource,\n note: verified\n};";
|
|
39
39
|
|
|
40
40
|
// ===== parsers 注册表(运行时注入,实现插件化)=====
|
|
41
41
|
const parsers = require("./parsers");
|