dsh-watch-together 0.2.12 → 0.2.13
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 +64 -0
- package/README.md +41 -5
- package/docs/VOICE.zh.md +44 -0
- package/dsh.plugin.json +12 -12
- package/examples/floating-chat/glass_capture.py +362 -341
- package/examples/floating-chat/glass_gpu.py +1 -1
- package/examples/floating-chat/window.py +1387 -1215
- package/examples/floating-chat/window_widgets.py +6 -3
- package/examples/voice-edge-tts/index.mjs +77 -7
- package/examples/voice-edge-tts/stream/client.mjs +8 -0
- package/examples/voice-edge-tts/stream/daemon.py +30 -0
- package/package.json +118 -118
- package/scripts/check-multimonitor.py +102 -0
- package/src/companion-api.js +88 -0
- package/src/playhead.js +75 -0
- package/src/public-api.js +7 -0
- package/src/voice-adapter.js +8 -1
- package/src/voice.js +9 -0
- package/src/watch-loop.js +26 -0
|
@@ -209,7 +209,9 @@ class TextLayer:
|
|
|
209
209
|
adapt=True) -> None:
|
|
210
210
|
"""按字符拆开建 item;anchor 支持 w/e/center 与 n/s 变体。
|
|
211
211
|
|
|
212
|
-
`shadow=True`
|
|
212
|
+
`shadow=True` 时每个字先落一层描边:**四个方向各偏移 1px** 的深色副本。
|
|
213
|
+
原来只有右下 1px,等于投影 —— 背景是浅色视频时右下那条边不够,字看起来
|
|
214
|
+
还是浮在水里(#44 第 2 条)。四方向才是真的描边,成本是每字多 3 个 item。
|
|
213
215
|
`adapt=False` 表示这块字有自己的底板,颜色固定、不参与 `adapt()` 采样。
|
|
214
216
|
"""
|
|
215
217
|
font = self.fonts.get(size, bold)
|
|
@@ -233,6 +235,7 @@ class TextLayer:
|
|
|
233
235
|
spec = self.fonts.spec(size, bold)
|
|
234
236
|
base_tags = tags if isinstance(tags, tuple) else ((tags,) if tags else ())
|
|
235
237
|
shadow_tags = base_tags + ("tshadow",) if shadow else ()
|
|
238
|
+
stroke = ((-1, 0), (1, 0), (0, -1), (0, 1)) if shadow else ()
|
|
236
239
|
for row, line in enumerate(lines):
|
|
237
240
|
width = measure(line)
|
|
238
241
|
lx = x - width if right else (x - width / 2 if center else x)
|
|
@@ -241,8 +244,8 @@ class TextLayer:
|
|
|
241
244
|
# 累积宽度,别对每个字重新 measure 前缀(那是 O(n²) 次 Tcl 调用)
|
|
242
245
|
cx = lx
|
|
243
246
|
for ch in line:
|
|
244
|
-
|
|
245
|
-
self.canvas.create_text(cx +
|
|
247
|
+
for dx, dy in stroke:
|
|
248
|
+
self.canvas.create_text(cx + dx, ly + dy, text=ch, anchor="w",
|
|
246
249
|
fill=self.COLOR_DARK, font=spec,
|
|
247
250
|
tags=shadow_tags)
|
|
248
251
|
item = self.canvas.create_text(cx, ly, text=ch, anchor="w",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
* 这样打包发布时不会把某个人的音色带进包里 —— 每个人自己配自己的。
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
|
-
import { execFile } from 'node:child_process';
|
|
43
|
+
import { execFile, spawn } from 'node:child_process';
|
|
44
44
|
import { existsSync, readFileSync, statSync, unlinkSync } from 'node:fs';
|
|
45
45
|
import { homedir, tmpdir } from 'node:os';
|
|
46
46
|
import { dirname, join } from 'node:path';
|
|
@@ -141,14 +141,36 @@ async function synthEdge(text, { bin, voice, rate }) {
|
|
|
141
141
|
return { ok: true, path: out, engine: 'edge-tts' };
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
/**
|
|
145
|
+
* 正在念的那一句的「掐断」句柄(老路的 ffplay 进程)。
|
|
146
|
+
*
|
|
147
|
+
* 常驻通道不需要它 —— 那边走 `stream.interrupt()`,杀的是播放管道那个 ffplay。
|
|
148
|
+
* 两条路都要能被打断:串行链只保证"不重叠",挡不住"越排越长"。
|
|
149
|
+
*/
|
|
150
|
+
let currentKill = null;
|
|
151
|
+
|
|
144
152
|
/** 播放一个已经合成好的 mp3;返回时无论成败都删掉临时文件。 */
|
|
145
|
-
|
|
153
|
+
function playEdge(path, onStart = null) {
|
|
146
154
|
// **就在这里上报"要出声了"**:ffplay 一启动就有声 —— 悬浮窗收到才把字摆出来,
|
|
147
155
|
// 于是"字出现"和"张嘴"几乎是同一刻(见 src/chat-store.js)。
|
|
148
156
|
try { onStart?.(); } catch { /* 上报失败不影响念 */ }
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
157
|
+
// 用 spawn 而不是 execFile:需要拿到 child 才能中途掐断(`interruptCurrent`)
|
|
158
|
+
return new Promise((resolve) => {
|
|
159
|
+
const child = spawn('ffplay', ['-nodisp', '-autoexit', '-loglevel', 'quiet', path], {
|
|
160
|
+
windowsHide: true,
|
|
161
|
+
});
|
|
162
|
+
let settled = false;
|
|
163
|
+
const done = (ok) => {
|
|
164
|
+
if (settled) return;
|
|
165
|
+
settled = true;
|
|
166
|
+
currentKill = null;
|
|
167
|
+
try { unlinkSync(path); } catch { /* 删不掉就留着 */ }
|
|
168
|
+
resolve(ok);
|
|
169
|
+
};
|
|
170
|
+
currentKill = () => { try { child.kill(); } catch { /* 已经退了 */ } };
|
|
171
|
+
child.on('error', () => done(false));
|
|
172
|
+
child.on('exit', (code) => done(code === 0));
|
|
173
|
+
});
|
|
152
174
|
}
|
|
153
175
|
|
|
154
176
|
/** Windows 系统声音。Linux/macOS 会失败,失败就当没这个引擎。 */
|
|
@@ -157,9 +179,23 @@ function speakSapi(text, rate, onStart = null) {
|
|
|
157
179
|
const cmd = `$v = New-Object -ComObject SAPI.SpVoice; $v.Rate = ${Math.max(-10, Math.min(10, Number(rate) || 0))}; $null = $v.Speak(${lit})`;
|
|
158
180
|
// PowerShell 冷启动要几百毫秒,上报放在**起进程之前**,宁可略早也别晚(字等声音没关系,声音等字不行)
|
|
159
181
|
try { onStart?.(); } catch { /* 上报失败不影响念 */ }
|
|
182
|
+
// spawn 而不是 execFile:`SpVoice.Speak()` 是阻塞的,只有杀掉进程才能让它闭嘴 ——
|
|
183
|
+
// 没有 edge-tts 的机器全走这条路(实测本机就是),不能中断的话"越堆越长"永远治不好。
|
|
160
184
|
return new Promise((resolve) => {
|
|
161
|
-
|
|
162
|
-
|
|
185
|
+
const child = spawn('powershell', ['-NoProfile', '-NonInteractive', '-Command', cmd], {
|
|
186
|
+
windowsHide: true,
|
|
187
|
+
});
|
|
188
|
+
let settled = false;
|
|
189
|
+
const done = (ok) => {
|
|
190
|
+
if (settled) return;
|
|
191
|
+
settled = true;
|
|
192
|
+
currentKill = null;
|
|
193
|
+
resolve(ok);
|
|
194
|
+
};
|
|
195
|
+
const guard = setTimeout(() => { try { child.kill(); } catch { /* 已经退了 */ } done(false); }, 60_000);
|
|
196
|
+
currentKill = () => { try { child.kill(); } catch { /* 已经退了 */ } };
|
|
197
|
+
child.on('error', () => { clearTimeout(guard); done(false); });
|
|
198
|
+
child.on('exit', (code) => { clearTimeout(guard); done(code === 0); });
|
|
163
199
|
});
|
|
164
200
|
}
|
|
165
201
|
|
|
@@ -189,6 +225,26 @@ export function attach(api) {
|
|
|
189
225
|
// 常驻合成器:能起就用它(首声 170~200ms),起不来就是 null,全部逻辑退回老路。
|
|
190
226
|
const stream = openStream(bin);
|
|
191
227
|
let chain = Promise.resolve(); // 播放串行:两句绝不重叠着念
|
|
228
|
+
/**
|
|
229
|
+
* 「该念的是第几句」。新的一句进来就 +1,之前排队的看到代际变了就自己退场。
|
|
230
|
+
*
|
|
231
|
+
* 为什么需要:串行链只保证"不重叠",挡不住"越排越长" —— 模型连说三句,
|
|
232
|
+
* 第三句要等前两句念完才开口,那时候画面早换了,听到的是"它在说上一段的事"。
|
|
233
|
+
* 用户要的是**新的直接顶掉旧的**,不是排队。
|
|
234
|
+
*/
|
|
235
|
+
let speakGen = 0;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* 掐断当前这一句,并清空排队。
|
|
239
|
+
*
|
|
240
|
+
* 常驻通道走 `stream.interrupt()`(只杀播放管道那个 ffplay,daemon 还活着);
|
|
241
|
+
* 老路直接 kill 调当前 ffplay。**chain 重置是有意的**:排队的都是"画面已经过去"的旧话。
|
|
242
|
+
*/
|
|
243
|
+
function interruptCurrent() {
|
|
244
|
+
if (stream?.alive) { try { stream.interrupt(); } catch { /* 通道挂了就算了 */ } }
|
|
245
|
+
if (currentKill) { try { currentKill(); } catch { /* 已经退了 */ } currentKill = null; }
|
|
246
|
+
chain = Promise.resolve();
|
|
247
|
+
}
|
|
192
248
|
|
|
193
249
|
// **预合成**:核心在台词写好、还没到点时发 `scheduled`。这里趁这段时间把 mp3 合成好,
|
|
194
250
|
// 到点只播放;否则 due 才开始跑 edge-tts(CLI 冷启动 + 网络往返 + 完整 mp3),
|
|
@@ -250,6 +306,18 @@ export function attach(api) {
|
|
|
250
306
|
return;
|
|
251
307
|
}
|
|
252
308
|
if (e.state !== 'due') return;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* **抢占**:新的一句要开口了,把上一句没念完的直接截断、把还在排队的丢掉。
|
|
312
|
+
*
|
|
313
|
+
* 这是用户明确的诉求("下一句来了直接把上一句停掉,不然越堆越长")。
|
|
314
|
+
* 代价:被截断的那句后面几个字听不到 —— 但那几个字本来就是"上一段画面"的话,
|
|
315
|
+
* 留着说完反而和眼前的东西对不上。
|
|
316
|
+
*/
|
|
317
|
+
speakGen += 1;
|
|
318
|
+
const myGen = speakGen;
|
|
319
|
+
interruptCurrent();
|
|
320
|
+
|
|
253
321
|
// 「真的出声了」只报一次:edge 成功之后就不该再由 SAPI 兜底那条报第二遍。
|
|
254
322
|
// 展示层(悬浮窗)等的就是这个上报 —— 不是 `due`(见 src/chat-store.js)。
|
|
255
323
|
let reported = false;
|
|
@@ -263,6 +331,8 @@ export function attach(api) {
|
|
|
263
331
|
};
|
|
264
332
|
const queuedAt = Date.now();
|
|
265
333
|
chain = chain.then(async () => {
|
|
334
|
+
// 已经被更新的一句顶掉了:直接退场,不念
|
|
335
|
+
if (myGen !== speakGen) return;
|
|
266
336
|
// **排太久了就别念**:串行链只会越排越长,声音离画面越来越远。
|
|
267
337
|
// 核心那边已经按"上一句念完才发下一句"节流,走到这里说明是真的卡住了
|
|
268
338
|
// (合成慢、引擎换挡、机器在忙)—— 这一句放弃,队立刻清空。
|
|
@@ -143,6 +143,14 @@ export function startStream({ python, script, args = ['-u', script], onError, lo
|
|
|
143
143
|
say: (text, { timeoutMs = 30_000, onFirst = null } = {}) => ask('say', text, timeoutMs, onFirst),
|
|
144
144
|
prefetch: (text, timeoutMs = 30_000) => ask('prefetch', text, timeoutMs).catch(() => ({ failed: true })),
|
|
145
145
|
forget: (text) => send({ op: 'forget', text }),
|
|
146
|
+
/**
|
|
147
|
+
* 截断正在念的那一句(**不停进程**)。
|
|
148
|
+
*
|
|
149
|
+
* 和 `stop()` 的区别:`stop` 是 `SystemExit(0)`,整个常驻合成器没了,下一句要
|
|
150
|
+
* 重新预热 1~2 秒;`interrupt` 只杀播放管道那一个 ffplay,daemon 还活着,
|
|
151
|
+
* 下一句从新进程开始念(多花一次 demuxer 探测 ~200ms)。
|
|
152
|
+
*/
|
|
153
|
+
interrupt() { try { send({ op: 'interrupt' }); } catch { /* 已经断了 */ } },
|
|
146
154
|
stop() {
|
|
147
155
|
try { send({ op: 'stop' }); } catch { /* already */ }
|
|
148
156
|
setTimeout(() => { try { proc.kill(); } catch { /* already */ } }, 300);
|
|
@@ -177,6 +177,31 @@ class Player:
|
|
|
177
177
|
except Exception:
|
|
178
178
|
pass
|
|
179
179
|
|
|
180
|
+
def interrupt(self):
|
|
181
|
+
"""截断"正在念的这一句":倒空待喂队列 + 杀掉 ffplay。
|
|
182
|
+
|
|
183
|
+
为什么需要:常驻 ffplay 是按顺序吃 mp3 帧的,一条管道进去就得念完。
|
|
184
|
+
串行链只保证"不重叠",挡不住"越排越长" —— 模型连说三句,第三句要等到
|
|
185
|
+
十几秒后才开口,那时候画面早换了。
|
|
186
|
+
|
|
187
|
+
下一帧数据进来时 `_loop` 会发现 `_proc is None` 自动 `_spawn` 一个新的,
|
|
188
|
+
所以**下一句是立刻开始念**,代价只是新进程要做一次 demuxer 探测(~200ms)。
|
|
189
|
+
"""
|
|
190
|
+
while True:
|
|
191
|
+
try:
|
|
192
|
+
self._q.get_nowait()
|
|
193
|
+
except queue.Empty:
|
|
194
|
+
break
|
|
195
|
+
except Exception:
|
|
196
|
+
break
|
|
197
|
+
proc = self._proc
|
|
198
|
+
self._proc = None
|
|
199
|
+
if proc is not None:
|
|
200
|
+
try:
|
|
201
|
+
proc.kill()
|
|
202
|
+
except Exception:
|
|
203
|
+
pass
|
|
204
|
+
|
|
180
205
|
def _spawn(self):
|
|
181
206
|
args = ["ffplay", "-nodisp", "-loglevel", self.loglevel, "-volume", str(self.volume), "-"]
|
|
182
207
|
extra = {"creationflags": 0x08000000} if os.name == "nt" else {} # CREATE_NO_WINDOW
|
|
@@ -399,6 +424,11 @@ class Daemon:
|
|
|
399
424
|
pass
|
|
400
425
|
emit(ev="skip", id=req.get("id"))
|
|
401
426
|
return
|
|
427
|
+
if op == "interrupt":
|
|
428
|
+
# 新的一句要开口了:把正在念的截断,别让它排队排到画面之外
|
|
429
|
+
self.player.interrupt()
|
|
430
|
+
emit(ev="interrupted")
|
|
431
|
+
return
|
|
402
432
|
if op == "stop":
|
|
403
433
|
raise SystemExit(0)
|
|
404
434
|
|
package/package.json
CHANGED
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-watch-together",
|
|
3
|
-
"version": "0.2.
|
|
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
|
-
"./client": "./lib/client.js",
|
|
33
|
-
"./register": "./src/register.js",
|
|
34
|
-
"./tool-spec": "./src/tool-spec.js",
|
|
35
|
-
"./watch": "./src/watch.js",
|
|
36
|
-
"./batches": "./src/batches.js",
|
|
37
|
-
"./chat": "./src/chat.js",
|
|
38
|
-
"./voice": "./src/voice.js",
|
|
39
|
-
"./speech-bus": "./src/speech-bus.js",
|
|
40
|
-
"./voice-adapter": "./src/voice-adapter.js",
|
|
41
|
-
"./interfaces": "./src/interfaces.js",
|
|
42
|
-
"./public-api": "./src/public-api.js",
|
|
43
|
-
"./recognition-interface": "./src/recognition-interface.js",
|
|
44
|
-
"./tts-interface": "./src/tts-interface.js",
|
|
45
|
-
"./window-interface": "./src/window-interface.js",
|
|
46
|
-
"./window-protocol": "./src/window-protocol.js"
|
|
47
|
-
},
|
|
48
|
-
"bin": {
|
|
49
|
-
"dsh-watch": "./bin/watch.mjs",
|
|
50
|
-
"dsh-watch-lines": "./bin/lines.mjs"
|
|
51
|
-
},
|
|
52
|
-
"files": [
|
|
53
|
-
"src",
|
|
54
|
-
"lib",
|
|
55
|
-
"bin",
|
|
56
|
-
"extension",
|
|
57
|
-
"scripts",
|
|
58
|
-
"docs",
|
|
59
|
-
"cordis.patch.yml",
|
|
60
|
-
"dsh.plugin.json",
|
|
61
|
-
"README.md",
|
|
62
|
-
"CHANGELOG.md",
|
|
63
|
-
"LICENSE",
|
|
64
|
-
"NOTICE",
|
|
65
|
-
"examples/floating-chat/*.py",
|
|
66
|
-
"examples/floating-chat/*.cmd",
|
|
67
|
-
"examples/floating-chat/*.png",
|
|
68
|
-
"examples/floating-chat/*.txt",
|
|
69
|
-
"examples/voice-edge-tts/index.mjs",
|
|
70
|
-
"examples/voice-edge-tts/stream/*.mjs",
|
|
71
|
-
"examples/voice-edge-tts/stream/*.py",
|
|
72
|
-
"examples/voice-edge-tts/stream/*.mp3"
|
|
73
|
-
],
|
|
74
|
-
"engines": {
|
|
75
|
-
"node": ">=20"
|
|
76
|
-
},
|
|
77
|
-
"scripts": {
|
|
78
|
-
"test": "node --test",
|
|
79
|
-
"pretest": "node scripts/sync-dep.mjs",
|
|
80
|
-
"sync:dep": "node scripts/sync-dep.mjs",
|
|
81
|
-
"prepublishOnly": "node scripts/check-syntax.mjs && node --test",
|
|
82
|
-
"check": "node scripts/check-syntax.mjs",
|
|
83
|
-
"doctor": "node bin/watch.mjs doctor",
|
|
84
|
-
"install:extension": "node bin/watch.mjs install-extension",
|
|
85
|
-
"sim": "node scripts/watch-sim.mjs",
|
|
86
|
-
"e2e": "node scripts/watch-e2e.mjs"
|
|
87
|
-
},
|
|
88
|
-
"dependencies": {
|
|
89
|
-
"dsh-video-storyboard": "^0.6.0"
|
|
90
|
-
},
|
|
91
|
-
"peerDependencies": {
|
|
92
|
-
"@deepseek-ai/dsh-tools": ">=0.1.0-rc.7"
|
|
93
|
-
},
|
|
94
|
-
"peerDependenciesMeta": {
|
|
95
|
-
"@deepseek-ai/dsh-tools": {
|
|
96
|
-
"optional": true
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
"dsh": {
|
|
100
|
-
"bundle": {
|
|
101
|
-
"patch": "./cordis.patch.yml"
|
|
102
|
-
},
|
|
103
|
-
"client": {
|
|
104
|
-
"platform": "web"
|
|
105
|
-
},
|
|
106
|
-
"catalog": {
|
|
107
|
-
"category": "tool",
|
|
108
|
-
"summary": {
|
|
109
|
-
"en": "Watch a video together with a text-only agent: it follows your real playback position and hands over one segment at a time, just before that segment ends.",
|
|
110
|
-
"zh": "和只有文字的智能体一起看视频:跟着你真实的播放位置,一段一段把画面和台词交到它手上,在每段结束前说完。"
|
|
111
|
-
},
|
|
112
|
-
"capabilities": [
|
|
113
|
-
"fs",
|
|
114
|
-
"shell"
|
|
115
|
-
]
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-watch-together",
|
|
3
|
+
"version": "0.2.13",
|
|
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
|
+
"./client": "./lib/client.js",
|
|
33
|
+
"./register": "./src/register.js",
|
|
34
|
+
"./tool-spec": "./src/tool-spec.js",
|
|
35
|
+
"./watch": "./src/watch.js",
|
|
36
|
+
"./batches": "./src/batches.js",
|
|
37
|
+
"./chat": "./src/chat.js",
|
|
38
|
+
"./voice": "./src/voice.js",
|
|
39
|
+
"./speech-bus": "./src/speech-bus.js",
|
|
40
|
+
"./voice-adapter": "./src/voice-adapter.js",
|
|
41
|
+
"./interfaces": "./src/interfaces.js",
|
|
42
|
+
"./public-api": "./src/public-api.js",
|
|
43
|
+
"./recognition-interface": "./src/recognition-interface.js",
|
|
44
|
+
"./tts-interface": "./src/tts-interface.js",
|
|
45
|
+
"./window-interface": "./src/window-interface.js",
|
|
46
|
+
"./window-protocol": "./src/window-protocol.js"
|
|
47
|
+
},
|
|
48
|
+
"bin": {
|
|
49
|
+
"dsh-watch": "./bin/watch.mjs",
|
|
50
|
+
"dsh-watch-lines": "./bin/lines.mjs"
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"src",
|
|
54
|
+
"lib",
|
|
55
|
+
"bin",
|
|
56
|
+
"extension",
|
|
57
|
+
"scripts",
|
|
58
|
+
"docs",
|
|
59
|
+
"cordis.patch.yml",
|
|
60
|
+
"dsh.plugin.json",
|
|
61
|
+
"README.md",
|
|
62
|
+
"CHANGELOG.md",
|
|
63
|
+
"LICENSE",
|
|
64
|
+
"NOTICE",
|
|
65
|
+
"examples/floating-chat/*.py",
|
|
66
|
+
"examples/floating-chat/*.cmd",
|
|
67
|
+
"examples/floating-chat/*.png",
|
|
68
|
+
"examples/floating-chat/*.txt",
|
|
69
|
+
"examples/voice-edge-tts/index.mjs",
|
|
70
|
+
"examples/voice-edge-tts/stream/*.mjs",
|
|
71
|
+
"examples/voice-edge-tts/stream/*.py",
|
|
72
|
+
"examples/voice-edge-tts/stream/*.mp3"
|
|
73
|
+
],
|
|
74
|
+
"engines": {
|
|
75
|
+
"node": ">=20"
|
|
76
|
+
},
|
|
77
|
+
"scripts": {
|
|
78
|
+
"test": "node --test",
|
|
79
|
+
"pretest": "node scripts/sync-dep.mjs",
|
|
80
|
+
"sync:dep": "node scripts/sync-dep.mjs",
|
|
81
|
+
"prepublishOnly": "node scripts/check-syntax.mjs && node --test",
|
|
82
|
+
"check": "node scripts/check-syntax.mjs",
|
|
83
|
+
"doctor": "node bin/watch.mjs doctor",
|
|
84
|
+
"install:extension": "node bin/watch.mjs install-extension",
|
|
85
|
+
"sim": "node scripts/watch-sim.mjs",
|
|
86
|
+
"e2e": "node scripts/watch-e2e.mjs"
|
|
87
|
+
},
|
|
88
|
+
"dependencies": {
|
|
89
|
+
"dsh-video-storyboard": "^0.6.0"
|
|
90
|
+
},
|
|
91
|
+
"peerDependencies": {
|
|
92
|
+
"@deepseek-ai/dsh-tools": ">=0.1.0-rc.7"
|
|
93
|
+
},
|
|
94
|
+
"peerDependenciesMeta": {
|
|
95
|
+
"@deepseek-ai/dsh-tools": {
|
|
96
|
+
"optional": true
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"dsh": {
|
|
100
|
+
"bundle": {
|
|
101
|
+
"patch": "./cordis.patch.yml"
|
|
102
|
+
},
|
|
103
|
+
"client": {
|
|
104
|
+
"platform": "web"
|
|
105
|
+
},
|
|
106
|
+
"catalog": {
|
|
107
|
+
"category": "tool",
|
|
108
|
+
"summary": {
|
|
109
|
+
"en": "Watch a video together with a text-only agent: it follows your real playback position and hands over one segment at a time, just before that segment ends.",
|
|
110
|
+
"zh": "和只有文字的智能体一起看视频:跟着你真实的播放位置,一段一段把画面和台词交到它手上,在每段结束前说完。"
|
|
111
|
+
},
|
|
112
|
+
"capabilities": [
|
|
113
|
+
"fs",
|
|
114
|
+
"shell"
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""check-multimonitor.py — 多显示器钳位的回归(不需要第二块显示器)。
|
|
2
|
+
|
|
3
|
+
跑法(仓库根):
|
|
4
|
+
|
|
5
|
+
python scripts/check-multimonitor.py
|
|
6
|
+
|
|
7
|
+
覆盖两件事:
|
|
8
|
+
|
|
9
|
+
1. **单屏等价**:窗口整个在主屏里时,`CaptureSource._clamp_box` 必须和改之前
|
|
10
|
+
逐像素一致(`max(0, l-PAD)` / `min(sw, r+PAD)`)。多屏支持不能把单屏观感改坏。
|
|
11
|
+
2. **副屏可用**:副屏在主屏左边(坐标为负)时,钳位后必须仍有正面积 ——
|
|
12
|
+
旧公式会算出 `gr <= gl` → 玻璃永远停在旧帧(#8)。
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import sys
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
HERE = Path(__file__).resolve().parent
|
|
21
|
+
sys.path.insert(0, str(HERE.parent / "examples" / "floating-chat"))
|
|
22
|
+
|
|
23
|
+
from glass_capture import CaptureSource # noqa: E402
|
|
24
|
+
|
|
25
|
+
PAD = 40
|
|
26
|
+
SW, SH = 2560, 1440
|
|
27
|
+
# 副屏在主屏左边:虚拟桌面从 (-1920, 0) 开始,宽 1920+2560
|
|
28
|
+
LEFT_BOUNDS = (-1920, 0, 1920 + SW, SH)
|
|
29
|
+
|
|
30
|
+
failures: list[str] = []
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def legacy_clamp(l, t, r, b, sw=SW, sh=SH, pad=PAD):
|
|
34
|
+
"""改动前的实现,作为等价性基准。"""
|
|
35
|
+
return max(0, l - pad), max(0, t - pad), min(sw, r + pad), min(sh, b + pad)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def check(name, got, want):
|
|
39
|
+
if got != want:
|
|
40
|
+
failures.append(f"{name}: got {got} want {want}")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_single_screen_identical():
|
|
44
|
+
src = CaptureSource((SW, SH))
|
|
45
|
+
for l in range(-200, SW + 200, 137):
|
|
46
|
+
for t in range(-200, SH + 200, 151):
|
|
47
|
+
for w in (80, 420, 900):
|
|
48
|
+
for h in (78, 300, 700):
|
|
49
|
+
r, b = l + w, t + h
|
|
50
|
+
# 只比较"窗口矩形完全落在主屏内"的那部分:外面本来就该钳,
|
|
51
|
+
# 旧实现钳到 0 之后可能小于窗口矩形,语义不同
|
|
52
|
+
if not (0 <= l and 0 <= t and r <= SW and b <= SH):
|
|
53
|
+
continue
|
|
54
|
+
check(f"single {l},{t},{w},{h}",
|
|
55
|
+
src._clamp_box(l, t, r, b), legacy_clamp(l, t, r, b))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_second_screen_left():
|
|
59
|
+
src = CaptureSource((SW, SH), bounds=LEFT_BOUNDS)
|
|
60
|
+
# 窗口整个在左副屏上(x 为负)
|
|
61
|
+
l, t, w, h = -1500, 300, 420, 320
|
|
62
|
+
gl, gt, gr, gb = src._clamp_box(l, t, l + w, t + h)
|
|
63
|
+
if not (gr > gl and gb > gt):
|
|
64
|
+
failures.append(f"left screen produced empty box: {(gl, gt, gr, gb)}")
|
|
65
|
+
check("left screen left edge", gl, l - PAD) # 外扩一圈仍在虚拟桌面内
|
|
66
|
+
check("left screen right edge", gr, l + w + PAD)
|
|
67
|
+
check("left screen top", gt, t - PAD)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_spanning_both_screens():
|
|
71
|
+
src = CaptureSource((SW, SH), bounds=LEFT_BOUNDS)
|
|
72
|
+
# 跨屏:从 -300 到 500
|
|
73
|
+
l, t, r, b = -300, 200, 500, 600
|
|
74
|
+
gl, gt, gr, gb = src._clamp_box(l, t, r, b)
|
|
75
|
+
if not (gr > gl and gb > gt):
|
|
76
|
+
failures.append(f"spanning produced empty box: {(gl, gt, gr, gb)}")
|
|
77
|
+
check("spanning left", gl, -340)
|
|
78
|
+
check("spanning right", gr, 540)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_no_bounds_still_works():
|
|
82
|
+
# bounds=None(老调用方 / 单屏):行为与改动前一致
|
|
83
|
+
src = CaptureSource((SW, SH), bounds=None)
|
|
84
|
+
check("no bounds", src._clamp_box(100, 100, 500, 500), legacy_clamp(100, 100, 500, 500))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def main() -> int:
|
|
88
|
+
test_single_screen_identical()
|
|
89
|
+
test_second_screen_left()
|
|
90
|
+
test_spanning_both_screens()
|
|
91
|
+
test_no_bounds_still_works()
|
|
92
|
+
if failures:
|
|
93
|
+
print(f"FAIL ({len(failures)})")
|
|
94
|
+
for line in failures[:20]:
|
|
95
|
+
print(" " + line)
|
|
96
|
+
return 1
|
|
97
|
+
print("OK — 单屏逐像素等价,副屏/跨屏都有正面积")
|
|
98
|
+
return 0
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
if __name__ == "__main__":
|
|
102
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* companion-api.js — 声音适配器能问核心的两个问题:**接下来念什么**、**现在播到哪**。
|
|
3
|
+
*
|
|
4
|
+
* ## 边界(issue #4 上定下来的,改之前先看)
|
|
5
|
+
*
|
|
6
|
+
* 这两个方法**必须是纯读**:核心不替适配器合成、不缓存音频、不知道合成要多久、
|
|
7
|
+
* 也不管适配器缓存几段。给到"下一两句是什么、现在播到哪"就够了 ——
|
|
8
|
+
* 决定预不预合成、什么时候丢过期音频,全在适配器自己。
|
|
9
|
+
*
|
|
10
|
+
* 为什么不能做成"核心帮你预合成":核心一旦开始管音频生命周期,就会出现第二个
|
|
11
|
+
* 声音引擎跟它抢话(core #27 的立场),而且合成慢的机器上要不要重试这种事,
|
|
12
|
+
* 核心根本没法知道。
|
|
13
|
+
*
|
|
14
|
+
* ## 和 `scheduled` 事件的关系
|
|
15
|
+
*
|
|
16
|
+
* `scheduled` 是**推**:核心在台词写好、还没到点时,逐句把未来 1 分钟内的句子发出来。
|
|
17
|
+
* 这两个方法是**拉**:适配器想知道"再往后呢 / 现在到哪了"时自己问。
|
|
18
|
+
* 两者不重复记账 —— `upcoming()` 读的是同一份台词槽,**不看**发过没发过。
|
|
19
|
+
*
|
|
20
|
+
* ## 别把这两个方法当"精确播放器"
|
|
21
|
+
*
|
|
22
|
+
* `at` 的单位是**播放秒**(不是墙钟),`pos` 是外推值(见 `position.js` 的三种可信度)。
|
|
23
|
+
* 位置只用来做"我合成的那句是不是已经过期"这种粗判断,别拿它算毫秒级同步。
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { readPlayhead } from './playhead.js';
|
|
27
|
+
import { upcomingLines } from './watch-lines.js';
|
|
28
|
+
|
|
29
|
+
/** 默认往前看多久(秒)。够盖住一次网络往返 + 排一句队,又不至于把整段台词都拉出来 */
|
|
30
|
+
export const DEFAULT_HORIZON_SEC = 20;
|
|
31
|
+
/**
|
|
32
|
+
* 上限。再长就不是"预取"了,而是在替核心做调度 ——
|
|
33
|
+
* 而且一次返回几十句会让适配器分不清哪些是马上要念的。
|
|
34
|
+
*/
|
|
35
|
+
export const MAX_HORIZON_SEC = 120;
|
|
36
|
+
|
|
37
|
+
const clampHorizon = (n) => {
|
|
38
|
+
const v = Number(n);
|
|
39
|
+
if (!Number.isFinite(v)) return DEFAULT_HORIZON_SEC;
|
|
40
|
+
return Math.min(MAX_HORIZON_SEC, Math.max(1, v));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 现在播到哪了。
|
|
45
|
+
*
|
|
46
|
+
* @returns {{pos:number|null, dur:number|null,
|
|
47
|
+
* confidence:'fresh'|'extrapolated'|'unknown', staleMs:number|null}}
|
|
48
|
+
* `confidence` 不是 fresh 就别拿 `pos` 当实时值;
|
|
49
|
+
* `unknown` 时 `pos` 是 `null`(不是 0 —— 见 `playhead.js` 那段)。
|
|
50
|
+
*/
|
|
51
|
+
export function position() {
|
|
52
|
+
const ph = readPlayhead();
|
|
53
|
+
return {
|
|
54
|
+
pos: ph.pos,
|
|
55
|
+
dur: ph.dur,
|
|
56
|
+
confidence: ph.confidence,
|
|
57
|
+
staleMs: ph.staleMs,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 接下来会念的台词(**只读**:不消费、不改槽位、不合成)。
|
|
63
|
+
*
|
|
64
|
+
* 只返回已经写好、而且带 `at` 的句子 —— 没写 `at` 的老台词还没钉到时间轴上,
|
|
65
|
+
* 拿去做预合成会排错顺序(见 `upcomingLines` 的注释)。
|
|
66
|
+
*
|
|
67
|
+
* **消费过的句子不会出现**:`dueLine` 会把念掉的那条从槽位里删掉,所以这里是
|
|
68
|
+
* "还欠着的"而不是"这一段的全文"。
|
|
69
|
+
*
|
|
70
|
+
* @param {{horizonSec?:number, env?:object}} [o]
|
|
71
|
+
* @returns {Promise<Array<{at:number, text:string, segment:number}>>} 按 `at` 升序;
|
|
72
|
+
* 没在陪看 / 位置不知道时是空数组
|
|
73
|
+
*/
|
|
74
|
+
export async function upcoming({ horizonSec = DEFAULT_HORIZON_SEC, env = process.env } = {}) {
|
|
75
|
+
const ph = readPlayhead();
|
|
76
|
+
if (!ph.active || !ph.input || !Number.isFinite(ph.pos)) return [];
|
|
77
|
+
const rows = await upcomingLines(ph.input, {
|
|
78
|
+
after: ph.pos,
|
|
79
|
+
before: ph.pos + clampHorizon(horizonSec),
|
|
80
|
+
env,
|
|
81
|
+
});
|
|
82
|
+
// `from` 是段首秒数(和 `due`/`scheduled` 事件里的 `segment` 同一个口径),
|
|
83
|
+
// 适配器按 (input, segment, text) 做预合成缓存时要靠它对上号。
|
|
84
|
+
return rows.map((r) => ({ at: r.at, text: r.text, segment: r.from }));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** 挂到 `attach(api)` 上的那两个方法。冻结,免得适配器改掉核心的实现 */
|
|
88
|
+
export const companionApi = Object.freeze({ upcoming, position });
|