@gobing-ai/knowledge-kit 0.1.29 → 0.1.30
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/.claude-plugin/marketplace.json +1 -1
- package/dist/board/api.js +8724 -3861
- package/dist/board/collect/index.js +69 -1
- package/dist/board/daily-voice/index.js +474 -265
- package/dist/board/itc/index.js +69 -1
- package/dist/board/wiki/index.css +1305 -0
- package/dist/board/wiki/index.js +1621 -0
- package/dist/index.js +34689 -28532
- package/package.json +1 -1
- package/plugins/generations/content-gen/dist/index.js +14 -1
- package/plugins/generations/core-facts-gen/dist/index.js +14 -1
- package/plugins/generations/daily-article-gen/dist/index.js +14 -1
- package/plugins/generations/dailynews-gen/dist/index.js +14 -1
- package/plugins/generations/episode-plan-gen/dist/index.js +32 -2
- package/plugins/generations/episode-plan-gen/src/index.ts +19 -1
- package/plugins/generations/gemini-tts/dist/index.js +14 -1
- package/plugins/generations/image-gen/dist/index.js +14 -1
- package/plugins/generations/music-gen/dist/index.js +15 -2
- package/plugins/generations/news-report-gen/dist/index.js +14 -1
- package/plugins/generations/vibe-voice-tts/dist/index.js +14 -1
- package/plugins/generations/video-gen/README.md +245 -8
- package/plugins/generations/video-gen/dist/index.js +22447 -4763
- package/plugins/generations/video-gen/package.json +1 -0
- package/plugins/generations/video-gen/presets/formats/avatar.yaml +5 -0
- package/plugins/generations/video-gen/presets/formats/editorial.yaml +6 -0
- package/plugins/generations/video-gen/presets/formats/hybrid-pip.yaml +5 -0
- package/plugins/generations/video-gen/presets/styles/daily-ai.yaml +5 -0
- package/plugins/generations/video-gen/presets/styles/neutral.yaml +3 -0
- package/plugins/generations/video-gen/python/colab_comfyui_h3.py +322 -0
- package/plugins/generations/video-gen/python/comfyui-h3-i2v-api.json +47 -0
- package/plugins/generations/video-gen/python/comfyui-h3-models.json +32 -0
- package/plugins/generations/video-gen/python/comfyui_model_cache.py +388 -0
- package/plugins/generations/video-gen/python/drive_client.py +187 -0
- package/plugins/generations/video-gen/src/brief-cli.ts +65 -0
- package/plugins/generations/video-gen/src/brief.ts +464 -0
- package/plugins/generations/video-gen/src/ccu-ledger.ts +206 -3
- package/plugins/generations/video-gen/src/colab-runner.ts +346 -35
- package/plugins/generations/video-gen/src/index.ts +141 -109
- package/plugins/generations/video-gen/src/inputs.ts +162 -4
- package/plugins/generations/video-gen/src/layout.ts +33 -0
- package/plugins/generations/video-gen/src/props.ts +27 -3
- package/plugins/generations/video-gen/src/remotion/AvatarReel.tsx +17 -1
- package/plugins/generations/video-gen/src/remotion/EditorialReel.tsx +17 -1
- package/plugins/generations/video-gen/src/remotion/Root.tsx +2 -0
- package/plugins/generations/video-gen/src/remotion/engine.ts +3 -7
- package/plugins/generations/video-gen/src/render.ts +25 -0
- package/plugins/generations/video-gen/src/request.ts +150 -20
- package/plugins/generations/video-gen/src/visual-provider.ts +116 -3
- package/plugins/generations/voice-gen/dist/index.js +14 -1
- package/plugins/generations/voxcpm-tts/dist/index.js +14 -1
- package/plugins/ingestions/aihot-ingest/dist/index.js +14 -1
- package/plugins/ingestions/horizon-ingest/dist/index.js +14 -1
- package/plugins/ingestions/last30days-ingest/dist/index.js +14 -1
- package/plugins/ingestions/web-search/dist/index.js +14 -1
- package/plugins/kk/config.example.yaml +1 -1
- package/plugins/kk/mcp-tools.yaml +47 -0
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/itc-surfdash-locales.json +42 -0
- package/plugins/kk/scripts/daily-stages.ts +87 -6
- package/plugins/kk/scripts/kk-workflow-stages.ts +64 -9
- package/plugins/kk/scripts/video-stages.ts +332 -0
- package/plugins/kk/scripts/wiki-normalize-audio.ts +354 -0
- package/plugins/kk/scripts/wiki-normalize-document.ts +495 -0
- package/plugins/kk/scripts/wiki-normalize-stages.ts +96 -0
- package/plugins/kk/scripts/wiki-stage-runtime.ts +39 -0
- package/plugins/kk/skills/news-editorial/SKILL.md +2 -1
- package/plugins/kk/workflows/kk-collect.yaml +10 -0
- package/plugins/kk/workflows/kk-news-generate.yaml +70 -8
- package/plugins/kk/workflows/kk-smart-seo.yaml +8 -0
- package/plugins/kk/workflows/kk-storm-research.yaml +10 -0
- package/plugins/kk/workflows/kk-video-generate.yaml +169 -0
- package/plugins/kk/workflows/kk-wiki-digest.yaml +49 -0
- package/plugins/publishings/bilibili-pub/dist/index.js +281 -268
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +202 -0
- package/plugins/publishings/cnblogs-pub/dist/index.js +281 -268
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +202 -0
- package/plugins/publishings/csdn-pub/dist/index.js +281 -268
- package/plugins/publishings/csdn-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/emdash-pub/dist/index.js +33 -3
- package/plugins/publishings/infoq-pub/dist/index.js +281 -268
- package/plugins/publishings/infoq-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/jike-pub/dist/index.js +281 -268
- package/plugins/publishings/jike-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/juejin-pub/dist/index.js +281 -268
- package/plugins/publishings/juejin-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/linkedin-pub/dist/index.js +281 -268
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/medium-pub/dist/index.js +281 -268
- package/plugins/publishings/medium-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/podcast-pub/dist/index.js +39 -9
- package/plugins/publishings/qiita-pub/dist/index.js +33 -3
- package/plugins/publishings/shipinhao-pub/dist/index.js +281 -268
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +175 -0
- package/plugins/publishings/sspai-pub/dist/index.js +281 -268
- package/plugins/publishings/sspai-pub/dist/profile-check.js +202 -0
- package/plugins/publishings/substack-pub/dist/index.js +281 -268
- package/plugins/publishings/substack-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/surfdash-pub/dist/index.js +99 -39
- package/plugins/publishings/surfdash-pub/plugin.json +54 -0
- package/plugins/publishings/surfdash-pub/src/index.ts +36 -5
- package/plugins/publishings/threads-pub/dist/index.js +281 -268
- package/plugins/publishings/threads-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/wechatmp-pub/dist/index.js +665 -451
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +215 -3
- package/plugins/publishings/weibo-pub/dist/index.js +281 -268
- package/plugins/publishings/weibo-pub/dist/profile-check.js +189 -1
- package/plugins/publishings/x-pub/dist/index.js +281 -268
- package/plugins/publishings/x-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/xhs-pub/dist/index.js +281 -268
- package/plugins/publishings/xhs-pub/dist/profile-check.js +119 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +281 -268
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +202 -0
- package/plugins/publishings/youtube-pub/dist/index.js +14 -1
- package/plugins/publishings/zenn-pub/dist/index.js +37 -7
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Standalone video workflow stages (D91 R4–R5, task 0457) — sibling of
|
|
4
|
+
* `kk-workflow-stages.ts`, dispatched from it by `kk stage run video-prepare|video-verify`.
|
|
5
|
+
*
|
|
6
|
+
* video-prepare <brief_file> <run_dir> <run_id> [runtime_file]
|
|
7
|
+
* video-verify <run_dir> <run_id>
|
|
8
|
+
*
|
|
9
|
+
* WHY these live outside the plugin: the plugin is a generator (request in → Content out) and must
|
|
10
|
+
* stay that way. Resolving an authored brief into a request, and proving the rendered MP4 matches the
|
|
11
|
+
* emitted Content, are workflow concerns — the standalone workflow's, not the executor's.
|
|
12
|
+
*
|
|
13
|
+
* Node/Bun builtins only, like its sibling: this file is resolved from the installed package or from
|
|
14
|
+
* a checkout, and it shells the video plugin's own resolver/entry rather than importing them.
|
|
15
|
+
*
|
|
16
|
+
* Fail-closed contract: every check runs before the next thing is allowed to happen, a nonzero exit
|
|
17
|
+
* is the signal to the workflow's default `onError: fail`, and the verification receipt is written
|
|
18
|
+
* only after every check passed.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { spawnSync } from 'node:child_process';
|
|
22
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, statSync, writeFileSync } from 'node:fs';
|
|
23
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
24
|
+
|
|
25
|
+
/** Output geometry the publishers accept; a video outside it is not a deliverable. */
|
|
26
|
+
const VIDEO_WIDTH = 1080;
|
|
27
|
+
const VIDEO_HEIGHT = 1920;
|
|
28
|
+
const VIDEO_FPS = 30;
|
|
29
|
+
/** Content/metadata duration agreement: container rounding is allowed, drift is not. */
|
|
30
|
+
const DURATION_TOLERANCE_SEC = 0.25;
|
|
31
|
+
/** `ffprobe` reads one header; a minute is generous and bounds a hung probe. */
|
|
32
|
+
const PROBE_TIMEOUT_MS = 60_000;
|
|
33
|
+
|
|
34
|
+
/** One run's artifact paths under `<run_dir>/<run_id>/`. */
|
|
35
|
+
interface RunPaths {
|
|
36
|
+
root: string;
|
|
37
|
+
request: string;
|
|
38
|
+
content: string;
|
|
39
|
+
video: string;
|
|
40
|
+
receipt: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A stage refusal. Thrown, never `process.exit`: the dispatch in `kk-workflow-stages.ts` turns it
|
|
45
|
+
* into the process status, and a test can assert the message without killing the runner.
|
|
46
|
+
*/
|
|
47
|
+
export class VideoStageError extends Error {
|
|
48
|
+
constructor(message: string) {
|
|
49
|
+
super(`video-stage: ${message}`);
|
|
50
|
+
this.name = 'VideoStageError';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function fail(message: string): never {
|
|
55
|
+
throw new VideoStageError(message);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function info(message: string): void {
|
|
59
|
+
process.stdout.write(`${message}\n`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Validate the engine-supplied run id before it becomes a path segment: one plain segment, never a
|
|
64
|
+
* separator, never a parent reference. A workflow run id is a UUID in practice, but this stage also
|
|
65
|
+
* runs from a hand-written invocation.
|
|
66
|
+
*/
|
|
67
|
+
export function assertRunId(runId: string): string {
|
|
68
|
+
if (runId === '' || runId.includes('/') || runId.includes('\\') || runId.includes('..')) {
|
|
69
|
+
fail(`invalid run id '${runId}' — expected one path segment (letters, digits, '.', '_' or '-')`);
|
|
70
|
+
}
|
|
71
|
+
if (!/^[A-Za-z0-9._-]+$/.test(runId)) {
|
|
72
|
+
fail(`invalid run id '${runId}' — expected letters, digits, '.', '_' or '-'`);
|
|
73
|
+
}
|
|
74
|
+
return runId;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Absolute run paths, built from the validated id. */
|
|
78
|
+
export function runPaths(runDir: string, runId: string): RunPaths {
|
|
79
|
+
const root = join(resolve(runDir), assertRunId(runId));
|
|
80
|
+
return {
|
|
81
|
+
root,
|
|
82
|
+
request: join(root, 'request.json'),
|
|
83
|
+
content: join(root, 'content.json'),
|
|
84
|
+
video: join(root, 'video.mp4'),
|
|
85
|
+
receipt: join(root, 'verification.json'),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Locate the video-gen plugin next to this script's `plugins/` tree — same sibling layout in a
|
|
91
|
+
* checkout (`<repo>/plugins/kk/scripts` → `<repo>/plugins/generations/video-gen`) and in the
|
|
92
|
+
* installed package bundle.
|
|
93
|
+
*/
|
|
94
|
+
export function videoPluginDir(scriptDir: string = import.meta.dir): string | null {
|
|
95
|
+
const candidate = resolve(scriptDir, '..', '..', 'generations', 'video-gen');
|
|
96
|
+
return existsSync(join(candidate, 'src', 'brief-cli.ts')) ? candidate : null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function requireFile(path: string, label: string): void {
|
|
100
|
+
if (!existsSync(path) || !statSync(path).isFile() || statSync(path).size === 0) {
|
|
101
|
+
fail(`${label} ${path} is missing or empty`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Run one bounded argv; returns stdout and the exit status (never throws on a nonzero exit). */
|
|
106
|
+
function run(argv: string[], timeoutMs: number): { code: number; stdout: string; stderr: string } {
|
|
107
|
+
const [command, ...args] = argv;
|
|
108
|
+
if (command === undefined) fail('cannot run an empty command');
|
|
109
|
+
const result = spawnSync(command, args, { timeout: timeoutMs, encoding: 'utf-8' });
|
|
110
|
+
return {
|
|
111
|
+
code: result.status ?? 1,
|
|
112
|
+
stdout: typeof result.stdout === 'string' ? result.stdout : '',
|
|
113
|
+
stderr: typeof result.stderr === 'string' ? result.stderr : '',
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* `video-prepare <brief_file> <run_dir> <run_id> [runtime_file]` — resolve the brief into the
|
|
119
|
+
* executor's request, in a run-scoped directory.
|
|
120
|
+
*
|
|
121
|
+
* Refuses to reuse a run directory that already holds outputs: a retry gets a fresh run id, so a
|
|
122
|
+
* stale render can never be mistaken for this run's media (the reason the output probe and receipt
|
|
123
|
+
* are separate from render success at all).
|
|
124
|
+
*/
|
|
125
|
+
export function videoPrepare(args: string[]): void {
|
|
126
|
+
const [briefFile = '', runDir = '', runId = '', runtimeFile = ''] = args;
|
|
127
|
+
if (briefFile === '' || runDir === '' || runId === '') {
|
|
128
|
+
fail('usage: video-prepare <brief_file> <run_dir> <run_id> [runtime_file]');
|
|
129
|
+
}
|
|
130
|
+
const paths = runPaths(runDir, runId);
|
|
131
|
+
for (const [label, path] of [
|
|
132
|
+
['content', paths.content],
|
|
133
|
+
['video', paths.video],
|
|
134
|
+
['verification receipt', paths.receipt],
|
|
135
|
+
] as const) {
|
|
136
|
+
if (existsSync(path)) {
|
|
137
|
+
fail(
|
|
138
|
+
`run ${runId} already holds ${label} at ${path} — refusing to prepare over existing run outputs; use a fresh run id`,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const pluginDir = videoPluginDir();
|
|
143
|
+
if (pluginDir === null) {
|
|
144
|
+
fail(
|
|
145
|
+
'video-gen plugin not found beside this stage script — build the bundle (bun scripts/bundle-plugins.ts) or refresh the kk package',
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
const briefPath = isAbsolute(briefFile) ? briefFile : resolve(briefFile);
|
|
149
|
+
requireFile(briefPath, 'brief');
|
|
150
|
+
mkdirSync(paths.root, { recursive: true });
|
|
151
|
+
const request = run(
|
|
152
|
+
[
|
|
153
|
+
process.execPath,
|
|
154
|
+
join(pluginDir, 'src', 'brief-cli.ts'),
|
|
155
|
+
'--brief',
|
|
156
|
+
briefPath,
|
|
157
|
+
'--out',
|
|
158
|
+
paths.request,
|
|
159
|
+
'--run-dir',
|
|
160
|
+
paths.root,
|
|
161
|
+
...(runtimeFile === ''
|
|
162
|
+
? []
|
|
163
|
+
: ['--runtime-file', isAbsolute(runtimeFile) ? runtimeFile : resolve(runtimeFile)]),
|
|
164
|
+
],
|
|
165
|
+
PROBE_TIMEOUT_MS * 2,
|
|
166
|
+
);
|
|
167
|
+
if (request.code !== 0) {
|
|
168
|
+
fail(`brief resolution failed (${request.stderr.trim() || `exit ${request.code}`})`);
|
|
169
|
+
}
|
|
170
|
+
requireFile(paths.request, 'prepared request');
|
|
171
|
+
info(`video-prepare: ${paths.request} (${request.stdout.trim()})`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** The `ffprobe` view of one file: the stream and format facts verification is allowed to read. */
|
|
175
|
+
interface ProbeFacts {
|
|
176
|
+
video: { codec?: string; width?: number; height?: number; fps?: number } | null;
|
|
177
|
+
hasAudio: boolean;
|
|
178
|
+
audioCodec?: string;
|
|
179
|
+
durationSec: number;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** `ffprobe` argv: local protocols only, JSON output, no shell. */
|
|
183
|
+
export function buildProbeArgv(videoPath: string): string[] {
|
|
184
|
+
return [
|
|
185
|
+
'ffprobe',
|
|
186
|
+
'-v',
|
|
187
|
+
'error',
|
|
188
|
+
'-protocol_whitelist',
|
|
189
|
+
'file,pipe',
|
|
190
|
+
'-show_entries',
|
|
191
|
+
'stream=codec_type,codec_name,width,height,avg_frame_rate:format=duration',
|
|
192
|
+
'-of',
|
|
193
|
+
'json',
|
|
194
|
+
videoPath,
|
|
195
|
+
];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Parse `ffprobe` JSON into the facts verification needs; a malformed payload is a hard failure. */
|
|
199
|
+
export function parseProbeFacts(stdout: string): ProbeFacts {
|
|
200
|
+
let parsed: unknown;
|
|
201
|
+
try {
|
|
202
|
+
parsed = JSON.parse(stdout);
|
|
203
|
+
} catch {
|
|
204
|
+
fail('ffprobe produced no readable JSON');
|
|
205
|
+
}
|
|
206
|
+
const record = parsed as { streams?: unknown; format?: unknown };
|
|
207
|
+
const streams = Array.isArray(record.streams) ? record.streams : [];
|
|
208
|
+
let video: ProbeFacts['video'] = null;
|
|
209
|
+
let hasAudio = false;
|
|
210
|
+
let audioCodec: string | undefined;
|
|
211
|
+
for (const entry of streams) {
|
|
212
|
+
const stream = entry as Record<string, unknown>;
|
|
213
|
+
if (stream.codec_type === 'video' && video === null) {
|
|
214
|
+
const rate = typeof stream.avg_frame_rate === 'string' ? stream.avg_frame_rate.split('/') : [];
|
|
215
|
+
const numerator = Number(rate[0]);
|
|
216
|
+
const denominator = Number(rate[1] ?? '1');
|
|
217
|
+
video = {
|
|
218
|
+
...(typeof stream.codec_name === 'string' ? { codec: stream.codec_name } : {}),
|
|
219
|
+
...(typeof stream.width === 'number' ? { width: stream.width } : {}),
|
|
220
|
+
...(typeof stream.height === 'number' ? { height: stream.height } : {}),
|
|
221
|
+
...(Number.isFinite(numerator) && Number.isFinite(denominator) && denominator !== 0
|
|
222
|
+
? { fps: numerator / denominator }
|
|
223
|
+
: {}),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
if (stream.codec_type === 'audio') {
|
|
227
|
+
hasAudio = true;
|
|
228
|
+
if (typeof stream.codec_name === 'string') audioCodec = stream.codec_name;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const format = record.format as Record<string, unknown> | undefined;
|
|
232
|
+
const durationSec = typeof format?.duration === 'string' ? Number.parseFloat(format.duration) : Number.NaN;
|
|
233
|
+
if (!Number.isFinite(durationSec) || durationSec <= 0) fail('ffprobe reported no positive duration');
|
|
234
|
+
return { video, hasAudio, ...(audioCodec === undefined ? {} : { audioCodec }), durationSec };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Every way a rendered file can fail to be this run's deliverable, checked before the receipt. */
|
|
238
|
+
export function assertProbeMatches(facts: ProbeFacts, contentDurationSec: number): void {
|
|
239
|
+
const video = facts.video;
|
|
240
|
+
if (video === null) fail('the rendered file carries no video stream');
|
|
241
|
+
if (video.codec !== 'h264') fail(`expected H.264 video, got ${video.codec ?? 'an unknown codec'}`);
|
|
242
|
+
if (video.width !== VIDEO_WIDTH || video.height !== VIDEO_HEIGHT) {
|
|
243
|
+
fail(`expected ${VIDEO_WIDTH}x${VIDEO_HEIGHT}, got ${video.width}x${video.height}`);
|
|
244
|
+
}
|
|
245
|
+
if (video.fps === undefined || Math.abs(video.fps - VIDEO_FPS) > 0.5) {
|
|
246
|
+
fail(`expected ${VIDEO_FPS} fps, got ${video.fps ?? 'an unreadable frame rate'}`);
|
|
247
|
+
}
|
|
248
|
+
if (!facts.hasAudio) fail('the rendered file carries no audio stream');
|
|
249
|
+
if (facts.audioCodec !== 'aac') fail(`expected AAC audio, got ${facts.audioCodec ?? 'an unknown codec'}`);
|
|
250
|
+
if (Math.abs(facts.durationSec - contentDurationSec) > DURATION_TOLERANCE_SEC) {
|
|
251
|
+
fail(
|
|
252
|
+
`rendered duration ${facts.durationSec.toFixed(2)}s disagrees with Content metadata ${contentDurationSec.toFixed(2)}s (tolerance ${DURATION_TOLERANCE_SEC}s)`,
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* `video-verify <run_dir> <run_id>` — prove the MP4 is *this run's* fresh deliverable and that it
|
|
259
|
+
* agrees with the emitted Content, then write the receipt.
|
|
260
|
+
*/
|
|
261
|
+
export function videoVerify(args: string[]): void {
|
|
262
|
+
const [runDir = '', runId = ''] = args;
|
|
263
|
+
if (runDir === '' || runId === '') fail('usage: video-verify <run_dir> <run_id>');
|
|
264
|
+
const paths = runPaths(runDir, runId);
|
|
265
|
+
requireFile(paths.request, 'prepared request');
|
|
266
|
+
requireFile(paths.content, 'render Content');
|
|
267
|
+
requireFile(paths.video, 'rendered video');
|
|
268
|
+
|
|
269
|
+
let content: Record<string, unknown>;
|
|
270
|
+
try {
|
|
271
|
+
content = JSON.parse(readFileSync(paths.content, 'utf-8')) as Record<string, unknown>;
|
|
272
|
+
} catch (error: unknown) {
|
|
273
|
+
fail(
|
|
274
|
+
`render Content ${paths.content} is not readable JSON: ${error instanceof Error ? error.message : String(error)}`,
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
const metadata = (content.metadata ?? {}) as Record<string, unknown>;
|
|
278
|
+
if (content.format !== 'video') fail(`render Content format is '${String(content.format)}', expected 'video'`);
|
|
279
|
+
const declaredRaw = metadata.videoPath;
|
|
280
|
+
if (typeof declaredRaw !== 'string' || declaredRaw === '') fail('render Content carries no metadata.videoPath');
|
|
281
|
+
const declared = isAbsolute(declaredRaw) ? declaredRaw : resolve(paths.root, declaredRaw);
|
|
282
|
+
const declaredReal = canonical(declared);
|
|
283
|
+
if (declaredReal === null) fail(`Content points at ${declaredRaw}, which does not exist`);
|
|
284
|
+
if (declaredReal !== canonical(paths.video)) {
|
|
285
|
+
fail(`Content points at ${declaredRaw}, not this run's ${paths.video} — stale or mismatched output`);
|
|
286
|
+
}
|
|
287
|
+
const contentDurationSec = typeof metadata.durationSec === 'number' ? metadata.durationSec : Number.NaN;
|
|
288
|
+
if (!Number.isFinite(contentDurationSec) || contentDurationSec <= 0) {
|
|
289
|
+
fail('render Content carries no positive metadata.durationSec');
|
|
290
|
+
}
|
|
291
|
+
// Freshness: the media must be at least as new as the request that asked for it.
|
|
292
|
+
const requestMtime = statSync(paths.request).mtimeMs;
|
|
293
|
+
const videoMtime = statSync(paths.video).mtimeMs;
|
|
294
|
+
if (videoMtime < requestMtime) {
|
|
295
|
+
fail(`rendered video ${paths.video} predates this run's request — stale render`);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const probe = run(buildProbeArgv(paths.video), PROBE_TIMEOUT_MS);
|
|
299
|
+
if (probe.code !== 0) fail(`ffprobe failed on ${paths.video}: ${probe.stderr.trim() || `exit ${probe.code}`}`);
|
|
300
|
+
const facts = parseProbeFacts(probe.stdout);
|
|
301
|
+
assertProbeMatches(facts, contentDurationSec);
|
|
302
|
+
|
|
303
|
+
const payload = {
|
|
304
|
+
schemaVersion: 'video-verification/v1',
|
|
305
|
+
runId,
|
|
306
|
+
requestPath: paths.request,
|
|
307
|
+
contentPath: paths.content,
|
|
308
|
+
videoPath: paths.video,
|
|
309
|
+
video: {
|
|
310
|
+
codec: facts.video?.codec,
|
|
311
|
+
width: facts.video?.width,
|
|
312
|
+
height: facts.video?.height,
|
|
313
|
+
fps: facts.video?.fps,
|
|
314
|
+
audioCodec: facts.audioCodec,
|
|
315
|
+
durationSec: Number(facts.durationSec.toFixed(3)),
|
|
316
|
+
},
|
|
317
|
+
contentDurationSec,
|
|
318
|
+
toleranceSec: DURATION_TOLERANCE_SEC,
|
|
319
|
+
status: 'PASS',
|
|
320
|
+
};
|
|
321
|
+
writeFileSync(paths.receipt, `${JSON.stringify(payload, null, 4)}\n`);
|
|
322
|
+
info(`video-verify: PASS ${paths.video} (${facts.durationSec.toFixed(2)}s) → ${paths.receipt}`);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** `realpathSync` when the path exists, else `null` (a missing file is not a mismatch). */
|
|
326
|
+
function canonical(path: string): string | null {
|
|
327
|
+
try {
|
|
328
|
+
return realpathSync(path);
|
|
329
|
+
} catch {
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, statSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { basename, join } from 'node:path';
|
|
5
|
+
import {
|
|
6
|
+
findExecutableOnPath,
|
|
7
|
+
type ProcessRunner,
|
|
8
|
+
type ProcessRunResult,
|
|
9
|
+
WIKI_JOB_DEADLINE_MS,
|
|
10
|
+
WIKI_NORM_TEXT_MAX_BYTES,
|
|
11
|
+
} from './wiki-normalize-document';
|
|
12
|
+
import { NormalizeStageError, type WikiNormalizeManifest } from './wiki-normalize-stages';
|
|
13
|
+
import { wikiStageRuntime } from './wiki-stage-runtime';
|
|
14
|
+
|
|
15
|
+
export const WIKI_AUDIO_MAX_SEC = 300;
|
|
16
|
+
export const WIKI_AUDIO_WORDS_MAX_BYTES = 4 * 1024 * 1024;
|
|
17
|
+
|
|
18
|
+
export type AudioSourceLocator = { type: 'time'; startSec: number; endSec: number };
|
|
19
|
+
|
|
20
|
+
export interface AudioNormalizationResult {
|
|
21
|
+
version: 1;
|
|
22
|
+
inputId: string;
|
|
23
|
+
captureId: string;
|
|
24
|
+
originalSha256: string;
|
|
25
|
+
mediaKind: 'audio';
|
|
26
|
+
normalizer: { name: string; version: string; parametersHash: string };
|
|
27
|
+
text: string;
|
|
28
|
+
segments: { text: string; locator: AudioSourceLocator }[];
|
|
29
|
+
warnings: string[];
|
|
30
|
+
bounds?: { durationSec: number };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface AudioCapabilities {
|
|
34
|
+
videoGenDir: string;
|
|
35
|
+
uv: string;
|
|
36
|
+
ffmpeg: string;
|
|
37
|
+
ffprobe: string;
|
|
38
|
+
modelDir: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function sha256Hex(input: string | Buffer): string {
|
|
42
|
+
return createHash('sha256').update(input).digest('hex');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function runProcessWithEnv(
|
|
46
|
+
cmd: string,
|
|
47
|
+
args: string[],
|
|
48
|
+
timeoutMs: number,
|
|
49
|
+
env?: Record<string, string | undefined>,
|
|
50
|
+
): Promise<ProcessRunResult> {
|
|
51
|
+
return wikiStageRuntime.runWikiNormalizerProcess(cmd, args, timeoutMs, env);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function resolveVideoGenDir(env: Record<string, string | undefined> = process.env): string | undefined {
|
|
55
|
+
const dir = env.KK_VIDEO_GEN_DIR ?? wikiStageRuntime.discoverWikiCaptionWorker(env);
|
|
56
|
+
return dir &&
|
|
57
|
+
existsSync(join(dir, 'pyproject.toml')) &&
|
|
58
|
+
existsSync(join(dir, 'uv.lock')) &&
|
|
59
|
+
existsSync(join(dir, 'python', 'align_captions.py'))
|
|
60
|
+
? dir
|
|
61
|
+
: undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function probeAudioCapabilities(env: Record<string, string | undefined> = process.env): AudioCapabilities {
|
|
65
|
+
const videoGenDir = resolveVideoGenDir(env);
|
|
66
|
+
if (!videoGenDir) {
|
|
67
|
+
throw new NormalizeStageError('capability.unavailable', 'video-gen caption worker');
|
|
68
|
+
}
|
|
69
|
+
const pathEnv = env.PATH ?? '';
|
|
70
|
+
const uv = findExecutableOnPath('uv', pathEnv);
|
|
71
|
+
if (!uv) throw new NormalizeStageError('capability.unavailable', 'uv');
|
|
72
|
+
const ffmpeg = findExecutableOnPath('ffmpeg', pathEnv);
|
|
73
|
+
if (!ffmpeg) throw new NormalizeStageError('capability.unavailable', 'ffmpeg');
|
|
74
|
+
const ffprobe = findExecutableOnPath('ffprobe', pathEnv);
|
|
75
|
+
if (!ffprobe) throw new NormalizeStageError('capability.unavailable', 'ffprobe');
|
|
76
|
+
|
|
77
|
+
const modelDir = env.KK_WIKI_ASR_MODEL_DIR?.trim();
|
|
78
|
+
if (!modelDir || !existsSync(modelDir) || !existsSync(join(modelDir, 'model.bin'))) {
|
|
79
|
+
throw new NormalizeStageError('capability.unavailable', 'KK_WIKI_ASR_MODEL_DIR (model.bin)');
|
|
80
|
+
}
|
|
81
|
+
if (!existsSync(join(env.UV_PROJECT_ENVIRONMENT ?? join(videoGenDir, '.venv'), 'bin', 'python'))) {
|
|
82
|
+
throw new NormalizeStageError('capability.unavailable', 'provisioned video-gen Python environment');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return { videoGenDir, uv, ffmpeg, ffprobe, modelDir };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function readWavDataBytes(wavPath: string): number {
|
|
89
|
+
if (statSync(wavPath).size > 302 * 32000 + 65536) {
|
|
90
|
+
throw new NormalizeStageError('budget.exceeded', 'decoded audio exceeds bounded PCM output');
|
|
91
|
+
}
|
|
92
|
+
const buf = readFileSync(wavPath);
|
|
93
|
+
if (buf.length < 44 || buf.subarray(0, 4).toString('ascii') !== 'RIFF') {
|
|
94
|
+
throw new NormalizeStageError('media.invalid', 'invalid decoded WAV header');
|
|
95
|
+
}
|
|
96
|
+
let offset = 12;
|
|
97
|
+
while (offset + 8 <= buf.length) {
|
|
98
|
+
const chunkId = buf.subarray(offset, offset + 4).toString('ascii');
|
|
99
|
+
const chunkSize = buf.readUInt32LE(offset + 4);
|
|
100
|
+
if (chunkId === 'data') {
|
|
101
|
+
return Math.min(chunkSize, Math.max(0, buf.length - (offset + 8)));
|
|
102
|
+
}
|
|
103
|
+
offset += 8 + chunkSize + (chunkSize % 2);
|
|
104
|
+
}
|
|
105
|
+
throw new NormalizeStageError('media.invalid', 'missing WAV data chunk');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
interface WorkerWord {
|
|
109
|
+
word: string;
|
|
110
|
+
startSec: number;
|
|
111
|
+
endSec: number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function buildAudioSegments(
|
|
115
|
+
words: WorkerWord[],
|
|
116
|
+
decodedDurationSec: number,
|
|
117
|
+
): { text: string; segments: { text: string; locator: AudioSourceLocator }[] } {
|
|
118
|
+
if (!Array.isArray(words) || words.length === 0) {
|
|
119
|
+
throw new NormalizeStageError('recognition.empty', 'audio contains no recognized speech');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let prevStart = -1;
|
|
123
|
+
for (const w of words) {
|
|
124
|
+
if (
|
|
125
|
+
typeof w?.word !== 'string' ||
|
|
126
|
+
w.word.trim() === '' ||
|
|
127
|
+
!Number.isFinite(w.startSec) ||
|
|
128
|
+
!Number.isFinite(w.endSec) ||
|
|
129
|
+
w.startSec < 0 ||
|
|
130
|
+
w.endSec < w.startSec ||
|
|
131
|
+
w.endSec > decodedDurationSec + 0.05 ||
|
|
132
|
+
w.startSec < prevStart
|
|
133
|
+
) {
|
|
134
|
+
throw new NormalizeStageError('media.invalid', 'recognition.invalid: out-of-bounds or non-monotonic word');
|
|
135
|
+
}
|
|
136
|
+
prevStart = w.startSec;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const segments: { text: string; locator: AudioSourceLocator }[] = [];
|
|
140
|
+
let group: WorkerWord[] = [];
|
|
141
|
+
|
|
142
|
+
const flush = () => {
|
|
143
|
+
if (group.length === 0) return;
|
|
144
|
+
const first = group[0];
|
|
145
|
+
const last = group[group.length - 1];
|
|
146
|
+
if (!first || !last) return;
|
|
147
|
+
segments.push({
|
|
148
|
+
text: group.map((g) => g.word.trim()).join(' '),
|
|
149
|
+
locator: {
|
|
150
|
+
type: 'time',
|
|
151
|
+
startSec: first.startSec,
|
|
152
|
+
endSec: Math.min(decodedDurationSec, last.endSec),
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
group = [];
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
for (const w of words) {
|
|
159
|
+
const last = group[group.length - 1];
|
|
160
|
+
if (last && (w.startSec - last.endSec >= 0.8 || group.length >= 30)) {
|
|
161
|
+
flush();
|
|
162
|
+
}
|
|
163
|
+
group.push(w);
|
|
164
|
+
}
|
|
165
|
+
flush();
|
|
166
|
+
|
|
167
|
+
const text = segments.map((s) => s.text).join('\n\n');
|
|
168
|
+
if (text.trim() === '') {
|
|
169
|
+
throw new NormalizeStageError('recognition.empty', 'empty transcript');
|
|
170
|
+
}
|
|
171
|
+
if (Buffer.byteLength(text, 'utf8') > WIKI_NORM_TEXT_MAX_BYTES) {
|
|
172
|
+
throw new NormalizeStageError('budget.exceeded', `transcript exceeds ${WIKI_NORM_TEXT_MAX_BYTES} bytes`);
|
|
173
|
+
}
|
|
174
|
+
return { text, segments };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function normalizeAudio(
|
|
178
|
+
ctx: { manifest: WikiNormalizeManifest; originalPath: string },
|
|
179
|
+
deps: {
|
|
180
|
+
env?: Record<string, string | undefined>;
|
|
181
|
+
runner?: ProcessRunner;
|
|
182
|
+
deadlineMs?: number;
|
|
183
|
+
} = {},
|
|
184
|
+
): Promise<AudioNormalizationResult> {
|
|
185
|
+
const env = deps.env ?? process.env;
|
|
186
|
+
const caps = probeAudioCapabilities(env);
|
|
187
|
+
const runner: ProcessRunner =
|
|
188
|
+
deps.runner ?? ((cmd, args, timeoutMs) => runProcessWithEnv(cmd, args, timeoutMs, env));
|
|
189
|
+
const deadlineMs = deps.deadlineMs ?? WIKI_JOB_DEADLINE_MS;
|
|
190
|
+
const deadlineAt = Date.now() + deadlineMs;
|
|
191
|
+
const remaining = (limit = deadlineMs) => {
|
|
192
|
+
const ms = deadlineAt - Date.now();
|
|
193
|
+
if (ms <= 0) throw new NormalizeStageError('deadline', 'audio normalization job deadline exceeded');
|
|
194
|
+
return Math.min(limit, ms);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const probeRes = await runner(
|
|
198
|
+
caps.ffprobe,
|
|
199
|
+
[
|
|
200
|
+
'-v',
|
|
201
|
+
'error',
|
|
202
|
+
'-protocol_whitelist',
|
|
203
|
+
'file,pipe',
|
|
204
|
+
'-show_entries',
|
|
205
|
+
'format=format_name:stream=codec_type,sample_rate',
|
|
206
|
+
'-of',
|
|
207
|
+
'json',
|
|
208
|
+
ctx.originalPath,
|
|
209
|
+
],
|
|
210
|
+
remaining(60_000),
|
|
211
|
+
);
|
|
212
|
+
if (probeRes.timedOut) throw new NormalizeStageError('deadline', 'ffprobe timed out');
|
|
213
|
+
if (probeRes.exitCode !== 0) {
|
|
214
|
+
throw new NormalizeStageError('media.invalid', `ffprobe failed: ${probeRes.stderr.trim()}`);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
let probeJson: { format?: { format_name?: string }; streams?: { codec_type?: string }[] };
|
|
218
|
+
try {
|
|
219
|
+
probeJson = JSON.parse(probeRes.stdout) as typeof probeJson;
|
|
220
|
+
} catch {
|
|
221
|
+
throw new NormalizeStageError('media.invalid', 'ffprobe output is not valid JSON');
|
|
222
|
+
}
|
|
223
|
+
const fmt = probeJson.format?.format_name ?? '';
|
|
224
|
+
const fmtParts = fmt.split(',').map((s) => s.trim().toLowerCase());
|
|
225
|
+
if (!fmtParts.includes('wav') && !fmtParts.includes('mp3')) {
|
|
226
|
+
throw new NormalizeStageError('media.invalid', `unsupported audio format '${fmt}'`);
|
|
227
|
+
}
|
|
228
|
+
const audioStreams = (probeJson.streams ?? []).filter((s) => s.codec_type === 'audio');
|
|
229
|
+
if (audioStreams.length !== 1) {
|
|
230
|
+
throw new NormalizeStageError('media.invalid', `expected 1 audio stream, found ${audioStreams.length}`);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const workDir = join(tmpdir(), `kk-wiki-audio-${ctx.manifest.captureId}`);
|
|
234
|
+
mkdirSync(workDir, { recursive: true });
|
|
235
|
+
const pcmPath = join(workDir, 'pcm.wav');
|
|
236
|
+
const wordsPath = join(workDir, 'words.json');
|
|
237
|
+
|
|
238
|
+
try {
|
|
239
|
+
const decodeRes = await runner(
|
|
240
|
+
caps.ffmpeg,
|
|
241
|
+
[
|
|
242
|
+
'-nostdin',
|
|
243
|
+
'-protocol_whitelist',
|
|
244
|
+
'file,pipe',
|
|
245
|
+
'-i',
|
|
246
|
+
ctx.originalPath,
|
|
247
|
+
'-t',
|
|
248
|
+
'301',
|
|
249
|
+
'-ac',
|
|
250
|
+
'1',
|
|
251
|
+
'-ar',
|
|
252
|
+
'16000',
|
|
253
|
+
'-f',
|
|
254
|
+
'wav',
|
|
255
|
+
pcmPath,
|
|
256
|
+
],
|
|
257
|
+
remaining(),
|
|
258
|
+
);
|
|
259
|
+
if (decodeRes.timedOut) throw new NormalizeStageError('deadline', 'ffmpeg decode timed out');
|
|
260
|
+
if (decodeRes.exitCode !== 0 || !existsSync(pcmPath)) {
|
|
261
|
+
throw new NormalizeStageError('media.invalid', `ffmpeg decode failed: ${decodeRes.stderr.trim()}`);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const dataBytes = readWavDataBytes(pcmPath);
|
|
265
|
+
const decodedDurationSec = dataBytes / (16000 * 2);
|
|
266
|
+
if (dataBytes <= 0 || decodedDurationSec <= 0) {
|
|
267
|
+
throw new NormalizeStageError('media.invalid', 'decoded audio has zero samples');
|
|
268
|
+
}
|
|
269
|
+
if (decodedDurationSec > WIKI_AUDIO_MAX_SEC) {
|
|
270
|
+
throw new NormalizeStageError(
|
|
271
|
+
'budget.exceeded',
|
|
272
|
+
`audio duration ${decodedDurationSec.toFixed(1)}s exceeds ${WIKI_AUDIO_MAX_SEC}s`,
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const workerEnv: Record<string, string | undefined> = {
|
|
277
|
+
...env,
|
|
278
|
+
HF_HUB_OFFLINE: '1',
|
|
279
|
+
TRANSFORMERS_OFFLINE: '1',
|
|
280
|
+
KK_CAPTION_MODEL: caps.modelDir,
|
|
281
|
+
};
|
|
282
|
+
const workerRunner: ProcessRunner =
|
|
283
|
+
deps.runner ?? ((cmd, args, timeoutMs) => runProcessWithEnv(cmd, args, timeoutMs, workerEnv));
|
|
284
|
+
|
|
285
|
+
const workerRes = await workerRunner(
|
|
286
|
+
caps.uv,
|
|
287
|
+
[
|
|
288
|
+
'run',
|
|
289
|
+
'--project',
|
|
290
|
+
caps.videoGenDir,
|
|
291
|
+
'--locked',
|
|
292
|
+
'--offline',
|
|
293
|
+
'--no-sync',
|
|
294
|
+
'--no-dev',
|
|
295
|
+
'python',
|
|
296
|
+
join(caps.videoGenDir, 'python', 'align_captions.py'),
|
|
297
|
+
'--audio',
|
|
298
|
+
pcmPath,
|
|
299
|
+
'--out',
|
|
300
|
+
wordsPath,
|
|
301
|
+
'--model',
|
|
302
|
+
caps.modelDir,
|
|
303
|
+
],
|
|
304
|
+
remaining(),
|
|
305
|
+
);
|
|
306
|
+
if (workerRes.timedOut) throw new NormalizeStageError('deadline', 'caption worker timed out');
|
|
307
|
+
if (workerRes.exitCode !== 0 || !existsSync(wordsPath)) {
|
|
308
|
+
if (workerRes.stderr.includes('transcription produced no words')) {
|
|
309
|
+
throw new NormalizeStageError('recognition.empty', 'audio contains no recognized speech');
|
|
310
|
+
}
|
|
311
|
+
throw new NormalizeStageError('media.invalid', `caption worker failed: ${workerRes.stderr.trim()}`);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (statSync(wordsPath).size > WIKI_AUDIO_WORDS_MAX_BYTES) {
|
|
315
|
+
throw new NormalizeStageError('budget.exceeded', 'worker words.json exceeds 4 MiB');
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
let workerJson: { language?: unknown; words?: WorkerWord[] };
|
|
319
|
+
try {
|
|
320
|
+
workerJson = JSON.parse(readFileSync(wordsPath, 'utf8')) as typeof workerJson;
|
|
321
|
+
} catch {
|
|
322
|
+
throw new NormalizeStageError('media.invalid', 'malformed worker words.json');
|
|
323
|
+
}
|
|
324
|
+
const language =
|
|
325
|
+
typeof workerJson.language === 'string' && workerJson.language.trim() !== ''
|
|
326
|
+
? workerJson.language.trim()
|
|
327
|
+
: 'unknown';
|
|
328
|
+
const { text, segments } = buildAudioSegments(workerJson.words ?? [], decodedDurationSec);
|
|
329
|
+
remaining();
|
|
330
|
+
|
|
331
|
+
const uvLockSha12 = sha256Hex(readFileSync(join(caps.videoGenDir, 'uv.lock'))).slice(0, 12);
|
|
332
|
+
const modelBinSha = sha256Hex(readFileSync(join(caps.modelDir, 'model.bin')));
|
|
333
|
+
const parametersHash = sha256Hex(`${basename(caps.modelDir)}:${modelBinSha}:${language}`);
|
|
334
|
+
|
|
335
|
+
return {
|
|
336
|
+
version: 1,
|
|
337
|
+
inputId: ctx.manifest.inputId,
|
|
338
|
+
captureId: ctx.manifest.captureId,
|
|
339
|
+
originalSha256: ctx.manifest.sha256,
|
|
340
|
+
mediaKind: 'audio',
|
|
341
|
+
normalizer: {
|
|
342
|
+
name: 'faster-whisper/align_captions',
|
|
343
|
+
version: uvLockSha12,
|
|
344
|
+
parametersHash,
|
|
345
|
+
},
|
|
346
|
+
text,
|
|
347
|
+
segments,
|
|
348
|
+
warnings: [`language:${language}`],
|
|
349
|
+
bounds: { durationSec: decodedDurationSec },
|
|
350
|
+
};
|
|
351
|
+
} finally {
|
|
352
|
+
if (existsSync(workDir)) rmSync(workDir, { recursive: true, force: true });
|
|
353
|
+
}
|
|
354
|
+
}
|