deep-read-summarize 0.4.0 → 0.5.0
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 +24 -0
- package/README.en.md +23 -4
- package/README.md +23 -4
- package/SECURITY.md +2 -2
- package/cordis.patch.yml +2 -0
- package/docs/ASR_BENCHMARK.md +46 -0
- package/docs/RELEASE.md +15 -1
- package/lib/options.js +4 -4
- package/lib/parser-bundle.js +11 -1
- package/lib/transcript-cache.js +173 -0
- package/lib/workflow-script.txt +20 -6
- package/package.json +3 -2
- package/parsers/video.js +5 -3
- package/scripts/transcribe.js +107 -13
- package/skills/deep-read-summarize/SKILL.md +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,30 @@
|
|
|
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
|
+
## [Unreleased]
|
|
7
|
+
|
|
8
|
+
## [0.5.0] — 2026-11-01
|
|
9
|
+
|
|
10
|
+
无字幕视频新增逐字稿内容缓存、转写阶段计时和 CPU 线程配置,保留默认精读与原文核验门槛。
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **逐字稿内容缓存**:默认按音频 SHA-256、受管理的本地模型快照、安装环境和固定解码配置复用真实分段;切换时间戳展示无需重复推理。缓存命中仍原子发布本次任务产物,后续精读和独立原文核验不跳过。自定义本地模型、环境不明、损坏/过期记录和失败/空结果不复用。
|
|
15
|
+
- **缓存控制**:`options.transcriptCache`(默认 true);CLI `--no-cache` 禁用读写、`--refresh-cache` 强制推理并更新、`--clear-cache` 仅清理逐字稿。内容保存在本地 `transcripts-v1`,单条最多 8 MiB、总量最多 128 MiB、有效期 30 天;写入时清理。缓存使用本地已有模型快照,不在线探测上游更新,不缓存音频。
|
|
16
|
+
- **CPU 线程配置**:`options.cpuThreads` / `--cpu-threads` 接受 0–64 的整数,默认 0 保持库策略;完整透传到视频转写,默认 small/int8、VAD 与解码参数保持原状。
|
|
17
|
+
- **转写阶段计时**:成功调用输出 `metrics` JSON,分开报告缓存命中、实际设备、音频时长、环境/依赖准备、Python 与发布耗时;未命中时记录导入、模型加载、准备和完整的延迟分段迭代,命中时不复用旧推理计时。
|
|
18
|
+
|
|
19
|
+
### Verification
|
|
20
|
+
|
|
21
|
+
- Windows CPU 对照一段自制 58.439 秒中文语音:原始 runner 24.517 秒,新 runner 强制推理 23.118 秒,命中缓存并开启时间戳 0.098 秒,8 线程且禁用缓存 21.275 秒。默认与 8 线程文本均与原结果逐字一致;缓存切换时间戳后正文一致。单样本结果仅覆盖 ASR,不代表完整精读或其他资料的加速比例。详见 [ASR 基准记录](https://github.com/PensiveFei/deep-read-summarize/blob/v0.5.0/docs/ASR_BENCHMARK.md)。
|
|
22
|
+
- ASR 错词仍可能进入逐字稿;笔记 `qualityPassed` 不等于音轨听写准确。GPU、批量推理和常驻模型未自动启用,仍需独立的音频质量与资源基准。
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- **工作流致命错误**:精读、成稿、原文核验和修订阶段统一传播 `[FATAL]`、`UNSUPPORTED_SCHEMA` 与 `fatal: true` 错误;精读遇到致命错误后停止派发剩余分块。普通临时错误仍保留原有降级行为。
|
|
27
|
+
- **转写环境初始化**:只有 `uv venv` 成功退出且实际生成 Python 解释器文件才继续转写;失败时留下的残缺环境不能跳过直连重试或被误用。
|
|
28
|
+
- **自定义解析器打包**:按 JavaScript 作用域规则分别处理 `switch` 判别式与 `case` 块,避免局部 `require` 隐藏判别式中的模块导入,或局部变量掩盖不可用的宿主 API。
|
|
29
|
+
|
|
6
30
|
## [0.4.0] — 2026-10-25
|
|
7
31
|
|
|
8
32
|
保留完整精读与独立原文核验,减少脚本搬运、并发空等和无效修订,并修复来源质量判断与视频分P等问题。
|
package/README.en.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# deep-read-summarize
|
|
2
2
|
|
|
3
|
+
[English](https://github.com/PensiveFei/deep-read-summarize/blob/main/README.en.md) | [简体中文](https://github.com/PensiveFei/deep-read-summarize/blob/main/README.md)
|
|
4
|
+
|
|
3
5
|
[](https://github.com/PensiveFei/deep-read-summarize/blob/main/LICENSE)
|
|
4
6
|
[](https://github.com/PensiveFei/deep-read-summarize/releases)
|
|
5
7
|
[](https://github.com/PensiveFei/deep-read-summarize/actions/workflows/ci.yml)
|
|
6
|
-
[](https://www.npmjs.com/package/deep-read-summarize)
|
|
7
9
|
|
|
8
10
|
> **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
11
|
|
|
@@ -206,6 +208,8 @@ The `deep_read_summarize` tool takes these parameters directly. On older hosts,
|
|
|
206
208
|
"whisperModel": "small", // video ASR tier: small | base | medium
|
|
207
209
|
"language": "zh", // video ASR language: use "en" for English-only videos
|
|
208
210
|
"device": "cpu", // ASR device: cpu (default) | auto | cuda; auto/cuda needs a CUDA runtime and falls back to cpu
|
|
211
|
+
"cpuThreads": 0, // 0 keeps library defaults; 1-64 allows hardware-specific tuning
|
|
212
|
+
"transcriptCache": true, // reuse a verified local transcript for matching audio and settings
|
|
209
213
|
"maxRetries": 0, // quality-check retries (default 0 = no retry; retrying is noticeably slower)
|
|
210
214
|
"frontmatter": "obsidian", // key set: obsidian (default, for Dataview) | generic (drops the keys Hugo reserves) | minimal
|
|
211
215
|
"requireCitations": true, // whether key conclusions must carry citations
|
|
@@ -268,7 +272,22 @@ Video text extraction is a **unified pipeline** (the old "three tiers" are gone)
|
|
|
268
272
|
|
|
269
273
|
**Transcription toolchain**: `uv` provisions **Python 3.12** and installs **`faster-whisper==1.2.1`** from the Tsinghua mirror; models use `HF_ENDPOINT=https://hf-mirror.com` and the local cache. Healthy cached environments run directly without requiring uv or a separate Python import probe. Actual interpreter and dependency versions are recorded in the cache's `runtime.json`; Python patch releases, uv, and all transitive dependencies are not fully pinned. PyAV decodes audio without a separate ffmpeg. All three platforms use `node scripts/transcribe.js --audio <file> --out <txt>`. CPU is the default; `options.device: "auto"` can try a supplied CUDA runtime and falls back to CPU. Cache roots are `%LOCALAPPDATA%\deep-read-summarize` on Windows, `~/Library/Caches/deep-read-summarize` on macOS, and `$XDG_CACHE_HOME/deep-read-summarize` on Linux (falling back to `~/.cache`). Python provisioning tries a mirror and then direct GitHub; `DRS_UV_PYTHON_MIRROR` overrides it, with an empty value selecting direct downloads.
|
|
270
274
|
|
|
271
|
-
> ⚠️ **The first transcription downloads the model
|
|
275
|
+
> ⚠️ **The first transcription downloads the model (small ≈ 484 MB, via hf-mirror, not GitHub) and may take a few minutes**. Later runs reuse model files; new audio still requires full inference. Only a verified transcript cache hit skips inference. **Only subtitle-less videos trigger transcription** (subtitled videos use their subtitles directly).
|
|
276
|
+
|
|
277
|
+
**Transcript cache and threads**: `options.transcriptCache` defaults to true. Keys include the audio SHA-256, managed local model snapshots, installed dependencies, and decoding settings. Canonical segments retain real start/end times, so changing timestamp presentation does not repeat inference. Changed content/configuration/models/dependencies, custom local model directories, unknown environments, corrupt entries and expired entries bypass reuse. Cache lookup uses the existing local snapshot and does not check for upstream model updates online. Entries live under `transcripts-v1` in the cache root: 8 MiB per entry, 128 MiB total, 30-day validity, pruned on writes. Audio is not stored, and reading/source review still runs.
|
|
278
|
+
|
|
279
|
+
`options.cpuThreads` accepts integers 0–64. The default `0` preserves the library's CPU thread policy. Compare 4/6/8 on the same audio; more threads are not necessarily faster. CLI controls:
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
node scripts/transcribe.js --audio sample.m4a --out transcript.txt --cpu-threads 8
|
|
283
|
+
node scripts/transcribe.js --audio sample.m4a --out transcript.txt --refresh-cache
|
|
284
|
+
node scripts/transcribe.js --audio sample.m4a --out transcript.txt --no-cache
|
|
285
|
+
node scripts/transcribe.js --clear-cache
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
`--clear-cache` removes only transcripts, retaining models and Python. `--refresh-cache` forces inference and updates the cache; `--no-cache` disables reads and writes. Successful calls print one `metrics` JSON line with `cacheHit`, actual device, audio duration, and milliseconds for hashing, environment preparation, dependency installation, Python, publication and total time. Misses also include import, model loading, preparation (including decoding/VAD), and complete lazy-segment iteration. Hits do not reuse previous inference timings.
|
|
289
|
+
|
|
290
|
+
The note's `qualityPassed` checks the note against acquired text; it does not establish ASR accuracy. ASR changes still need audio/reference comparisons for errors, omissions, numbers, negation and timestamps.
|
|
272
291
|
|
|
273
292
|
**Quality/speed**: `small` + `int8` quantization + `VAD` silence filtering gives usable Chinese quality and is CPU-friendly. **Subtitled videos are not transcribed (fast)**; subtitle-less videos are transcribed at roughly 0.5–2× the video length on CPU.
|
|
274
293
|
|
|
@@ -299,7 +318,7 @@ Video text extraction is a **unified pipeline** (the old "three tiers" are gone)
|
|
|
299
318
|
- **Chunking structure**: different types chunk differently (chapter/topic/paragraph), affecting **output structure** and coverage.
|
|
300
319
|
|
|
301
320
|
### Hardware
|
|
302
|
-
- **GPU vs CPU**:
|
|
321
|
+
- **GPU vs CPU**: gains depend on hardware, runtime libraries, model and audio. A visible GPU does not prove CUDA inference works; compare actual time and transcript accuracy.
|
|
303
322
|
|
|
304
323
|
### Other
|
|
305
324
|
- **First run vs reuse**: the first run downloads the model (≈ 484 MB); later runs reuse the cache.
|
|
@@ -326,7 +345,7 @@ Two classes:
|
|
|
326
345
|
- Video `textSource: "desc"` is explicitly degraded and cannot pass as a complete deep read. Bilibili `p` selects the matching CID, part title, and duration.
|
|
327
346
|
- Returned `timings` reports stage durations in milliseconds. Compare the same sources, model, output size, and quality gates; scheduling simulations are not real LLM speedup measurements.
|
|
328
347
|
|
|
329
|
-
|
|
348
|
+
Defaults preserve small/int8, existing decoding settings, output length and independent source review. Transcript caching speeds up repeated audio; new audio can be profiled and tuned with CPU thread settings. Persistent ASR workers, batch inference and hierarchical review require separate benchmarks and are not enabled automatically.
|
|
330
349
|
|
|
331
350
|
## Cost
|
|
332
351
|
|
package/README.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# deep-read-summarize
|
|
2
2
|
|
|
3
|
+
[English](https://github.com/PensiveFei/deep-read-summarize/blob/main/README.en.md) | [简体中文](https://github.com/PensiveFei/deep-read-summarize/blob/main/README.md)
|
|
4
|
+
|
|
3
5
|
[](https://github.com/PensiveFei/deep-read-summarize/blob/main/LICENSE)
|
|
4
6
|
[](https://github.com/PensiveFei/deep-read-summarize/releases)
|
|
5
7
|
[](https://github.com/PensiveFei/deep-read-summarize/actions/workflows/ci.yml)
|
|
6
|
-
[](https://www.npmjs.com/package/deep-read-summarize)
|
|
7
9
|
|
|
8
10
|
> **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
11
|
|
|
@@ -205,6 +207,8 @@ parsers: book, paper, video, web
|
|
|
205
207
|
"whisperModel": "small", // 视频转写模型档位:small | base | medium
|
|
206
208
|
"language": "zh", // 视频转写语言:纯英文视频可设 "en"
|
|
207
209
|
"device": "cpu", // 转写设备:cpu(默认)| auto | cuda;auto/cuda 需自备 CUDA 运行库,失败自动回退 cpu
|
|
210
|
+
"cpuThreads": 0, // 0 保持转写库默认值;1-64 可按实际硬件调优
|
|
211
|
+
"transcriptCache": true, // 音频内容与配置一致时复用本地逐字稿;false 强制每次推理
|
|
208
212
|
"maxRetries": 0, // 质量校验重试次数(默认 0 = 不重试,重试会明显变慢)
|
|
209
213
|
"frontmatter": "obsidian", // frontmatter 键集:obsidian(默认,配 Dataview)| generic(换掉 Hugo 保留键)| minimal
|
|
210
214
|
"requireCitations": true, // 关键结论是否必须标注出处
|
|
@@ -267,7 +271,22 @@ parsers: book, paper, video, web
|
|
|
267
271
|
|
|
268
272
|
**转写工具链**:脚本用 `uv` 创建 **Python 3.12** 环境,从清华镜像安装 **`faster-whisper==1.2.1`**,通过 `HF_ENDPOINT=https://hf-mirror.com` 下载并缓存模型。健康的缓存环境直接运行,不要求 uv 仍在 PATH,也不再启动单独的 Python 导入探测。实际解释器和依赖版本记录在缓存目录的 `runtime.json`;Python 补丁版本、uv 和传递依赖未全部锁定,不能据此声称环境逐字一致。PyAV 可直接解码音频,无需单独 ffmpeg。三平台使用同一条命令 `node scripts/transcribe.js --audio <音频> --out <txt>`,默认 CPU;`options.device: "auto"` 可尝试自备的 CUDA,失败回退 CPU。缓存目录:Windows `%LOCALAPPDATA%\deep-read-summarize`、macOS `~/Library/Caches/deep-read-summarize`、Linux `$XDG_CACHE_HOME/deep-read-summarize`(未设置时用 `~/.cache`)。创建 Python 环境默认先用镜像,失败再直连 GitHub;`DRS_UV_PYTHON_MIRROR` 可覆盖镜像,空字符串表示直连。
|
|
269
273
|
|
|
270
|
-
> ⚠️ **首次转写会先下载模型(small 约 484MB,走 hf-mirror,非 GitHub
|
|
274
|
+
> ⚠️ **首次转写会先下载模型(small 约 484MB,走 hf-mirror,非 GitHub),可能需要几分钟**。之后复用模型文件;新音频仍需完整推理。同一音频命中经过校验的逐字稿缓存时,才会跳过推理。**只有「无字幕」视频才会触发转写**(有字幕的视频直接用字幕,不触发、不下载)。
|
|
275
|
+
|
|
276
|
+
**逐字稿缓存与线程**:`options.transcriptCache` 默认开启。缓存键包含音频 SHA-256、受管理的本地模型快照、已安装依赖及解码配置;存储真实分段和起止时间,切换时间戳展示不必重转写。更改内容、配置或本地模型/依赖会失效;自定义本地模型目录、无法确认环境、损坏和过期记录均跳过缓存。缓存复用本地已有快照,不在线探测模型上游是否更新。逐字稿保存在上述缓存根目录的 `transcripts-v1`,单条上限 8 MiB、总量上限 128 MiB、有效期 30 天;清理在写入时执行。它不保存音频,也不会跳过后续精读与原文核验。
|
|
277
|
+
|
|
278
|
+
`options.cpuThreads` 为 0–64 的整数,默认 `0` 保持库的 CPU 线程策略。可用同一音频对比 4/6/8 线程,线程越多不一定越快。CLI 可直接使用:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
node scripts/transcribe.js --audio sample.m4a --out transcript.txt --cpu-threads 8
|
|
282
|
+
node scripts/transcribe.js --audio sample.m4a --out transcript.txt --refresh-cache
|
|
283
|
+
node scripts/transcribe.js --audio sample.m4a --out transcript.txt --no-cache
|
|
284
|
+
node scripts/transcribe.js --clear-cache
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
`--clear-cache` 只清理逐字稿,不删除模型或 Python 环境。`--refresh-cache` 强制推理并更新缓存,`--no-cache` 禁用读写。成功调用输出一行 `metrics` JSON,报告 `cacheHit`、实际设备、音频时长,以及哈希、环境准备、依赖安装、Python、发布和总毫秒耗时;未命中时还报告导入、模型加载、准备(含解码/VAD)与完整分段迭代耗时。缓存命中不会冒用上次推理耗时。
|
|
288
|
+
|
|
289
|
+
笔记的 `qualityPassed` 核验笔记与取得的原文,不证明 ASR 听写准确;调整转写路径仍须对照音频检查误字、漏段、数字、否定句与时间戳。
|
|
271
290
|
|
|
272
291
|
**质量/速度**:`small` + `int8` 量化 + `VAD` 静音过滤,中文质量可用且 CPU 友好。**有字幕的视频不转写(快)**;无字幕视频转写,CPU 上约为视频时长的 0.5–2×。
|
|
273
292
|
|
|
@@ -298,7 +317,7 @@ parsers: book, paper, video, web
|
|
|
298
317
|
- **分块结构**:不同类型分块方式不同(章节/主题/段落),影响**输出结构**与覆盖。
|
|
299
318
|
|
|
300
319
|
### 硬件
|
|
301
|
-
- **GPU vs CPU**:GPU
|
|
320
|
+
- **GPU vs CPU**:GPU 收益依赖显卡、运行库、模型与音频;设备可见不代表 CUDA 推理可用,应以实际耗时与文本对照为准。
|
|
302
321
|
|
|
303
322
|
### 其他
|
|
304
323
|
- **首次 vs 复用**:首次要下模型(约 484MB),之后缓存复用。
|
|
@@ -325,7 +344,7 @@ parsers: book, paper, video, web
|
|
|
325
344
|
- 视频 `textSource: "desc"` 明确为降级来源,不能取得完整精读的质量通过状态。B站多 P 链接按 `p` 选择对应 CID、分 P 标题和时长。
|
|
326
345
|
- 返回 `timings` 提供各阶段毫秒耗时,用同一资料、模型、篇幅和质量门槛比较;调度测试不能当成真实 LLM 加速比例。
|
|
327
346
|
|
|
328
|
-
|
|
347
|
+
默认保持 small/int8、既有解码设置、篇幅与独立原文核验。逐字稿缓存主要加速重复处理,新视频可用线程配置和分阶段计时调优;常驻 ASR 模型、批量推理和分层 QC 仍需独立基准,不自动启用。
|
|
329
348
|
|
|
330
349
|
## 成本
|
|
331
350
|
|
package/SECURITY.md
CHANGED
|
@@ -6,7 +6,7 @@ Please do **not** open a public issue for security vulnerabilities.
|
|
|
6
6
|
|
|
7
7
|
To report a vulnerability privately:
|
|
8
8
|
|
|
9
|
-
1. Open a [private security advisory](https://github.com
|
|
9
|
+
1. Open a [private security advisory](https://github.com/PensiveFei/deep-read-summarize/security/advisories/new) (if available), or
|
|
10
10
|
2. Email the maintainer (see repository profile for contact).
|
|
11
11
|
|
|
12
12
|
## What to include
|
|
@@ -24,4 +24,4 @@ To report a vulnerability privately:
|
|
|
24
24
|
|
|
25
25
|
## Scope
|
|
26
26
|
|
|
27
|
-
This project only ships workflow code, prompt templates, and schemas. It does not contain copyrighted content or secrets. Vulnerabilities of interest include prompt injection in parser prompts, sandbox escape attempts, and unsafe file handling.
|
|
27
|
+
This project only ships workflow code, prompt templates, and schemas. It does not contain copyrighted content or secrets. Vulnerabilities of interest include prompt injection in parser prompts, sandbox escape attempts, and unsafe file handling.
|
package/cordis.patch.yml
CHANGED
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
# whisperModel: 'small' # transcription model (default: small)
|
|
27
27
|
# language: 'zh' # transcription language (default: zh)
|
|
28
28
|
# device: 'cpu' # cpu | auto | cuda; GPU needs a CUDA runtime (default: cpu)
|
|
29
|
+
# cpuThreads: 0 # 0 keeps library defaults; 1-64 for measured CPU tuning
|
|
30
|
+
# transcriptCache: true # local content/config-verified transcript reuse (30 days, 128 MiB)
|
|
29
31
|
# maxRetries: 0 # quality-check retry rounds (default: 0)
|
|
30
32
|
# frontmatter: 'obsidian' # obsidian | generic | minimal (default: obsidian)
|
|
31
33
|
# # generic swaps the keys Hugo reserves: type -> docType,
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# ASR performance check — 2026-11-01
|
|
2
|
+
|
|
3
|
+
This check compares the unmodified `6b95206` runner with the transcript-cache/thread/metrics changes. It measures transcription only, excluding video download, deep reading, drafting and independent source review.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
- Windows, Intel Core i5-12500H (12 cores, 16 logical processors), 16 GB RAM; CPU execution.
|
|
8
|
+
- Node 24.19.0, faster-whisper 1.2.1, CTranslate2 4.8.1, PyAV 18.1.0.
|
|
9
|
+
- Existing `small` model snapshot `536b0662742c02347bc0e980a01041f333bce120`, int8, Chinese, existing beam/VAD/decoding defaults; model files already downloaded. HF offline mode prevented network/download variation.
|
|
10
|
+
- One self-authored Chinese passage, rendered locally by Microsoft Huihui Desktop to a 58.439-second WAV. The passage includes numeric contrasts and negation. No private audio was used.
|
|
11
|
+
- Each row starts a separate Node process. The first two use the library's default CPU thread policy; the final row explicitly selects 8. A transcript-cache hit still hashes the input, validates cache identity and publishes a new output.
|
|
12
|
+
|
|
13
|
+
## Observations
|
|
14
|
+
|
|
15
|
+
| Run | Wall time | Lazy inference iteration | Text relative to baseline |
|
|
16
|
+
| --- | ---: | ---: | --- |
|
|
17
|
+
| Original runner | 24.517 s | not instrumented | baseline |
|
|
18
|
+
| New runner, forced inference | 23.118 s | 20.184 s | byte-identical |
|
|
19
|
+
| New runner, cached, timestamps enabled | 0.098 s | skipped | byte-identical after removing timestamp prefixes |
|
|
20
|
+
| New runner, 8 threads, cache disabled | 21.275 s | 18.306 s | byte-identical |
|
|
21
|
+
|
|
22
|
+
The new forced-inference run spent 0.549 s importing, 1.378 s loading the model, and 0.334 s preparing audio/VAD before consuming segments. The cache-hit call reported zero Python time. Stored segments were rendered with their real times; enabling timestamps did not call Python again.
|
|
23
|
+
|
|
24
|
+
These are single observations, not a latency distribution or a general speed guarantee. Execution order, OS/model-file caches and machine load can affect the difference between fresh runs. The unchanged default is intentional: this sample does not justify increasing CPU threads for every machine.
|
|
25
|
+
|
|
26
|
+
The normalized reference CER was 9.852% in all four rows. Normalization keeps Unicode letters/numbers, folds case and removes punctuation; it does not equate spoken number words with digits or traditional with simplified Chinese. The result establishes output preservation on this sample, not accurate listening for all videos. Real speech, noise, accents, mixed languages, long silence and long-form omissions need their own reference set. GPU and batch inference were not tested or enabled by this change.
|
|
27
|
+
|
|
28
|
+
## Repeating the check
|
|
29
|
+
|
|
30
|
+
Generate audio from the reference below or use a licensed clip with a reference transcript. Keep the same audio, model snapshot, device, decoding settings and machine load for paired runs. Measure full process wall time and inspect the `metrics` JSON. The `inference` timer consumes the complete lazy segment iterator; timing only the return of `transcribe()` is insufficient.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Fresh result and cache population
|
|
34
|
+
node scripts/transcribe.js --audio sample.wav --out fresh.txt --refresh-cache
|
|
35
|
+
# Same audio, different presentation, no inference
|
|
36
|
+
node scripts/transcribe.js --audio sample.wav --out timestamped.txt --timestamps
|
|
37
|
+
# Thread comparisons must bypass the cache
|
|
38
|
+
node scripts/transcribe.js --audio sample.wav --out threads4.txt --cpu-threads 4 --no-cache
|
|
39
|
+
node scripts/transcribe.js --audio sample.wav --out threads8.txt --cpu-threads 8 --no-cache
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Check exact text, omissions, numbers, negation and timestamps as well as aggregate error rates. Keep cold environment/model download, fresh inference and transcript hits separate. Gather multiple representative clips and repeated runs before making a broader performance claim.
|
|
43
|
+
|
|
44
|
+
## Self-authored reference
|
|
45
|
+
|
|
46
|
+
今天讨论怎样检查学习笔记的准确性。第一,完整的音频转写不能只保留开头,也不能把视频简介当成全文。第二,数字和否定句需要特别检查。实验用了五十个样本,不是十五个样本;正确率是百分之九十二,而不是百分之九十七。第三,模型下载到磁盘以后,处理新的音频仍然需要推理。重复处理同一份音频时,可以验证内容哈希并复用逐字稿。第四,缓存命中以后,笔记仍然需要精读和独立核验,不能直接宣布质量通过。最后,请保留每一段的真实时间位置,遇到不确定的术语时明确标记,不要编造。
|
package/docs/RELEASE.md
CHANGED
|
@@ -30,6 +30,19 @@
|
|
|
30
30
|
- <未解决的问题或限制>
|
|
31
31
|
- ...
|
|
32
32
|
|
|
33
|
+
### 贡献者与致谢
|
|
34
|
+
|
|
35
|
+
- @<GitHub 用户名>:<代码、报告、复现、复测或文档等具体贡献>(<对应 Issue/PR 的完整链接>)。
|
|
36
|
+
- <没有外部贡献时如实说明;需要匿名时按贡献者意愿记录,不猜测真实姓名或邮箱。>
|
|
37
|
+
|
|
38
|
+
**归属清单(维护者发布前后各核对一次)**:
|
|
39
|
+
|
|
40
|
+
- [ ] 对照已合并 PR、已解决 Issue 和复测记录,核对用户名与贡献,保留作者/共同作者信息。
|
|
41
|
+
- [ ] 在目标版本的 **CHANGELOG.md 小节**中填好致谢;`npm run release` 从该小节原样生成 Notes,仅修改此模板不会进入发布说明。
|
|
42
|
+
- [ ] GitHub Generate release notes 可用 `.github/release.yml` 分类并列出 PR 作者;人工补齐报告者和复测者,不覆盖已有署名。
|
|
43
|
+
- [ ] 发布后核对公开 Release 的用户名、贡献说明和来源链接;遗漏时补记,保留原有说明、资产和 tag。
|
|
44
|
+
- [ ] 按 [贡献指南](../CONTRIBUTING.md) 在相关讨论中说明结果并及时致谢;敏感报告先确认披露范围。
|
|
45
|
+
|
|
33
46
|
---
|
|
34
47
|
|
|
35
48
|
## npm 发布流程
|
|
@@ -140,7 +153,8 @@ npm view deep-read-summarize --prefer-online # 验证线
|
|
|
140
153
|
| v0.3.17 | npm 已发布 | 修 `resolve()` 原型链回退与质量清单 required;新增发布脚本 `scripts/release.js` |
|
|
141
154
|
| v0.3.18 | npm 已发布 | 修复自动解析器分流、并发临时文件串稿和分块上限导致的全文遗漏 |
|
|
142
155
|
| v0.3.19 | npm 已发布 | 修复 B04–B10,并让质量检查结合程序门禁和可回查的原文证据(O01)。 |
|
|
143
|
-
|
|
|
156
|
+
| v0.4.0 | npm 已发布 | 保留完整精读与独立原文核验,减少脚本搬运、并发空等和无效修订,并修复来源质量判断与视频分P等问题。 |
|
|
157
|
+
| **v0.5.0** | **npm 已发布(当前)** | 无字幕视频新增逐字稿内容缓存、转写阶段计时和 CPU 线程配置,保留默认精读与原文核验门槛。 |
|
|
144
158
|
| v1.0.0 | 计划 | API 稳定后发布 |
|
|
145
159
|
|
|
146
160
|
> 早期迭代用 0.x 表达不稳定;API 稳定后再发 1.0.0。
|
package/lib/options.js
CHANGED
|
@@ -6,7 +6,7 @@ function normalizeWorkflowOptions(raw, behavior) {
|
|
|
6
6
|
minWords: 2500, fastMode: false, maxChunks: 4, transcribe: true,
|
|
7
7
|
requireCitations: true, includeTimestamps: false, outputDir: './output',
|
|
8
8
|
tempDir: './.tmp', whisperModel: 'small', language: 'zh', device: 'cpu',
|
|
9
|
-
maxRetries: 0, frontmatter: 'obsidian'
|
|
9
|
+
maxRetries: 0, frontmatter: 'obsidian', cpuThreads: 0, transcriptCache: true
|
|
10
10
|
};
|
|
11
11
|
const settings = behavior || {};
|
|
12
12
|
const tolerant = settings.mode === 'config';
|
|
@@ -37,9 +37,9 @@ function normalizeWorkflowOptions(raw, behavior) {
|
|
|
37
37
|
if (!Object.prototype.hasOwnProperty.call(raw, key) || raw[key] === undefined) continue;
|
|
38
38
|
let value = raw[key];
|
|
39
39
|
let reason = '';
|
|
40
|
-
if (key === 'minWords' || key === 'maxChunks' || key === 'maxRetries') {
|
|
41
|
-
const minimum = key === 'maxRetries' ? 0 : 1;
|
|
42
|
-
const maximum = key === 'minWords' ? 100000 : (key === 'maxRetries' ? 3 : Infinity);
|
|
40
|
+
if (key === 'minWords' || key === 'maxChunks' || key === 'maxRetries' || key === 'cpuThreads') {
|
|
41
|
+
const minimum = key === 'maxRetries' || key === 'cpuThreads' ? 0 : 1;
|
|
42
|
+
const maximum = key === 'cpuThreads' ? 64 : key === 'minWords' ? 100000 : (key === 'maxRetries' ? 3 : Infinity);
|
|
43
43
|
if (typeof value !== 'number' || !Number.isFinite(value) || !Number.isInteger(value) || value < minimum || value > maximum) {
|
|
44
44
|
reason = 'expected a finite integer in ' + minimum + '..' + (maximum === Infinity ? '12 (larger values are capped)' : maximum);
|
|
45
45
|
} else if (key === 'maxChunks' && value > 12) {
|
package/lib/parser-bundle.js
CHANGED
|
@@ -34,6 +34,16 @@ function analyze(source, filename) {
|
|
|
34
34
|
else if (pattern.type === 'ObjectPattern') pattern.properties.forEach(item => bind(item.type === 'RestElement' ? item.argument : item.value, target));
|
|
35
35
|
}
|
|
36
36
|
function collect(node, active, parent, key) {
|
|
37
|
+
if (node.type === 'SwitchStatement') {
|
|
38
|
+
// The discriminant is evaluated before entering the case block's lexical
|
|
39
|
+
// environment. A case-local `require` must not hide an outer import here.
|
|
40
|
+
scopes.set(node, active);
|
|
41
|
+
nodes.push({ node, parent, key });
|
|
42
|
+
collect(node.discriminant, active, node, 'discriminant');
|
|
43
|
+
const cases = scope(active, 'block');
|
|
44
|
+
node.cases.forEach(item => collect(item, cases, node, 'cases'));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
37
47
|
if (/^Function/.test(node.type) || node.type === 'ArrowFunctionExpression') {
|
|
38
48
|
if (node.type === 'FunctionDeclaration') bind(node.id, active);
|
|
39
49
|
const parameters = scope(active, 'parameters');
|
|
@@ -49,7 +59,7 @@ function analyze(source, filename) {
|
|
|
49
59
|
if (node.type === 'ClassDeclaration') bind(node.id, active);
|
|
50
60
|
if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
|
|
51
61
|
active = scope(active, 'block'); bind(node.id, active);
|
|
52
|
-
} else if (['BlockStatement', 'CatchClause', 'ForStatement', 'ForInStatement', 'ForOfStatement'
|
|
62
|
+
} else if (['BlockStatement', 'CatchClause', 'ForStatement', 'ForInStatement', 'ForOfStatement'].indexOf(node.type) >= 0) {
|
|
53
63
|
active = scope(active, 'block');
|
|
54
64
|
} else if (node.type === 'StaticBlock') active = scope(active, 'function');
|
|
55
65
|
if (node.type === 'CatchClause') bind(node.param, active);
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const crypto = require('node:crypto');
|
|
6
|
+
|
|
7
|
+
const VERSION = 1;
|
|
8
|
+
const MAX_ENTRY_BYTES = 8 * 1024 * 1024;
|
|
9
|
+
const MAX_CACHE_BYTES = 128 * 1024 * 1024;
|
|
10
|
+
const MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000;
|
|
11
|
+
const entryName = /^[a-f0-9]{64}\.json$/;
|
|
12
|
+
function digest(value) { return crypto.createHash('sha256').update(value).digest('hex'); }
|
|
13
|
+
function directory(root) { return path.join(root, 'transcripts-v1'); }
|
|
14
|
+
|
|
15
|
+
function hashFile(file) {
|
|
16
|
+
const hash = crypto.createHash('sha256');
|
|
17
|
+
const fd = fs.openSync(file, 'r');
|
|
18
|
+
try {
|
|
19
|
+
const buffer = Buffer.alloc(1024 * 1024);
|
|
20
|
+
let count;
|
|
21
|
+
while ((count = fs.readSync(fd, buffer, 0, buffer.length, null)) > 0) hash.update(buffer.subarray(0, count));
|
|
22
|
+
} finally { fs.closeSync(fd); }
|
|
23
|
+
return hash.digest('hex');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Cache only managed HF snapshots with a locally identifiable environment.
|
|
27
|
+
// Any installed package or model snapshot change invalidates the identity.
|
|
28
|
+
// Local/custom model directories deliberately bypass this cache.
|
|
29
|
+
function runtimeIdentity(root, model) {
|
|
30
|
+
try {
|
|
31
|
+
if (!/^[a-z0-9.-]+$/i.test(model) || fs.existsSync(model)) return null;
|
|
32
|
+
const venv = path.join(root, 'venv');
|
|
33
|
+
const sites = [path.join(venv, 'Lib', 'site-packages')];
|
|
34
|
+
const lib = path.join(venv, 'lib');
|
|
35
|
+
if (fs.existsSync(lib)) {
|
|
36
|
+
for (const name of fs.readdirSync(lib)) {
|
|
37
|
+
if (/^python\d+\.\d+$/.test(name)) sites.push(path.join(lib, name, 'site-packages'));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const packages = sites.filter(p => fs.existsSync(p)).flatMap(p => fs.readdirSync(p).filter(n => n.endsWith('.dist-info'))).sort();
|
|
41
|
+
if (!packages.some(n => /^faster_whisper-1\.2\.1\.dist-info$/.test(n)) ||
|
|
42
|
+
!packages.some(n => /^ctranslate2-/.test(n))) return null;
|
|
43
|
+
const hub = path.join(root, 'hf', 'hub');
|
|
44
|
+
const canonicalHub = fs.realpathSync(hub);
|
|
45
|
+
const manifest = [];
|
|
46
|
+
let binaries = 0;
|
|
47
|
+
function visit(dir, prefix, depth) {
|
|
48
|
+
if (depth > 5 || manifest.length > 4096) throw new Error('model manifest exceeds limits');
|
|
49
|
+
for (const name of fs.readdirSync(dir).sort()) {
|
|
50
|
+
if (manifest.length >= 4096) throw new Error('model manifest exceeds limits');
|
|
51
|
+
const file = path.join(dir, name);
|
|
52
|
+
const relative = prefix + '/' + name;
|
|
53
|
+
const link = fs.lstatSync(file);
|
|
54
|
+
if (link.isDirectory()) visit(file, relative, depth + 1);
|
|
55
|
+
else {
|
|
56
|
+
const real = fs.realpathSync(file);
|
|
57
|
+
const inside = path.relative(canonicalHub, real);
|
|
58
|
+
if (inside.startsWith('..') || path.isAbsolute(inside)) throw new Error('model file outside managed cache');
|
|
59
|
+
const stat = fs.statSync(file);
|
|
60
|
+
if (!stat.isFile()) throw new Error('non-file model artifact');
|
|
61
|
+
if (name === 'model.bin') binaries++;
|
|
62
|
+
manifest.push([relative, stat.size, stat.mtimeMs,
|
|
63
|
+
prefix.includes('/refs') ? fs.readFileSync(file, 'utf8') : '']);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
for (const repo of fs.readdirSync(hub).filter(n => n.startsWith('models--')).sort()) {
|
|
68
|
+
for (const section of ['refs', 'snapshots']) {
|
|
69
|
+
const dir = path.join(hub, repo, section);
|
|
70
|
+
if (fs.existsSync(dir)) visit(dir, repo + '/' + section, 0);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!binaries) return null;
|
|
74
|
+
const pythonConfig = path.join(venv, 'pyvenv.cfg');
|
|
75
|
+
return digest(JSON.stringify({ packages, manifest,
|
|
76
|
+
python: fs.existsSync(pythonConfig) ? fs.readFileSync(pythonConfig, 'utf8') : '' }));
|
|
77
|
+
} catch (error) { return null; }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function identity(audioHash, args, runtime, runner) {
|
|
81
|
+
if (!runtime) return null;
|
|
82
|
+
// Timestamp presentation is excluded: canonical segments retain both times.
|
|
83
|
+
const config = { version: VERSION, audioHash, runtime, model: args.model,
|
|
84
|
+
language: args.language, device: args.device, cpuThreads: args.cpuThreads,
|
|
85
|
+
fasterWhisper: '1.2.1', computeType: 'int8', beamSize: 5, bestOf: 5,
|
|
86
|
+
vadFilter: true, conditionOnPreviousText: true,
|
|
87
|
+
temperature: [0, 0.2, 0.4, 0.6, 0.8, 1], pipeline: 'standard-v1', runner: digest(runner || '') };
|
|
88
|
+
return { key: digest(JSON.stringify(config)), config };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function validSegments(segments) {
|
|
92
|
+
return Array.isArray(segments) && segments.length > 0 && segments.every(s =>
|
|
93
|
+
s && typeof s.text === 'string' && s.text.trim() && !/[\u0000\r\n]/.test(s.text) &&
|
|
94
|
+
Number.isFinite(s.start) && Number.isFinite(s.end) && s.start >= 0 && s.end >= s.start);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function timestamp(seconds) {
|
|
98
|
+
// Match Python round() (ties to even) used by the existing runner.
|
|
99
|
+
const value = Math.max(0, seconds * 1000);
|
|
100
|
+
const floor = Math.floor(value);
|
|
101
|
+
let millis = value - floor === 0.5 ? floor + (floor % 2) : Math.round(value);
|
|
102
|
+
const hours = Math.floor(millis / 3600000); millis %= 3600000;
|
|
103
|
+
const minutes = Math.floor(millis / 60000); millis %= 60000;
|
|
104
|
+
const whole = Math.floor(millis / 1000); millis %= 1000;
|
|
105
|
+
return String(hours).padStart(2, '0') + ':' + String(minutes).padStart(2, '0') + ':' +
|
|
106
|
+
String(whole).padStart(2, '0') + '.' + String(millis).padStart(3, '0');
|
|
107
|
+
}
|
|
108
|
+
function render(segments, timestamps) {
|
|
109
|
+
return segments.map(s => (timestamps ? '[' + timestamp(s.start) + ' --> ' + timestamp(s.end) + '] ' : '') + s.text).join('\n');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function read(root, id) {
|
|
113
|
+
if (!id) return null;
|
|
114
|
+
try {
|
|
115
|
+
const file = path.join(directory(root), id.key + '.json');
|
|
116
|
+
const stat = fs.lstatSync(file);
|
|
117
|
+
if (!stat.isFile() || stat.size > MAX_ENTRY_BYTES) return null;
|
|
118
|
+
const entry = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
119
|
+
if (entry.version !== VERSION || entry.key !== id.key ||
|
|
120
|
+
JSON.stringify(entry.config) !== JSON.stringify(id.config) ||
|
|
121
|
+
!Number.isFinite(entry.createdAt) || entry.createdAt > Date.now() || Date.now() - entry.createdAt > MAX_AGE_MS ||
|
|
122
|
+
!entry.report || !validSegments(entry.report.segments) ||
|
|
123
|
+
entry.checksum !== digest(JSON.stringify(entry.report))) return null;
|
|
124
|
+
try { fs.utimesSync(file, new Date(), new Date()); } catch (error) { /* best effort LRU */ }
|
|
125
|
+
return entry.report;
|
|
126
|
+
} catch (error) { return null; }
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function prune(root, limit = MAX_CACHE_BYTES) {
|
|
130
|
+
const dir = directory(root);
|
|
131
|
+
if (!fs.existsSync(dir)) return;
|
|
132
|
+
const files = fs.readdirSync(dir).filter(n => entryName.test(n)).flatMap(name => {
|
|
133
|
+
try {
|
|
134
|
+
const file = path.join(dir, name), stat = fs.lstatSync(file);
|
|
135
|
+
return stat.isFile() ? [{ file, size: stat.size, modified: stat.mtimeMs }] : [];
|
|
136
|
+
} catch (error) { return []; }
|
|
137
|
+
}).sort((a, b) => b.modified - a.modified);
|
|
138
|
+
let size = 0;
|
|
139
|
+
for (const file of files) {
|
|
140
|
+
if (size + file.size > limit || Date.now() - file.modified > MAX_AGE_MS) fs.unlinkSync(file.file);
|
|
141
|
+
else size += file.size;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function write(root, id, report) {
|
|
146
|
+
if (!id || !report || !validSegments(report.segments)) return false;
|
|
147
|
+
let temporary;
|
|
148
|
+
try {
|
|
149
|
+
const data = JSON.stringify({ version: VERSION, key: id.key, config: id.config,
|
|
150
|
+
createdAt: Date.now(), report, checksum: digest(JSON.stringify(report)) });
|
|
151
|
+
if (Buffer.byteLength(data) > MAX_ENTRY_BYTES) return false;
|
|
152
|
+
const dir = directory(root);
|
|
153
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
154
|
+
temporary = path.join(dir, '.write-' + crypto.randomBytes(16).toString('hex'));
|
|
155
|
+
fs.writeFileSync(temporary, data, { flag: 'wx', mode: 0o600 });
|
|
156
|
+
fs.renameSync(temporary, path.join(dir, id.key + '.json'));
|
|
157
|
+
prune(root);
|
|
158
|
+
return true;
|
|
159
|
+
} catch (error) { return false; }
|
|
160
|
+
finally { if (temporary) { try { fs.unlinkSync(temporary); } catch (error) { /* already renamed */ } } }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Delete only this module's strictly named entries; never recurse or touch models.
|
|
164
|
+
function clear(root) {
|
|
165
|
+
const dir = directory(root);
|
|
166
|
+
if (!fs.existsSync(dir)) return;
|
|
167
|
+
for (const name of fs.readdirSync(dir).filter(n => entryName.test(n))) {
|
|
168
|
+
const file = path.join(dir, name);
|
|
169
|
+
if (fs.lstatSync(file).isFile()) fs.unlinkSync(file);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
module.exports = { hashFile, runtimeIdentity, identity, validSegments, render, read, write, clear, prune, directory };
|
package/lib/workflow-script.txt
CHANGED
|
@@ -129,7 +129,7 @@ const kindFocus = {
|
|
|
129
129
|
phase("获取与分块");
|
|
130
130
|
const fetchStartedAt = Date.now();
|
|
131
131
|
const fetchPrompt = parsers[selectedType]
|
|
132
|
-
.buildPrompt(input, { tempDir: tempDir, tempFile: tempFile, maxChunks: maxChunks, transcribe: options.transcribe, whisperModel: whisperModel, language: transcribeLanguage, device: transcribeDevice, includeTimestamps: includeTimestamps, transcribeScriptPath: __runtimePaths.transcribeScript });
|
|
132
|
+
.buildPrompt(input, { tempDir: tempDir, tempFile: tempFile, maxChunks: maxChunks, transcribe: options.transcribe, whisperModel: whisperModel, language: transcribeLanguage, device: transcribeDevice, cpuThreads: options.cpuThreads, transcriptCache: options.transcriptCache, includeTimestamps: includeTimestamps, transcribeScriptPath: __runtimePaths.transcribeScript });
|
|
133
133
|
// fetchSchema 由插件在构建时从 schemas/index.js 注入(单一真相,避免两份 schema 漂移)。
|
|
134
134
|
|
|
135
135
|
let fetched;
|
|
@@ -235,13 +235,17 @@ const chunkPrompts = chunkPlan.map(function (c) {
|
|
|
235
235
|
|
|
236
236
|
const reads = new Array(chunkPrompts.length);
|
|
237
237
|
let nextRead = 0;
|
|
238
|
+
let stopReading = false;
|
|
238
239
|
const readWorkers = [];
|
|
239
240
|
for (let worker = 0; worker < Math.min(3, chunkPrompts.length); worker++) {
|
|
240
241
|
readWorkers.push(async function () {
|
|
241
|
-
while (nextRead < chunkPrompts.length) {
|
|
242
|
+
while (!stopReading && nextRead < chunkPrompts.length) {
|
|
242
243
|
const index = nextRead++;
|
|
243
244
|
try { reads[index] = await agent(chunkPrompts[index], { label: "精读块", phase: "并行精读" }); }
|
|
244
|
-
catch (error) {
|
|
245
|
+
catch (error) {
|
|
246
|
+
if (fatalWorkflowError(error)) { stopReading = true; throw error; }
|
|
247
|
+
log("精读调用失败,保留对应分块缺口"); reads[index] = "";
|
|
248
|
+
}
|
|
245
249
|
}
|
|
246
250
|
});
|
|
247
251
|
}
|
|
@@ -351,7 +355,11 @@ const draftPrompt = [
|
|
|
351
355
|
|
|
352
356
|
let draft;
|
|
353
357
|
try { draft = await agent(draftPrompt, { label: "汇总成稿", phase: "汇总成稿" }); }
|
|
354
|
-
catch (error) {
|
|
358
|
+
catch (error) {
|
|
359
|
+
if (fatalWorkflowError(error)) throw error;
|
|
360
|
+
timings.draft = Date.now() - draftStartedAt;
|
|
361
|
+
return timedResult({ ok: false, stage: "draft", fatal: false, message: "成稿调用失败,未产生可保存的笔记" });
|
|
362
|
+
}
|
|
355
363
|
timings.draft = Date.now() - draftStartedAt;
|
|
356
364
|
if (typeof draft !== "string" || !draft.trim()) return timedResult({ ok: false, stage: "draft", fatal: false, message: "成稿为空或不是字符串" });
|
|
357
365
|
|
|
@@ -400,7 +408,10 @@ for (let round = 0; round <= maxRetries; round++) {
|
|
|
400
408
|
};
|
|
401
409
|
let check = null;
|
|
402
410
|
try { check = await agent(checkPrompt, { schema: checkSchema, label: "质量校验", phase: "质量校验" }); }
|
|
403
|
-
catch (error) {
|
|
411
|
+
catch (error) {
|
|
412
|
+
if (fatalWorkflowError(error)) throw error;
|
|
413
|
+
log("原文核验调用失败,保留当前有效笔记并报告质量未通过");
|
|
414
|
+
}
|
|
404
415
|
const sourceCheck = __quality.validateSourceCheck(check, {
|
|
405
416
|
chunkPlan: chunkPlan, failedChunkIds: failedChunkIds, coverageComplete: coverageComplete, sourceComplete: sourceComplete, textSource: textSource,
|
|
406
417
|
requireCitations: requireCitations, note: verified, visibleNote: localCheck.visibleText, quotes: localCheck.quotes
|
|
@@ -425,7 +436,10 @@ for (let round = 0; round <= maxRetries; round++) {
|
|
|
425
436
|
].join("\n");
|
|
426
437
|
let repaired;
|
|
427
438
|
try { repaired = await agent(fixPrompt, { label: "修正笔记", phase: "质量校验" }); }
|
|
428
|
-
catch (error) {
|
|
439
|
+
catch (error) {
|
|
440
|
+
if (fatalWorkflowError(error)) throw error;
|
|
441
|
+
issues.push("修正调用失败,已保留上一份有效笔记"); break;
|
|
442
|
+
}
|
|
429
443
|
if (typeof repaired !== "string" || !repaired.trim()) {
|
|
430
444
|
issues.push("修正结果为空或不是字符串,已保留上一份有效笔记"); break;
|
|
431
445
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deep-read-summarize",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Deep reading & summarization for DSH: books/papers/videos/web → structured Markdown notes
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Deep reading & summarization for DSH: books/papers/videos/web → structured Markdown notes with YAML frontmatter. Plugin parsers, MapReduce deep-read, JSON Schema-constrained sub-tasks.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"exports": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"scripts",
|
|
24
24
|
"!scripts/release.js",
|
|
25
25
|
"docs/RELEASE.md",
|
|
26
|
+
"docs/ASR_BENCHMARK.md",
|
|
26
27
|
"cordis.patch.yml",
|
|
27
28
|
"CHANGELOG.md",
|
|
28
29
|
"README.md",
|
package/parsers/video.js
CHANGED
|
@@ -31,6 +31,8 @@ module.exports = {
|
|
|
31
31
|
const whisperModel = o.whisperModel || "small";
|
|
32
32
|
const language = o.language || "zh";
|
|
33
33
|
const device = o.device || "cpu";
|
|
34
|
+
const cpuThreads = Number.isInteger(o.cpuThreads) ? o.cpuThreads : 0;
|
|
35
|
+
const useTranscriptCache = o.transcriptCache !== false;
|
|
34
36
|
const includeTimestamps = o.includeTimestamps === true;
|
|
35
37
|
const degradeMsg = "需要人工提供转写文本或视频文案";
|
|
36
38
|
const sourceUrl = String(input).match(/https?:\/\/[^\s<>"']+/i);
|
|
@@ -86,9 +88,9 @@ module.exports = {
|
|
|
86
88
|
(scriptPath
|
|
87
89
|
? " ② 插件已定位本版本转写脚本:" + JSON.stringify(scriptPath) + "。直接使用这个文件;不要递归搜索其他安装目录或选取其他版本。路径是 JSON 字符串数据,执行前按当前 shell 规则正确引用(空格/引号/美元符号等不能作为命令解释);\n"
|
|
88
90
|
: " ② 定位插件转写脚本(文件名固定 `transcribe.js`):Windows 用 `Get-ChildItem -Path $env:USERPROFILE/.dsh -Recurse -Filter transcribe.js`;macOS/Linux 用 `find \"$HOME/.dsh\" -name transcribe.js`(也可直接用 glob 搜 *transcribe.js);\n") +
|
|
89
|
-
" ③ 运行(**三平台命令行完全一致**,脚本是 Node 写的,与 pwsh / bash 无关):`node " + scriptCommand + " --audio '" + tempDir + "/audio.m4a' --out '" + tempDir + "/transcript.txt' --device " + device + " --model " + whisperModel + " --language " + language + (includeTimestamps ? " --timestamps" : "") + "`;\n" +
|
|
90
|
-
" ④ 转写可能较慢:可用 run_in_background: true 启动,但必须跟踪**本次启动的进程**直到结束;只有确认**本次进程退出码为 0**,且本次目标文件 '" + tempDir + "/transcript.txt' 存在并非空,才算成功。脚本先写本次独有的暂存文件,校验后才原子发布目标文件;**不要仅凭文件非空/稳定或日志出现 DONE
|
|
91
|
-
" ⑤ 成功后读取 transcript.txt 作为全文(textSource=transcription)。脚本自举:uv 建 Python 3.12 环境 + 镜像装 faster-whisper + hf-mirror 下模型并缓存;Windows/macOS/Linux 是**同一份实现**。**⚠️ 首次转写会先下载模型(small 约 484MB,hf-mirror,非 GitHub
|
|
91
|
+
" ③ 运行(**三平台命令行完全一致**,脚本是 Node 写的,与 pwsh / bash 无关):`node " + scriptCommand + " --audio '" + tempDir + "/audio.m4a' --out '" + tempDir + "/transcript.txt' --device " + device + " --model " + whisperModel + " --language " + language + " --cpu-threads " + cpuThreads + (useTranscriptCache ? "" : " --no-cache") + (includeTimestamps ? " --timestamps" : "") + "`;\n" +
|
|
92
|
+
" ④ 转写可能较慢:可用 run_in_background: true 启动,但必须跟踪**本次启动的进程**直到结束;只有确认**本次进程退出码为 0**,且本次目标文件 '" + tempDir + "/transcript.txt' 存在并非空,才算成功。脚本先写本次独有的暂存文件,校验后才原子发布目标文件;**不要仅凭文件非空/稳定或日志出现 DONE 判断完成,不要自行复用其他任务或上次运行的逐字稿**。仅脚本可以按音频 SHA-256、环境/模型快照和解码配置验证逐字稿缓存,命中后仍发布本次产物;缓存不能代替后续精读和独立原文核验。记录脚本输出的 metrics(cacheHit、实际 device、阶段毫秒耗时),不要推测不存在的计时。设合理超时,超时则终止本次进程;超时/非 0 退出/空产物均按降级处理;\n" +
|
|
93
|
+
" ⑤ 成功后读取 transcript.txt 作为全文(textSource=transcription)。脚本自举:uv 建 Python 3.12 环境 + 镜像装 faster-whisper + hf-mirror 下模型并缓存;Windows/macOS/Linux 是**同一份实现**。**⚠️ 首次转写会先下载模型(small 约 484MB,hf-mirror,非 GitHub)并较慢——先向用户说明这是正常的一次性下载,勿当成卡死;之后复用模型文件,新音频仍需推理。**\n" +
|
|
92
94
|
" ⑥ 若 `node` 不在 PATH(macOS 从图形界面启动时常见),先用 `command -v node` 确认;确认不可用就直接降级,不要为了跑转写脚本去安装 Node。"
|
|
93
95
|
);
|
|
94
96
|
} else {
|
package/scripts/transcribe.js
CHANGED
|
@@ -20,6 +20,7 @@ const { spawnSync } = require('node:child_process');
|
|
|
20
20
|
const fs = require('node:fs');
|
|
21
21
|
const os = require('node:os');
|
|
22
22
|
const path = require('node:path');
|
|
23
|
+
const transcriptCache = require('../lib/transcript-cache');
|
|
23
24
|
|
|
24
25
|
// 新环境使用 Python 3.12;ASR 主包固定为已验证版本。
|
|
25
26
|
// 复用环境不强制更换解释器;实际 Python / 传递依赖版本记录在 runtime.json。
|
|
@@ -175,19 +176,24 @@ function isFileAt(p) {
|
|
|
175
176
|
|
|
176
177
|
/** 解析命令行(支持 --k v、--k=v、-k v 三种写法)。 */
|
|
177
178
|
function parseArgs(argv) {
|
|
178
|
-
const out = { audio: '', out: '', model: 'small', language: 'zh', device: 'cpu',
|
|
179
|
+
const out = { audio: '', out: '', model: 'small', language: 'zh', device: 'cpu', cpuThreads: 0,
|
|
180
|
+
cache: true, refreshCache: false, clearCache: false, timestamps: false, selfCheck: false, help: false, unknown: [] };
|
|
179
181
|
const takes = {
|
|
180
182
|
'--audio': 'audio', '-a': 'audio',
|
|
181
183
|
'--out': 'out', '-o': 'out',
|
|
182
184
|
'--model': 'model', '-m': 'model',
|
|
183
185
|
'--language': 'language', '-l': 'language', '--lang': 'language',
|
|
184
|
-
'--device': 'device', '-d': 'device'
|
|
186
|
+
'--device': 'device', '-d': 'device', '--cpu-threads': 'cpuThreads'
|
|
185
187
|
};
|
|
186
188
|
const list = argv || [];
|
|
187
189
|
for (let i = 0; i < list.length; i++) {
|
|
188
190
|
const a = String(list[i]);
|
|
189
191
|
if (a === '--help' || a === '-h') { out.help = true; continue; }
|
|
190
192
|
if (a === '--self-check') { out.selfCheck = true; continue; }
|
|
193
|
+
if (a === '--no-cache' || a === '--cache=false') { out.cache = false; continue; }
|
|
194
|
+
if (a === '--cache' || a === '--cache=true') { out.cache = true; continue; }
|
|
195
|
+
if (a === '--refresh-cache') { out.refreshCache = true; continue; }
|
|
196
|
+
if (a === '--clear-cache') { out.clearCache = true; continue; }
|
|
191
197
|
if (a === '--timestamps' || a === '--timestamps=true') { out.timestamps = true; continue; }
|
|
192
198
|
if (a === '--no-timestamps' || a === '--timestamps=false') { out.timestamps = false; continue; }
|
|
193
199
|
if (takes[a]) {
|
|
@@ -210,7 +216,10 @@ const PY_RUNNER = [
|
|
|
210
216
|
"import sys",
|
|
211
217
|
"import json",
|
|
212
218
|
"import tempfile",
|
|
219
|
+
"import time",
|
|
213
220
|
"import importlib.metadata as metadata",
|
|
221
|
+
"runner_started = time.perf_counter()",
|
|
222
|
+
"timings = {'import': 0, 'modelLoad': 0, 'prepare': 0, 'inference': 0, 'write': 0}",
|
|
214
223
|
"",
|
|
215
224
|
"def bootstrap_required(code, reason, message):",
|
|
216
225
|
" status_file = os.environ.get('DRS_BOOTSTRAP_STATUS')",
|
|
@@ -233,6 +242,7 @@ const PY_RUNNER = [
|
|
|
233
242
|
" from faster_whisper import WhisperModel",
|
|
234
243
|
"except ModuleNotFoundError as exc:",
|
|
235
244
|
" bootstrap_required(" + DEPENDENCY_MISSING + ", 'missing-dependency', 'missing import dependency: %s' % exc)",
|
|
245
|
+
"timings['import'] = (time.perf_counter() - runner_started) * 1000",
|
|
236
246
|
"",
|
|
237
247
|
"runtime_versions = None",
|
|
238
248
|
"def record_runtime(device, phase):",
|
|
@@ -247,7 +257,7 @@ const PY_RUNNER = [
|
|
|
247
257
|
" runtime_versions[name] = metadata.version(name)",
|
|
248
258
|
" except metadata.PackageNotFoundError:",
|
|
249
259
|
" runtime_versions[name] = None",
|
|
250
|
-
" runtime = {'python': sys.version.split()[0], 'packages': runtime_versions, 'model': os.environ['DRS_MODEL'], 'device': device, 'computeType': 'int8', 'phase': phase}",
|
|
260
|
+
" runtime = {'python': sys.version.split()[0], 'packages': runtime_versions, 'model': os.environ['DRS_MODEL'], 'device': device, 'computeType': 'int8', 'cpuThreads': int(os.environ.get('DRS_CPU_THREADS', '0')), 'phase': phase}",
|
|
251
261
|
" temporary = None",
|
|
252
262
|
" try:",
|
|
253
263
|
" with tempfile.NamedTemporaryFile(mode='w', encoding='utf-8', dir=os.path.dirname(target), prefix='.runtime-', suffix='.json', delete=False) as f:",
|
|
@@ -265,12 +275,23 @@ const PY_RUNNER = [
|
|
|
265
275
|
" print('[transcribe] runtime python=%s faster-whisper=%s device=%s phase=%s' % (runtime['python'], runtime_versions['faster-whisper'], device, phase), file=sys.stderr)",
|
|
266
276
|
"",
|
|
267
277
|
"def load(device):",
|
|
268
|
-
" return WhisperModel(os.environ['DRS_MODEL'], device=device, compute_type='int8')",
|
|
278
|
+
" return WhisperModel(os.environ['DRS_MODEL'], device=device, compute_type='int8', cpu_threads=int(os.environ.get('DRS_CPU_THREADS', '0')))",
|
|
269
279
|
"",
|
|
270
280
|
"def run(device):",
|
|
271
|
-
"
|
|
281
|
+
" started = time.perf_counter()",
|
|
282
|
+
" try:",
|
|
283
|
+
" model = load(device)",
|
|
284
|
+
" finally:",
|
|
285
|
+
" timings['modelLoad'] += (time.perf_counter() - started) * 1000",
|
|
286
|
+
" started = time.perf_counter()",
|
|
272
287
|
" segs, info = model.transcribe(os.environ['DRS_AUDIO'], vad_filter=True, language=(os.environ.get('DRS_LANG') or None))",
|
|
273
|
-
"
|
|
288
|
+
" timings['prepare'] += (time.perf_counter() - started) * 1000",
|
|
289
|
+
" started = time.perf_counter()",
|
|
290
|
+
" try:",
|
|
291
|
+
" segments = [{'start': s.start, 'end': s.end, 'text': s.text.strip().replace('\\r', ' ').replace('\\n', ' ')} for s in segs if s.text.strip()]",
|
|
292
|
+
" finally:",
|
|
293
|
+
" timings['inference'] += (time.perf_counter() - started) * 1000",
|
|
294
|
+
" return segments, info, getattr(getattr(model, 'model', None), 'device', device)",
|
|
274
295
|
"",
|
|
275
296
|
"def timestamp(seconds):",
|
|
276
297
|
" millis = max(0, int(round(float(seconds) * 1000)))",
|
|
@@ -284,18 +305,19 @@ const PY_RUNNER = [
|
|
|
284
305
|
"device = os.environ.get('DRS_DEVICE') or 'cpu'",
|
|
285
306
|
"record_runtime(device, 'starting')",
|
|
286
307
|
"try:",
|
|
287
|
-
" segments, info = run(device)",
|
|
308
|
+
" segments, info, device = run(device)",
|
|
288
309
|
"except Exception as exc:",
|
|
289
310
|
" if device == 'cpu':",
|
|
290
311
|
" raise",
|
|
291
312
|
" print('[transcribe] device=%s failed (%s); retrying on cpu' % (device, exc), file=sys.stderr)",
|
|
292
313
|
" device = 'cpu'",
|
|
293
314
|
" record_runtime(device, 'starting')",
|
|
294
|
-
" segments, info = run('cpu')",
|
|
315
|
+
" segments, info, device = run('cpu')",
|
|
295
316
|
"record_runtime(device, 'completed')",
|
|
296
317
|
"",
|
|
297
318
|
"# DRS_OUT 是本次调用独有的暂存路径;Node 校验后才原子发布到最终路径。",
|
|
298
319
|
"# 先收集全部分段再落盘,中途推理失败不会留下半截文本。",
|
|
320
|
+
"write_started = time.perf_counter()",
|
|
299
321
|
"include_timestamps = os.environ.get('DRS_TIMESTAMPS') == '1'",
|
|
300
322
|
"lines = []",
|
|
301
323
|
"for segment in segments:",
|
|
@@ -307,6 +329,11 @@ const PY_RUNNER = [
|
|
|
307
329
|
" lines.append(text)",
|
|
308
330
|
"with open(os.environ['DRS_OUT'], 'w', encoding='utf-8', newline='\\n') as f:",
|
|
309
331
|
" f.write('\\n'.join(lines))",
|
|
332
|
+
"timings['write'] = (time.perf_counter() - write_started) * 1000",
|
|
333
|
+
"timings['total'] = (time.perf_counter() - runner_started) * 1000",
|
|
334
|
+
"if os.environ.get('DRS_SEGMENTS'):",
|
|
335
|
+
" with open(os.environ['DRS_SEGMENTS'], 'w', encoding='utf-8') as f:",
|
|
336
|
+
" json.dump({'segments': segments, 'device': device, 'cpuThreads': int(os.environ.get('DRS_CPU_THREADS', '0')), 'duration': getattr(info, 'duration', None), 'durationAfterVad': getattr(info, 'duration_after_vad', None), 'timings': timings}, f, ensure_ascii=False, allow_nan=False)",
|
|
310
337
|
""
|
|
311
338
|
].join("\n");
|
|
312
339
|
|
|
@@ -320,7 +347,9 @@ const USAGE = [
|
|
|
320
347
|
'',
|
|
321
348
|
'选项:--audio/-a --out/-o --model/-m(默认 small) --language/-l(默认 zh)',
|
|
322
349
|
' --device(默认 cpu;auto/cuda 需自备 CUDA 运行库,失败会自动回退 cpu)',
|
|
323
|
-
' --timestamps(逐段保留真实起止时间;默认关闭,关闭时仍按段换行)'
|
|
350
|
+
' --timestamps(逐段保留真实起止时间;默认关闭,关闭时仍按段换行)',
|
|
351
|
+
' --cpu-threads 0..64(0 保持库默认值);--no-cache 禁用逐字稿缓存',
|
|
352
|
+
' --refresh-cache 强制重转写并更新缓存;--clear-cache 仅清理逐字稿缓存'
|
|
324
353
|
].join('\n');
|
|
325
354
|
|
|
326
355
|
function fail(msg, code) {
|
|
@@ -350,6 +379,8 @@ function needsBootstrap(result, statusFile) {
|
|
|
350
379
|
}
|
|
351
380
|
|
|
352
381
|
function main(argv) {
|
|
382
|
+
const startedAt = Date.now();
|
|
383
|
+
const timing = { hash: 0, environment: 0, cacheLookup: 0, dependencyInstall: 0, python: 0, publish: 0, total: 0 };
|
|
353
384
|
const args = parseArgs(argv);
|
|
354
385
|
const c = context({});
|
|
355
386
|
const root = cacheRoot(c);
|
|
@@ -358,7 +389,6 @@ function main(argv) {
|
|
|
358
389
|
const uv = findUv(c);
|
|
359
390
|
|
|
360
391
|
if (args.help) { process.stdout.write(USAGE + '\n'); return 0; }
|
|
361
|
-
|
|
362
392
|
// --self-check:CI 与排查用,只报告解析结果,不产生任何副作用。
|
|
363
393
|
if (args.selfCheck) {
|
|
364
394
|
process.stdout.write(JSON.stringify({
|
|
@@ -376,7 +406,15 @@ function main(argv) {
|
|
|
376
406
|
return 0;
|
|
377
407
|
}
|
|
378
408
|
|
|
409
|
+
if (args.clearCache) {
|
|
410
|
+
try { transcriptCache.clear(root); process.stdout.write('[transcribe] transcript cache cleared\n'); return 0; }
|
|
411
|
+
catch (error) { return fail('无法清理逐字稿缓存:' + error.message); }
|
|
412
|
+
}
|
|
413
|
+
|
|
379
414
|
if (args.unknown.length) process.stderr.write('[transcribe] 忽略未知参数:' + args.unknown.join(', ') + '\n');
|
|
415
|
+
if (!/^\d+$/.test(String(args.cpuThreads))) return fail('--cpu-threads 必须为 0..64 的整数');
|
|
416
|
+
args.cpuThreads = Number(args.cpuThreads);
|
|
417
|
+
if (!Number.isInteger(args.cpuThreads) || args.cpuThreads < 0 || args.cpuThreads > 64) return fail('--cpu-threads 必须为 0..64 的整数');
|
|
380
418
|
if (!args.audio || !args.out) {
|
|
381
419
|
process.stderr.write(USAGE + '\n');
|
|
382
420
|
return fail('--audio 与 --out 都是必填的。');
|
|
@@ -401,28 +439,52 @@ function main(argv) {
|
|
|
401
439
|
// 与最终文件处于同一文件系统,rename 才能原子发布;每次调用独占暂存目录。
|
|
402
440
|
stagingDir = fs.mkdtempSync(path.join(path.dirname(outputPath), '.drs-transcribe-'));
|
|
403
441
|
const stagingOutput = path.join(stagingDir, 'transcript.txt');
|
|
442
|
+
const segmentsFile = path.join(stagingDir, 'segments.json');
|
|
443
|
+
const hashStarted = Date.now();
|
|
444
|
+
const audioHash = args.cache ? transcriptCache.hashFile(args.audio) : null;
|
|
445
|
+
timing.hash = Date.now() - hashStarted;
|
|
446
|
+
const lookupStarted = Date.now();
|
|
447
|
+
const runtimeBefore = args.cache ? transcriptCache.runtimeIdentity(root, args.model) : null;
|
|
448
|
+
const id = transcriptCache.identity(audioHash, args, runtimeBefore, PY_RUNNER);
|
|
449
|
+
const cached = args.cache && !args.refreshCache ? transcriptCache.read(root, id) : null;
|
|
450
|
+
timing.cacheLookup = Date.now() - lookupStarted;
|
|
451
|
+
if (cached) {
|
|
452
|
+
fs.writeFileSync(stagingOutput, transcriptCache.render(cached.segments, args.timestamps), 'utf8');
|
|
453
|
+
const publishStarted = Date.now();
|
|
454
|
+
fs.renameSync(stagingOutput, outputPath);
|
|
455
|
+
timing.publish = Date.now() - publishStarted;
|
|
456
|
+
timing.total = Date.now() - startedAt;
|
|
457
|
+
process.stdout.write('[transcribe] metrics ' + JSON.stringify({ cacheHit: true, device: cached.device,
|
|
458
|
+
cpuThreads: cached.cpuThreads, duration: cached.duration, timings: timing }) + '\n');
|
|
459
|
+
process.stdout.write('TRANSCRIBED ' + fs.statSync(outputPath).size + ' bytes to ' + args.out + '\nDONE\n');
|
|
460
|
+
return 0;
|
|
461
|
+
}
|
|
404
462
|
|
|
405
463
|
const childEnv = Object.assign({}, process.env);
|
|
464
|
+
const environmentStarted = Date.now();
|
|
406
465
|
|
|
407
466
|
// 1) venv:优先复用已装好的 3.12,没有才让 uv 装。
|
|
408
467
|
// 镜像只用于加速;失败就换直连重试 —— 镜像挂掉不该让用户彻底装不上。
|
|
409
|
-
if (!
|
|
468
|
+
if (!isFileAt(py)) {
|
|
410
469
|
if (uv === null) throw new Error('需要创建 Python 环境,但没有找到 uv。请先安装:' + uvInstallHint(c));
|
|
411
470
|
process.stdout.write('[transcribe] 创建 venv(Python ' + PY_VERSION + '):' + venvDir + '\n');
|
|
412
471
|
const attempts = venvEnvAttempts(childEnv, resolveUvMirror(process.env));
|
|
413
472
|
let lastErr = null;
|
|
473
|
+
let created = false;
|
|
414
474
|
for (let i = 0; i < attempts.length; i++) {
|
|
415
475
|
try {
|
|
416
476
|
runStep(uv, ['venv', '--python', PY_VERSION, venvDir], attempts[i].env, 'uv venv');
|
|
477
|
+
if (!isFileAt(py)) throw new Error('uv venv 未生成 Python 解释器文件:' + py);
|
|
478
|
+
created = true;
|
|
417
479
|
} catch (e) { lastErr = e; }
|
|
418
|
-
if (
|
|
480
|
+
if (created) break;
|
|
419
481
|
// 失败的尝试可能留下半个 venv 目录,重试前先清掉
|
|
420
482
|
try { fs.rmSync(venvDir, { recursive: true, force: true }); } catch (e) { /* 清不掉就让下一次尝试自己报错 */ }
|
|
421
483
|
if (i + 1 < attempts.length) {
|
|
422
484
|
process.stderr.write('[transcribe] 用 ' + attempts[i].label + ' 创建 venv 失败,改用 ' + attempts[i + 1].label + ' 重试…\n');
|
|
423
485
|
}
|
|
424
486
|
}
|
|
425
|
-
if (!
|
|
487
|
+
if (!created) throw (lastErr || new Error('uv venv 失败:' + venvDir));
|
|
426
488
|
}
|
|
427
489
|
|
|
428
490
|
// 2) 健康环境直接运行;不另开 Python 重复 import,也不要求 uv 仍在 PATH。
|
|
@@ -437,6 +499,8 @@ function main(argv) {
|
|
|
437
499
|
childEnv.DRS_LANG = args.language;
|
|
438
500
|
childEnv.DRS_DEVICE = args.device;
|
|
439
501
|
childEnv.DRS_TIMESTAMPS = args.timestamps ? '1' : '0';
|
|
502
|
+
childEnv.DRS_CPU_THREADS = String(args.cpuThreads);
|
|
503
|
+
childEnv.DRS_SEGMENTS = segmentsFile;
|
|
440
504
|
childEnv.DRS_FASTER_WHISPER_VERSION = FASTER_WHISPER_VERSION;
|
|
441
505
|
childEnv.DRS_RUNTIME = path.join(root, 'runtime.json');
|
|
442
506
|
const bootstrapStatus = path.join(stagingDir, 'bootstrap-status.json');
|
|
@@ -444,6 +508,8 @@ function main(argv) {
|
|
|
444
508
|
|
|
445
509
|
const pyScript = path.join(stagingDir, 'transcribe_run.py');
|
|
446
510
|
fs.writeFileSync(pyScript, PY_RUNNER, 'utf8');
|
|
511
|
+
timing.environment = Date.now() - environmentStarted;
|
|
512
|
+
const pythonStarted = Date.now();
|
|
447
513
|
|
|
448
514
|
// 3) 转写(首次会下载模型到 HF_HOME,之后缓存复用)。
|
|
449
515
|
// 只有导入缺失/明确版本不符才允许自举并重试一次,解码/CUDA/推理失败不重装。
|
|
@@ -451,19 +517,47 @@ function main(argv) {
|
|
|
451
517
|
if (needsBootstrap(result, bootstrapStatus)) {
|
|
452
518
|
if (uv === null) throw new Error('需要安装 faster-whisper==' + FASTER_WHISPER_VERSION + ',但没有找到 uv。请先安装:' + uvInstallHint(c));
|
|
453
519
|
process.stdout.write('[transcribe] 安装 faster-whisper==' + FASTER_WHISPER_VERSION + '(清华镜像)…\n');
|
|
520
|
+
const installStarted = Date.now();
|
|
454
521
|
runStep(uv, ['pip', 'install', '--python', py, 'faster-whisper==' + FASTER_WHISPER_VERSION, '-i', PYPI_MIRROR], childEnv, 'faster-whisper 安装');
|
|
522
|
+
timing.dependencyInstall = Date.now() - installStarted;
|
|
455
523
|
fs.rmSync(bootstrapStatus, { force: true });
|
|
456
524
|
runStep(py, [pyScript], childEnv, '转写');
|
|
457
525
|
} else {
|
|
458
526
|
checkStep(result, py, '转写');
|
|
459
527
|
}
|
|
528
|
+
timing.python = Date.now() - pythonStarted - timing.dependencyInstall;
|
|
460
529
|
|
|
461
530
|
const bytes = fs.statSync(stagingOutput).size;
|
|
462
531
|
const verdict = judgeTranscript(bytes);
|
|
463
532
|
if (!verdict.ok) {
|
|
464
533
|
return fail(verdict.message, verdict.code);
|
|
465
534
|
}
|
|
535
|
+
let report = null;
|
|
536
|
+
try {
|
|
537
|
+
const candidate = JSON.parse(fs.readFileSync(segmentsFile, 'utf8'));
|
|
538
|
+
if (transcriptCache.validSegments(candidate.segments) &&
|
|
539
|
+
transcriptCache.render(candidate.segments, args.timestamps) === fs.readFileSync(stagingOutput, 'utf8')) report = candidate;
|
|
540
|
+
} catch (error) { /* A missing diagnostic must not discard a valid transcript. */ }
|
|
541
|
+
const publishStarted = Date.now();
|
|
466
542
|
fs.renameSync(stagingOutput, outputPath);
|
|
543
|
+
timing.publish = Date.now() - publishStarted;
|
|
544
|
+
if (args.cache && report) {
|
|
545
|
+
try {
|
|
546
|
+
const runtimeAfter = transcriptCache.runtimeIdentity(root, args.model);
|
|
547
|
+
// Do not cache audio modified during inference, or a model/environment
|
|
548
|
+
// changed concurrently. A newly bootstrapped environment is eligible.
|
|
549
|
+
if ((!runtimeBefore || runtimeBefore === runtimeAfter) && audioHash === transcriptCache.hashFile(args.audio)) {
|
|
550
|
+
const stored = transcriptCache.write(root, transcriptCache.identity(audioHash, args, runtimeAfter, PY_RUNNER), report);
|
|
551
|
+
if (!stored) process.stderr.write('[transcribe] transcript cache unavailable; current result retained\n');
|
|
552
|
+
}
|
|
553
|
+
} catch (error) {
|
|
554
|
+
process.stderr.write('[transcribe] transcript cache unavailable; current result retained\n');
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
timing.total = Date.now() - startedAt;
|
|
558
|
+
process.stdout.write('[transcribe] metrics ' + JSON.stringify({ cacheHit: false, device: report && report.device,
|
|
559
|
+
cpuThreads: args.cpuThreads, duration: report && report.duration, timings: timing,
|
|
560
|
+
runnerTimings: report && report.timings }) + '\n');
|
|
467
561
|
process.stdout.write('TRANSCRIBED ' + bytes + ' bytes to ' + args.out + '\n');
|
|
468
562
|
process.stdout.write('DONE\n');
|
|
469
563
|
return 0;
|
|
@@ -23,7 +23,7 @@ whenToUse: 用户提供一本书、论文(arXiv/PDF)、视频链接(YouTub
|
|
|
23
23
|
## 输入
|
|
24
24
|
|
|
25
25
|
用户提供:内容链接或本地文件路径。
|
|
26
|
-
可选参数:`type`(auto/book/paper/video/web)、`options`(minWords / fastMode / maxChunks / maxRetries / requireCitations / includeTimestamps / transcribe / whisperModel / language / device / outputDir / tempDir / frontmatter)。
|
|
26
|
+
可选参数:`type`(auto/book/paper/video/web)、`options`(minWords / fastMode / maxChunks / maxRetries / requireCitations / includeTimestamps / transcribe / whisperModel / language / device / cpuThreads / transcriptCache / outputDir / tempDir / frontmatter)。
|
|
27
27
|
|
|
28
28
|
优先调用插件提供的 `deep_read_summarize` 工具,参数为 `{ input, type, options }`。如果当前宿主没有这个工具,按技能末尾提供的 meta / script / args 调用 `workflow` 工具。两种入口执行相同的获取、精读与质量核验。
|
|
29
29
|
|
|
@@ -81,7 +81,9 @@ status: 已完成
|
|
|
81
81
|
3. 都不行 → 降级提示用户手动提供转写文本,或退回 desc 作背景;**绝不阻塞、绝不自动装重依赖**。
|
|
82
82
|
- `options.transcribe`:**默认 true**(无字幕自动转写);设为 `false` 则跳过转写(只用字幕/desc 或降级)。
|
|
83
83
|
- **转写工具链**:脚本自举,本机/用户一致——`uv` 建 Python 3.12 环境 + 清华镜像装 `faster-whisper` + `HF_ENDPOINT=https://hf-mirror.com` 下模型并缓存;脚本是 **Node** 写的,三平台**同一份实现、同一条命令**(`node <脚本路径> --audio <音频> --out <txt>`);转写默认 **CPU**(`options.device` 默认 `cpu`),GPU 需自备 CUDA 运行库(设 `options.device: "auto"`,失败自动回退 CPU);faster-whisper 内置 PyAV 解码音频,**无需单独 ffmpeg**。
|
|
84
|
-
- **⚠️ 首次转写会先下载 small 模型(约 484MB,hf-mirror,非 GitHub
|
|
84
|
+
- **⚠️ 首次转写会先下载 small 模型(约 484MB,hf-mirror,非 GitHub),可能较慢**——执行转写前**先向用户说明**这是正常的一次性下载;之后复用模型文件,新音频仍需推理,不保证秒开。
|
|
85
|
+
- `options.transcriptCache` 默认 true:只有脚本核对音频内容、受管理的模型快照、环境和解码配置后才可复用逐字稿,命中也必须确认本次进程成功并发布本次产物,不能直接使用别的任务的旧文件。缓存含本地文本、有效期 30 天、总量上限 128 MiB;`--clear-cache` 只清理逐字稿。设 false 禁用读写,`--refresh-cache` 可强制重转写。缓存不会跳过精读和独立核验。
|
|
86
|
+
- `options.cpuThreads` 为 0–64 的整数,默认 0 保持库默认策略。记录转写日志的 metrics:cacheHit、实际设备、音频时长与阶段耗时;命中缓存时不要引用上次推理耗时,也不要由此推测 token。笔记核验不能证明音轨听写准确,线程或 GPU 调优需单独比对音频,不自行降低模型或解码门槛。
|
|
85
87
|
- **质量/速度**:small/int8 + VAD 静音过滤,中文质量可用且 CPU 友好;有字幕视频不转写(快)。装不上/失败则降级,不静默。
|
|
86
88
|
- YouTube 用 yt-dlp 抓 CC;未装时**绝不下载 exe 二进制**(GitHub 直连易卡死),按系统装(Windows `winget install yt-dlp.yt-dlp` / macOS `brew install yt-dlp` / 任意平台 `pip install -U yt-dlp`);仍不可用则转写或降级。
|
|
87
89
|
- 运行 yt-dlp 加 `--socket-timeout 15 --retries 3` 防超时。
|