dsh-watch-together 0.1.0 → 0.2.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/package.json CHANGED
@@ -1,89 +1,89 @@
1
- {
2
- "name": "dsh-watch-together",
3
- "version": "0.1.0",
4
- "description": "Watch a video together with a text-only agent: follow the user's real playback position, hand over one segment at a time just before it ends, and keep a single text stream of scripted lines, interjections and the user's replies.",
5
- "keywords": [
6
- "dsh",
7
- "dsh-plugin",
8
- "deepseek-harness",
9
- "video",
10
- "watch-together",
11
- "watch-party",
12
- "companion",
13
- "playback",
14
- "subtitle",
15
- "caption",
16
- "tts"
17
- ],
18
- "homepage": "https://github.com/SAOS-3624/dsh-watch-together#readme",
19
- "bugs": {
20
- "url": "https://github.com/SAOS-3624/dsh-watch-together/issues"
21
- },
22
- "repository": {
23
- "type": "git",
24
- "url": "git+https://github.com/SAOS-3624/dsh-watch-together.git"
25
- },
26
- "author": "SAOS-3624",
27
- "license": "Apache-2.0",
28
- "type": "module",
29
- "main": "./src/index.js",
30
- "exports": {
31
- ".": "./src/index.js",
32
- "./register": "./src/register.js",
33
- "./tool-spec": "./src/tool-spec.js",
34
- "./watch": "./src/watch.js",
35
- "./batches": "./src/batches.js",
36
- "./chat": "./src/chat.js",
37
- "./voice": "./src/voice.js",
38
- "./speech-bus": "./src/speech-bus.js",
39
- "./voice-adapter": "./src/voice-adapter.js"
40
- },
41
- "bin": {
42
- "dsh-watch": "./bin/watch.mjs",
43
- "dsh-watch-lines": "./bin/lines.mjs"
44
- },
45
- "files": [
46
- "src",
47
- "bin",
48
- "examples",
49
- "extension",
50
- "scripts",
51
- "docs",
52
- "cordis.patch.yml",
53
- "dsh.plugin.json",
54
- "README.md",
55
- "CHANGELOG.md",
56
- "LICENSE",
57
- "NOTICE"
58
- ],
59
- "engines": {
60
- "node": ">=20"
61
- },
62
- "scripts": {
63
- "test": "node --test",
64
- "pretest": "node scripts/sync-dep.mjs",
65
- "sync:dep": "node scripts/sync-dep.mjs",
66
- "prepublishOnly": "node scripts/check-syntax.mjs && node --test",
67
- "check": "node scripts/check-syntax.mjs",
68
- "doctor": "node bin/watch.mjs doctor",
69
- "install:extension": "node bin/watch.mjs install-extension",
70
- "sim": "node scripts/watch-sim.mjs",
71
- "e2e": "node scripts/watch-e2e.mjs"
72
- },
73
- "dependencies": {
74
- "dsh-video-storyboard": "^0.5.11"
75
- },
76
- "peerDependencies": {
77
- "@deepseek-ai/dsh-tools": ">=0.1.0-rc.7"
78
- },
79
- "peerDependenciesMeta": {
80
- "@deepseek-ai/dsh-tools": {
81
- "optional": true
82
- }
83
- },
84
- "dsh": {
85
- "bundle": {
86
- "patch": "./cordis.patch.yml"
87
- }
88
- }
89
- }
1
+ {
2
+ "name": "dsh-watch-together",
3
+ "version": "0.2.0",
4
+ "description": "Watch a video together with a text-only agent: follow the user's real playback position, hand over one segment at a time just before it ends, and keep a single text stream of scripted lines, interjections and the user's replies.",
5
+ "keywords": [
6
+ "dsh",
7
+ "dsh-plugin",
8
+ "deepseek-harness",
9
+ "video",
10
+ "watch-together",
11
+ "watch-party",
12
+ "companion",
13
+ "playback",
14
+ "subtitle",
15
+ "caption",
16
+ "tts"
17
+ ],
18
+ "homepage": "https://github.com/SAOS-3624/dsh-watch-together#readme",
19
+ "bugs": {
20
+ "url": "https://github.com/SAOS-3624/dsh-watch-together/issues"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/SAOS-3624/dsh-watch-together.git"
25
+ },
26
+ "author": "SAOS-3624",
27
+ "license": "Apache-2.0",
28
+ "type": "module",
29
+ "main": "./src/index.js",
30
+ "exports": {
31
+ ".": "./src/index.js",
32
+ "./register": "./src/register.js",
33
+ "./tool-spec": "./src/tool-spec.js",
34
+ "./watch": "./src/watch.js",
35
+ "./batches": "./src/batches.js",
36
+ "./chat": "./src/chat.js",
37
+ "./voice": "./src/voice.js",
38
+ "./speech-bus": "./src/speech-bus.js",
39
+ "./voice-adapter": "./src/voice-adapter.js"
40
+ },
41
+ "bin": {
42
+ "dsh-watch": "./bin/watch.mjs",
43
+ "dsh-watch-lines": "./bin/lines.mjs"
44
+ },
45
+ "files": [
46
+ "src",
47
+ "bin",
48
+ "examples",
49
+ "extension",
50
+ "scripts",
51
+ "docs",
52
+ "cordis.patch.yml",
53
+ "dsh.plugin.json",
54
+ "README.md",
55
+ "CHANGELOG.md",
56
+ "LICENSE",
57
+ "NOTICE"
58
+ ],
59
+ "engines": {
60
+ "node": ">=20"
61
+ },
62
+ "scripts": {
63
+ "test": "node --test",
64
+ "pretest": "node scripts/sync-dep.mjs",
65
+ "sync:dep": "node scripts/sync-dep.mjs",
66
+ "prepublishOnly": "node scripts/check-syntax.mjs && node --test",
67
+ "check": "node scripts/check-syntax.mjs",
68
+ "doctor": "node bin/watch.mjs doctor",
69
+ "install:extension": "node bin/watch.mjs install-extension",
70
+ "sim": "node scripts/watch-sim.mjs",
71
+ "e2e": "node scripts/watch-e2e.mjs"
72
+ },
73
+ "dependencies": {
74
+ "dsh-video-storyboard": "^0.6.0"
75
+ },
76
+ "peerDependencies": {
77
+ "@deepseek-ai/dsh-tools": ">=0.1.0-rc.7"
78
+ },
79
+ "peerDependenciesMeta": {
80
+ "@deepseek-ai/dsh-tools": {
81
+ "optional": true
82
+ }
83
+ },
84
+ "dsh": {
85
+ "bundle": {
86
+ "patch": "./cordis.patch.yml"
87
+ }
88
+ }
89
+ }
package/src/lines-util.js CHANGED
@@ -64,11 +64,15 @@ async function asrCues(input, { env = process.env, start = 0, end = undefined }
64
64
  if (!media) return { ok: false, cues: [], source: 'none', reason: 'no-media' };
65
65
 
66
66
  const here = new URL('./', import.meta.resolve('dsh-video-storyboard/locate'));
67
- const [{ resolveAsrConfig }, { ensureAsr }] = await Promise.all([
67
+ const [{ resolveAsrConfig, canTranscribe }, { ensureAsr }] = await Promise.all([
68
68
  import(new URL('asr.js', here)),
69
69
  import(new URL('asr-lifecycle.js', here)),
70
70
  ]);
71
71
  const cfg = resolveAsrConfig(env);
72
+ // **没配就先说"没配",别发请求。** 以前这里照样往默认的云端地址发,401 被 catch 吞成
73
+ // `asr-empty` —— 于是"这台机器没装 ASR"和"这片子真的没人说话"在结果里长得一模一样。
74
+ // 用户听到的只有一句"我听不见声音",不知道该装什么(2026-11-01 评论区的主要来源)。
75
+ if (!canTranscribe(cfg)) return { ok: false, cues: [], source: 'none', reason: 'no-key' };
72
76
  // 本机 ASR 服务没起就拉起来。**必须把配置传进去** —— `ensureAsr({})` 读不到
73
77
  // `~/.dsh/asr.json` 里的 `manage.start`,只会回 "no manage.start configured"。
74
78
  await ensureAsr({ baseUrl: cfg.baseUrl, config: cfg, env }).catch(() => {});
@@ -78,15 +82,28 @@ async function asrCues(input, { env = process.env, start = 0, end = undefined }
78
82
  const base = cfg.baseUrl.replace(/\/$/, '');
79
83
 
80
84
  const out = [];
85
+ // 三种失败要分开报,否则全糊成 asr-empty(= "这片子没人说话",一个会误导人的结论):
86
+ // wav === null → 媒体里抽不出音轨(这条副本没声音,或 ffmpeg 不认)
87
+ // sent === 0 → 一次都没连上 ASR(服务没起 / 端口错 / 云端 401)
88
+ // 其余 → 真连上了,但一个字都没听出来
89
+ let chunks = 0;
90
+ let sent = 0;
91
+ let lastError = null;
81
92
  for (let s = from; s < to; s += CHUNK_SEC) {
82
93
  const len = Math.min(CHUNK_SEC, to - s);
83
94
  const wav = await extractWav(media, s, len, env);
84
95
  if (!wav) continue;
96
+ chunks += 1;
85
97
  let got = null;
86
98
  for (let attempt = 0; attempt < 2 && !got; attempt++) {
87
- got = await postWav(base, wav, cfg).catch(() => null);
88
- if (!got) await new Promise((r) => setTimeout(r, 800));
99
+ try {
100
+ got = await postWav(base, wav, cfg);
101
+ } catch (e) {
102
+ lastError = e;
103
+ await new Promise((r) => setTimeout(r, 800));
104
+ }
89
105
  }
106
+ if (got) sent += 1;
90
107
  for (const seg of got?.segments ?? []) {
91
108
  const text = String(seg.text ?? '').trim();
92
109
  const a = Number(seg.start ?? seg.from);
@@ -95,7 +112,19 @@ async function asrCues(input, { env = process.env, start = 0, end = undefined }
95
112
  out.push({ from: a + s, to: (Number.isFinite(b) ? b : a + 2) + s, text });
96
113
  }
97
114
  }
98
- if (out.length === 0) return { ok: false, cues: [], source: 'none', reason: 'asr-empty' };
115
+ if (out.length === 0) {
116
+ if (chunks === 0) return { ok: false, cues: [], source: 'none', reason: 'no-audio' };
117
+ if (sent === 0) {
118
+ return {
119
+ ok: false,
120
+ cues: [],
121
+ source: 'none',
122
+ reason: 'asr-unreachable',
123
+ detail: `${String(lastError?.message ?? lastError ?? 'no response').slice(0, 120)} @ ${base}`,
124
+ };
125
+ }
126
+ return { ok: false, cues: [], source: 'none', reason: 'asr-empty' };
127
+ }
99
128
 
100
129
  const file = subsFile(input, env);
101
130
  let merged = out;
@@ -159,16 +188,22 @@ function findCachedMedia(input, env = process.env) {
159
188
  // 和 storyboard 的 media-store 同一个默认值(`<tmpdir>/dsh-video-storyboard/media`)。
160
189
  // 以前写的是 `LOCALAPPDATA/Temp/...` —— 在 Windows 上碰巧是同一个目录,换个系统就找不到。
161
190
  const dir = env.DSH_VIDEO_MEDIA_DIR || join(tmpdir(), 'dsh-video-storyboard', 'media');
162
- const s = String(input ?? '');
191
+ const s = String(input ?? '').trim();
192
+ if (!s) return null;
193
+ // 本地文件**自己就是媒体**,不用去缓存目录里找。
194
+ if (!/^https?:/i.test(s)) return existsSync(s) ? s : null;
163
195
  const m = s.match(/(BV[0-9A-Za-z]{10})/i);
164
- const needle = m ? m[1].toLowerCase() : null;
196
+ // 匹配用的针:B 站用 BV 号,别的站点用整条 URL。
197
+ // **不能留 `if (!needle) return video` 那种兜底** —— YouTube / 直链没有 BV 号时会
198
+ // 返回目录里碰到的**第一个** video.mp4,于是转写的是另一部片子的音轨:台词全错,
199
+ // 而且一句错都不报(用户只会说"它听到的东西和画面对不上")。
200
+ const needle = (m ? m[1] : s).toLowerCase();
165
201
  try {
166
202
  for (const d of readdirSync(dir)) {
167
203
  const sub = join(dir, d);
168
204
  const meta = join(sub, 'meta.json');
169
205
  const video = join(sub, 'video.mp4');
170
206
  if (!existsSync(video) || !existsSync(meta)) continue;
171
- if (!needle) return video;
172
207
  try {
173
208
  const j = JSON.parse(readFileSync(meta, 'utf8'));
174
209
  if (String(j?.url ?? '').toLowerCase().includes(needle)) return video;
@@ -178,6 +213,42 @@ function findCachedMedia(input, env = process.env) {
178
213
  return null;
179
214
  }
180
215
 
216
+ /**
217
+ * "拿不到台词"的每种原因 → 一句**用户能懂**的话(含该做什么)。
218
+ *
219
+ * 文案只写一份:`transcriptOnly` 的返回、陪看交付时的告示都从这里取。
220
+ * 以前这些都只报一个英文码(`no-key` / `asr-empty`),模型转述成"我听不见声音",
221
+ * 用户既不知道缺什么、也不知道装一次就永久解决 —— 评论区里同一个问题被问了几十遍。
222
+ */
223
+ export function explainCuesFailure(reason, detail) {
224
+ switch (String(reason ?? '')) {
225
+ case 'no-key':
226
+ return '这台机器没有可用的听音能力:默认后端是云端(要 key),本机 ASR 也没起。'
227
+ + '装一次 sherpa-onnx(免费、不联网,约 15 分钟,docs/INSTALL.zh.md 第 3 步)就能永久解决;'
228
+ + '或者给 B 站 cookie,让我改读它的 CC 字幕。';
229
+ case 'asr-unreachable':
230
+ return `ASR 服务连不上(${detail ?? 'no response'})—— 装了但没启动,或地址/端口不对(~/.dsh/asr.json)。`;
231
+ case 'asr-failed':
232
+ return `ASR 调用失败(${detail ?? 'see log'})—— 服务在跑但这一路不通。`;
233
+ case 'no-audio':
234
+ return '这份副本**没有音轨**(下载时只取了画面),不是我听不见 —— 换成带声音的副本或本地文件。';
235
+ case 'asr-empty':
236
+ return 'ASR 跑过了,这一段没听到人声(纯音乐 / 只有音效 / 真没人说话)。';
237
+ case 'no-media':
238
+ return '还没有本地副本可听 —— 先让它出一次图(会顺手下载这一段),再取字幕。';
239
+ case 'local-file-needs-sidecar':
240
+ return '本地文件没有配套字幕:把同名 .srt/.ass 放在旁边,或让它直接听这个文件。';
241
+ case 'needs-login':
242
+ return 'B 站有 CC 字幕,但要登录才给 —— 配一次 cookies(`checkCookies: true` 可当场验证)。';
243
+ case 'no-ytdlp':
244
+ return '这台机器没有 yt-dlp,抓不到站点字幕。';
245
+ case 'no-subs':
246
+ return '这条片子既没有 CC 字幕,ASR 也没给出句子。';
247
+ default:
248
+ return `拿不到台词(${reason ?? 'unknown'})。`;
249
+ }
250
+ }
251
+
181
252
  /**
182
253
  * 拿这支片子的字幕(带缓存)。
183
254
  *
@@ -206,7 +277,15 @@ export async function loadCues(input, {
206
277
  // 台词就会提前几十秒冒出来 —— 用户 2026-10-31 报的"台词比视频提前了有点多"就是这个。
207
278
  const a = await asrCues(input, { env, start, end }).catch(() => null);
208
279
  if (a?.ok) return a;
209
- return { ok: false, cues: [], source: 'none', reason: r?.reason ?? 'no-subs' };
280
+ // 把 ASR 那边的**具体**原因带上去:`no-key`(没装)/ `asr-unreachable`(装了没起)/
281
+ // `no-audio`(这份副本没音轨)/ `asr-empty`(真没说话)—— 四种药方完全不同。
282
+ return {
283
+ ok: false,
284
+ cues: [],
285
+ source: 'none',
286
+ reason: a?.reason ?? r?.reason ?? 'no-subs',
287
+ ...(a?.detail ? { detail: a.detail } : {}),
288
+ };
210
289
  }
211
290
  const cues = r.segments
212
291
  .map((c) => ({ from: Number(c.from), to: Number(c.to), text: String(c.text ?? '').trim() }))
package/src/tool-spec.js CHANGED
@@ -367,7 +367,12 @@ export function watchToolSpec() {
367
367
  'plugin cannot see your normal reply and the chat box would otherwise show only the script. ' +
368
368
  'Do not wait for the user to speak first.\n\n' +
369
369
  'It is the cheapest call there is: no position read, no frame built, no batch advanced. ' +
370
- 'One round trip and the sentence is out.',
370
+ 'One round trip and the sentence is out.\n\n' +
371
+ '**ONE call carries everything you want to say at this moment.** The text is spoken as a ' +
372
+ 'single utterance and lands as a single bubble, so two or three short sentences belong in ' +
373
+ 'ONE `say` (separate them with 。 or a newline) - not in two or three separate calls. Every ' +
374
+ 'call re-sends the whole conversation, and firing one per sentence is the single easiest way ' +
375
+ 'to burn tokens for nothing. Batch the thought, not the round trips.',
371
376
  },
372
377
  loop: {
373
378
  type: 'boolean',
@@ -17,7 +17,7 @@
17
17
 
18
18
  import { configuredPort, probeBrowser } from 'dsh-video-storyboard/browser-time';
19
19
  import { checkBiliLogin, fetchRemoteSubtitles } from 'dsh-video-storyboard/subtitles';
20
- import { loadCues, sentencesBetween } from './lines-util.js';
20
+ import { explainCuesFailure, loadCues, sentencesBetween } from './lines-util.js';
21
21
  import { linesOverview } from './watch-lines.js';
22
22
  import { markMaterial, materialNote } from './watch-material.js';
23
23
  import { controllerOf, wakeSession } from './timer.js';
@@ -85,8 +85,11 @@ export async function runWatchAction(args, { ctx = null, sessionId = null, brows
85
85
  .catch((e) => ({ ok: false, reason: String(e?.message ?? e) }));
86
86
  if (!cuesRes.ok) {
87
87
  return {
88
- text: `[transcriptOnly] 拿不到字幕(${cuesRes.reason})。`
89
- + '那就用带图交付里每格下面那行转写 —— 它和这里是同一批句子。别凭印象写 `at`。',
88
+ text: `[transcriptOnly] 拿不到台词(${cuesRes.reason})。`
89
+ + explainCuesFailure(cuesRes.reason, cuesRes.detail)
90
+ + '\n如果用户问"你为什么听不到声音",就照上面这句回答(**别只说"我听不到"**:'
91
+ + '他们以为插件坏了,其实是缺一步配置)。'
92
+ + '\n还能用的:带图交付里每格下面那行转写 —— 它和这里是同一批句子。别凭印象写 `at`。',
90
93
  images: [],
91
94
  };
92
95
  }