dsh-watch-together 0.2.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/README.md +21 -4
- package/docs/VOICE.zh.md +9 -2
- package/dsh.plugin.json +12 -12
- package/examples/floating-chat/glass_window_gpu.py +11 -2
- package/examples/floating-chat/window.py +30 -3
- package/examples/voice-edge-tts/index.mjs +101 -18
- package/package.json +115 -115
- package/src/watch-lines.js +494 -459
- package/src/watch-loop.js +44 -2
- package/src/watch.js +44 -43
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,49 @@
|
|
|
3
3
|
All notable changes to **dsh-watch-together** are documented here.
|
|
4
4
|
This package starts its own version line at `0.0.7` — it is not a continuation of `dsh-video-storyboard`.
|
|
5
5
|
|
|
6
|
+
## [0.2.6] - 2026-11-02
|
|
7
|
+
|
|
8
|
+
> 陪看的声音还差最后一步:到点才开始合成。这一轮把"合成"从关键路径上挪开。
|
|
9
|
+
|
|
10
|
+
### Added — `scheduled` 事件(合 PR #36,作者 @ggfgfgf-on)
|
|
11
|
+
|
|
12
|
+
- 循环每一拍把**未来 60 秒内、已经写好且带 `at`** 的台词以 `scheduled` 广播一次(每句一次;
|
|
13
|
+
只在有会出声的订阅者时发)。它不参与"该不该念"的判断,只给适配器时间预合成。
|
|
14
|
+
- `upcomingLines(input, { after, before })`:只读的"未来台词"查询,不消费稿件。
|
|
15
|
+
|
|
16
|
+
### Changed — 示例适配器预合成
|
|
17
|
+
|
|
18
|
+
- `examples/voice-edge-tts`:`speakEdge` 拆成 `synthEdge`(只合成)+ `playEdge`(播放并删临时文件);
|
|
19
|
+
`scheduled` 到达即合成,按 `input|segment|text` 缓存(上限 6 条,满时踢 `at` 最远的一条),
|
|
20
|
+
`due` 优先播缓存。日志多出 `prefetched` / `synth`、`ready Nms`、`wait Nms`。
|
|
21
|
+
- `MAX_QUEUE_LAG_MS` 的计时从 `due` **到达**起算,合成时间本来就算在里面 ——
|
|
22
|
+
预取因此还降低了"排队太久被丢弃"的概率,不只是首声早一点。
|
|
23
|
+
|
|
24
|
+
### Fixed — 评审补丁(`5fa1307`、`bd5b3c7`)
|
|
25
|
+
|
|
26
|
+
- **跨段时缓存 key 对不上**:`dueLine` 跨段挑 `at` 最小的一句,选中上一段的句子时 `due` 报的却是
|
|
27
|
+
当前段,和 `scheduled` 的 `segment` 不一致 → 缓存白做、首声又晚回 0.6~2 秒。
|
|
28
|
+
`dueLine({ meta: true })` 现在多返回 `from`,`speak()` 用它。
|
|
29
|
+
- **`Number(null) === 0`**:没写 `at` 的台词会被当成"at=0"挤进预取窗口;适配器 `prefetch()` 同理,
|
|
30
|
+
6 个槽位被 at=0 占满后永久失效。两处都改成显式判空。
|
|
31
|
+
|
|
32
|
+
## [0.2.5] - 2026-11-02
|
|
33
|
+
|
|
34
|
+
> 0.2.4 里 PR #28 留下的两个 GPU 尾巴,作者当天补了 PR #29 收掉,外加气泡留白微调。
|
|
35
|
+
|
|
36
|
+
### Fixed — GPU 内框边缘(合 PR #29,作者 @ggfgfgf-on)
|
|
37
|
+
|
|
38
|
+
- **底部输入/发送框发黑**:内框边缘原来直接拿 `small` 的 render target 当 sampler,
|
|
39
|
+
贴边小框会采到边界外。现在单独拷一份 blur(1.45) 到 `edgeblur` FBO 再采样
|
|
40
|
+
(注释里写明「直接当 sampler 会触发驱动崩溃」,所以宁可多一次 copy)。
|
|
41
|
+
- **内框边缘的折射/扭曲丢了**:CPU 里 `edge_w=0` 是边缘(取折射样本)、`=1` 是中心
|
|
42
|
+
(取强模糊),Shader 里方向是反的。改成 `mix(edgep, strong, e)` 后恢复。
|
|
43
|
+
|
|
44
|
+
### Changed — 气泡留白
|
|
45
|
+
|
|
46
|
+
- 横向 14→18,纵向 `+4`→`+16`,正文按 `(bh - lines*ls)/2` 垂直居中。
|
|
47
|
+
字不再贴着气泡边,短消息也不会挤成一条。
|
|
48
|
+
|
|
6
49
|
## [0.2.4] - 2026-11-02
|
|
7
50
|
|
|
8
51
|
> 0.2.3 发出去 20 分钟就发了这个 —— 因为它带着一个肉眼可见的毛病:
|
package/README.md
CHANGED
|
@@ -286,15 +286,31 @@ watch_together({ browserPort: 9333 }) // 或者单次传参
|
|
|
286
286
|
```
|
|
287
287
|
|
|
288
288
|
后台循环里某句到点时,会把同一条推给你,`state` 变成 `"due"`。
|
|
289
|
+
另外,循环每一拍还会把**未来 1 分钟内、已经写好且带 `at` 的台词**提前推成 `scheduled`(每句一次)——
|
|
290
|
+
这不是让你现在念,而是给适配器时间**预合成**;真正播放仍然只认 `due`。
|
|
291
|
+
|
|
292
|
+
> `scheduled` **一定带有限的 `at`**(没写 `at` 的台词进不了这个窗口)。写适配器时别拿 `Number(at)`
|
|
293
|
+
> 判空——`Number(null)` 是 `0`,会被当成"最早的一句"占满预取队列,之后既踢不掉旧的也进不来新的。
|
|
289
294
|
|
|
290
295
|
### 同进程:订阅
|
|
291
296
|
|
|
292
297
|
```js
|
|
293
298
|
import { onSpeech } from 'dsh-watch-together/voice';
|
|
294
299
|
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
300
|
+
const pending = new Map(); // key -> 预合成 Promise
|
|
301
|
+
const keyOf = ({ input, segment, text }) => `${input ?? ''}|${segment ?? ''}|${text ?? ''}`;
|
|
302
|
+
|
|
303
|
+
const off = onSpeech(async (event) => {
|
|
304
|
+
const { state, text } = event;
|
|
305
|
+
const key = keyOf(event);
|
|
306
|
+
if (state === 'scheduled') { // 还没到点:先合成,不播放
|
|
307
|
+
if (!pending.has(key)) pending.set(key, mySynth(text));
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (state !== 'due') return; // spoken / skipped 不是"该念了"
|
|
311
|
+
const audio = pending.get(key) ? await pending.get(key) : await mySynth(text);
|
|
312
|
+
pending.delete(key);
|
|
313
|
+
await myPlay(audio); // ← 你自己的播放器
|
|
298
314
|
});
|
|
299
315
|
```
|
|
300
316
|
|
|
@@ -599,7 +615,8 @@ node scripts/install-dev.mjs # 把本包同步进 DSH profile(副本
|
|
|
599
615
|
社区提的改动按 PR 记在这里(storyboard 那边的完整名单在 `dsh-video-storyboard/CREDITS.md`):
|
|
600
616
|
|
|
601
617
|
- [@ggfgfgf-on](https://github.com/ggfgfgf-on) —— 插件设置页([PR #11](https://github.com/SAOS-3624/dsh-watch-together/pull/11),设置直接渲染在插件详情页);
|
|
602
|
-
核心改走 runtime-ports、悬浮窗气泡与折叠重做([PR #22](https://github.com/SAOS-3624/dsh-watch-together/pull/22)
|
|
618
|
+
核心改走 runtime-ports、悬浮窗气泡与折叠重做([PR #22](https://github.com/SAOS-3624/dsh-watch-together/pull/22));
|
|
619
|
+
小框边缘模糊过渡、CPU 补色散与运动混合、麦克风回到玻璃帧合成([PR #28](https://github.com/SAOS-3624/dsh-watch-together/pull/28))
|
|
603
620
|
- [@DreamDLYY](https://github.com/DreamDLYY) —— 悬浮窗拖出屏幕后抓屏越界、日志每帧刷错、背景永久花屏的复现与修复([PR #23](https://github.com/SAOS-3624/dsh-watch-together/pull/23))
|
|
604
621
|
|
|
605
622
|
## 许可
|
package/docs/VOICE.zh.md
CHANGED
|
@@ -191,7 +191,9 @@ export function attach(api) {
|
|
|
191
191
|
### 一定要上报"真的出声了":`api.emitSpoken(e)`
|
|
192
192
|
|
|
193
193
|
`due` 只说明**该念了**。从 `due` 到"真的有声音"之间还隔着一整套合成(edge-tts 一次网络往返
|
|
194
|
-
加一个 ffplay 启动,短句也要 0.6~2
|
|
194
|
+
加一个 ffplay 启动,短句也要 0.6~2 秒)。**不要等 due 才开始合成**:核心会在台词写好、
|
|
195
|
+
还没到点时先发 `scheduled`(未来 1 分钟内,每句一次),适配器可以据此预合成;到点再播放,
|
|
196
|
+
首声就不用再等网络。示例适配器已经这么做。悬浮窗里的台词等的是 `spoken`:
|
|
195
197
|
|
|
196
198
|
```js
|
|
197
199
|
api.onSpeech((e) => {
|
|
@@ -210,12 +212,17 @@ api.onSpeech((e) => {
|
|
|
210
212
|
|
|
211
213
|
`api.onSpeech` 收到的事件关键字段:
|
|
212
214
|
|
|
213
|
-
- `state`:`'due'` =
|
|
215
|
+
- `state`:`'due'` = 到点该念(**播放只处理这个**);`'scheduled'` = 还没到点,
|
|
216
|
+
可以现在预合成(**不要现在播放**);
|
|
214
217
|
`'spoken'` = 适配器上报的"开始出声了";`'skipped'` = 放弃这句(见下)。
|
|
215
218
|
- `text`:要念的台词。
|
|
216
219
|
- `at`:**这句对应的播放位置(秒)**,不是墙钟 —— 打时间码用它。
|
|
217
220
|
- `input` / `segment`:哪一支片子的哪一段(多支片子交叉时用得上)。
|
|
218
221
|
|
|
222
|
+
> **`scheduled` 一定带有限的 `at`**:预取要靠它排"哪句更近",没写 `at` 的台词不会进这个窗口。
|
|
223
|
+
> 适配器自己也别用 `Number(at)` 判空 —— `Number(null)` 是 `0` 且算有限数,会被当成"最早的一句"
|
|
224
|
+
> 占满预取队列,之后既踢不掉旧的、也进不来新的,预取就静默失效了(不报错)。判 `at == null` 才是对的。
|
|
225
|
+
|
|
219
226
|
### 追不上就放弃:`state: 'skipped'`
|
|
220
227
|
|
|
221
228
|
引擎是串行的(一句念完才轮到下一句)。台词一密,队列就会越来越长,声音离画面越来越远。
|
package/dsh.plugin.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-watch-together",
|
|
3
|
-
"description": "Watch a video together with a text-only agent: follow the user's real playback position and hand over one segment at a time, just before the segment ends.",
|
|
4
|
-
"version": "0.2.
|
|
5
|
-
"entry": {
|
|
6
|
-
"name": "dsh-watch-together",
|
|
7
|
-
"inject": [
|
|
8
|
-
"tools",
|
|
9
|
-
"attachments"
|
|
10
|
-
]
|
|
11
|
-
}
|
|
12
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-watch-together",
|
|
3
|
+
"description": "Watch a video together with a text-only agent: follow the user's real playback position and hand over one segment at a time, just before the segment ends.",
|
|
4
|
+
"version": "0.2.6",
|
|
5
|
+
"entry": {
|
|
6
|
+
"name": "dsh-watch-together",
|
|
7
|
+
"inject": [
|
|
8
|
+
"tools",
|
|
9
|
+
"attachments"
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -110,7 +110,9 @@ void main() {
|
|
|
110
110
|
ivec2 ep = clamp(ivec2(floor(ec + 0.5)), ivec2(0), ivec2(src_size) - 1);
|
|
111
111
|
// 边缘从小框自己的原始帧取,避免 warped 在贴边小框上采到黑边。
|
|
112
112
|
vec3 edgep = texelFetch(raw, ep, 0).rgb;
|
|
113
|
-
|
|
113
|
+
// CPU 里 edge_w=0 是边缘(取折射样本),=1 是中心(取强模糊);
|
|
114
|
+
// 这里方向必须一致,否则内框边缘反而没有扭曲。
|
|
115
|
+
vec3 patch = mix(edgep, strong, e);
|
|
114
116
|
frag = vec4(mix(base, patch, a), 1.0);
|
|
115
117
|
}
|
|
116
118
|
"""
|
|
@@ -374,10 +376,17 @@ class GPULens:
|
|
|
374
376
|
src_size=(float(bw), float(bh)))
|
|
375
377
|
p.vao.render(moderngl.TRIANGLES)
|
|
376
378
|
|
|
379
|
+
# 单独拷一份 blur(1.45) 给边缘采样;直接把 small 的 render target
|
|
380
|
+
# 当 sampler 会触发驱动崩溃。
|
|
381
|
+
edgeblur = self._fbo("edgeblur", (bw, bh))
|
|
382
|
+
edgeblur.use(); self.ctx.viewport = (0, 0, bw, bh)
|
|
383
|
+
small.color_attachments[0].use(0)
|
|
384
|
+
p = self.progs["final"]; p["tex"] = 0; p.vao.render(moderngl.TRIANGLES)
|
|
385
|
+
|
|
377
386
|
lens.use(); self.ctx.viewport = (0, 0, hw, hh)
|
|
378
387
|
warped.color_attachments[0].use(0)
|
|
379
388
|
strongw.color_attachments[0].use(1)
|
|
380
|
-
|
|
389
|
+
edgeblur.color_attachments[0].use(2)
|
|
381
390
|
self.texs["alpha"].use(3)
|
|
382
391
|
self.texs["edge"].use(4)
|
|
383
392
|
self.texs["coord"].use(5)
|
|
@@ -87,6 +87,13 @@ CHAT_FILE = cache_dir() / "chat.jsonl"
|
|
|
87
87
|
CONFIG = Path(os.environ.get("DSH_HOME") or os.path.expanduser("~/.dsh")) / "watch-window.json"
|
|
88
88
|
MIC_SCRIPT = HERE / "mic.py"
|
|
89
89
|
|
|
90
|
+
# **心跳**:插件侧靠它区分"进程还在"和"窗口真的在画"。
|
|
91
|
+
# 只看 pid 不够 —— pid 会被系统复用,进程也可能活着但界面已经卡死、或者是一张空窗,
|
|
92
|
+
# 那样宿主会永远认为"窗还开着",于是**再也不重开**(dsh-see-now issue #2 第 3 条)。
|
|
93
|
+
# 每秒最多写一次,别把磁盘当草稿纸。
|
|
94
|
+
HEARTBEAT = cache_dir() / "window-heartbeat"
|
|
95
|
+
HEARTBEAT_EVERY = 1.0
|
|
96
|
+
|
|
90
97
|
|
|
91
98
|
def read_config():
|
|
92
99
|
try:
|
|
@@ -1255,7 +1262,7 @@ class LiveGlass:
|
|
|
1255
1262
|
left, right = base[0][0], base[0][2]
|
|
1256
1263
|
max_bubble = min(right - left, max(240, int((right - left) * 0.72)))
|
|
1257
1264
|
min_bubble = min(110, max_bubble)
|
|
1258
|
-
pad =
|
|
1265
|
+
pad = 18
|
|
1259
1266
|
body_font = f(11)
|
|
1260
1267
|
stamp_font = f(9)
|
|
1261
1268
|
fbody = tkfont.Font(root=self.root, font=body_font)
|
|
@@ -1279,7 +1286,8 @@ class LiveGlass:
|
|
|
1279
1286
|
content_max, body_avail)
|
|
1280
1287
|
inner = max([0] + [fbody.measure(line) for line in lines])
|
|
1281
1288
|
bw = min(max_bubble, max(min_bubble, inner + 2 * pad))
|
|
1282
|
-
|
|
1289
|
+
# 上下留白比原来多一圈;正文垂直居中,气泡不会贴着字。
|
|
1290
|
+
bh = min(body_avail, max(ls + 16, len(lines) * ls + 16))
|
|
1283
1291
|
by0 = y0 + stamp_h
|
|
1284
1292
|
by1 = min(y1, by0 + bh)
|
|
1285
1293
|
if is_user:
|
|
@@ -1295,7 +1303,8 @@ class LiveGlass:
|
|
|
1295
1303
|
infos.append({
|
|
1296
1304
|
"shape": shape, "is_user": is_user, "stamp": stamp,
|
|
1297
1305
|
"tx": tx, "ta": ta, "lines": lines,
|
|
1298
|
-
"body_font": body_font,
|
|
1306
|
+
"body_font": body_font,
|
|
1307
|
+
"ty": by0 + max(4, (bh - len(lines) * ls) // 2),
|
|
1299
1308
|
"stamp_y": y0, "ls": ls,
|
|
1300
1309
|
})
|
|
1301
1310
|
shapes.extend(base[4:])
|
|
@@ -1629,7 +1638,25 @@ class LiveGlass:
|
|
|
1629
1638
|
if self._excluded:
|
|
1630
1639
|
self._set_exclude(False)
|
|
1631
1640
|
|
|
1641
|
+
def _beat(self):
|
|
1642
|
+
"""写心跳(每秒最多一次)。插件侧 `windowAlive()` 读它的 mtime。
|
|
1643
|
+
|
|
1644
|
+
为什么不是"进程活着就算活着":pid 会被系统复用,进程也可能活着但界面卡死、
|
|
1645
|
+
或者是一张全透明的空窗。那种情况下宿主一直认为窗还开着,于是**再也不重开** ——
|
|
1646
|
+
用户体感就是"点了没反应"。
|
|
1647
|
+
"""
|
|
1648
|
+
now = time.time()
|
|
1649
|
+
if now - getattr(self, "_beat_at", 0.0) < HEARTBEAT_EVERY:
|
|
1650
|
+
return
|
|
1651
|
+
self._beat_at = now
|
|
1652
|
+
try:
|
|
1653
|
+
HEARTBEAT.parent.mkdir(parents=True, exist_ok=True)
|
|
1654
|
+
HEARTBEAT.write_bytes(b"")
|
|
1655
|
+
except Exception:
|
|
1656
|
+
pass
|
|
1657
|
+
|
|
1632
1658
|
def _tick(self):
|
|
1659
|
+
self._beat()
|
|
1633
1660
|
# 截图模式:worker 已暂停,保持 WDA 关闭;否则下一拍会重新开 WDA,
|
|
1634
1661
|
# 窗口再次从截图/录屏里消失,_snapshot_mode 等于没做。
|
|
1635
1662
|
if SNAPSHOT and getattr(self, "_snapshot_done", False):
|
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* ## 两件事,别混
|
|
9
9
|
*
|
|
10
|
-
* 收到 `
|
|
11
|
-
*
|
|
10
|
+
* 收到 `scheduled` = 还没到点,可以**预合成**(本文件按台词缓存 mp3,不播放)
|
|
11
|
+
* 收到 `due` = 该念了(核心按播放位置发的)
|
|
12
|
+
* 发 `spoken` = **真的出声了**(本文件在开始播放那一瞬发)
|
|
12
13
|
*
|
|
13
14
|
* 悬浮窗认的是 `spoken`:不然字会先摆出来、声音一两秒后才到(`due` → 合成是一次网络往返
|
|
14
15
|
* 加一个 ffplay 启动)。上报晚了就等于又回到旧毛病,所以上报点选在**播放之前**。
|
|
@@ -81,21 +82,35 @@ function edgeBin(cfg) {
|
|
|
81
82
|
return null;
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
|
|
85
|
+
/** 只合成,不播放。预取和"到点没赶上预取"两条路共用。 */
|
|
86
|
+
async function synthEdge(text, { bin, voice, rate }) {
|
|
85
87
|
const out = join(tmpdir(), `voice-${Date.now()}-${Math.random().toString(36).slice(2, 7)}.mp3`);
|
|
86
88
|
const pct = Math.round(Math.max(-10, Math.min(10, Number(rate) || 0)) * 3);
|
|
87
89
|
const args = ['--voice', voice, '--text', text, '--write-media', out];
|
|
88
90
|
if (pct) args.push(`--rate=${pct > 0 ? '+' : ''}${pct}%`);
|
|
89
|
-
if (!(await run(bin, args)))
|
|
91
|
+
if (!(await run(bin, args))) {
|
|
92
|
+
try { unlinkSync(out); } catch { /* 没有文件正常 */ }
|
|
93
|
+
return { ok: false, reason: 'synth-failed' };
|
|
94
|
+
}
|
|
90
95
|
try {
|
|
91
|
-
if (statSync(out).size < 800)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
if (statSync(out).size < 800) {
|
|
97
|
+
try { unlinkSync(out); } catch { /* 空文件删不掉也不影响 */ }
|
|
98
|
+
return { ok: false, reason: 'empty-audio' };
|
|
99
|
+
}
|
|
100
|
+
} catch {
|
|
101
|
+
return { ok: false, reason: 'stat-failed' };
|
|
102
|
+
}
|
|
103
|
+
return { ok: true, path: out, engine: 'edge-tts' };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** 播放一个已经合成好的 mp3;返回时无论成败都删掉临时文件。 */
|
|
107
|
+
async function playEdge(path, onStart = null) {
|
|
108
|
+
// **就在这里上报"要出声了"**:ffplay 一启动就有声 —— 悬浮窗收到才把字摆出来,
|
|
109
|
+
// 于是"字出现"和"张嘴"几乎是同一刻(见 src/chat-store.js)。
|
|
95
110
|
try { onStart?.(); } catch { /* 上报失败不影响念 */ }
|
|
96
|
-
const played = await run('ffplay', ['-nodisp', '-autoexit', '-loglevel', 'quiet',
|
|
97
|
-
try { unlinkSync(
|
|
98
|
-
return played
|
|
111
|
+
const played = await run('ffplay', ['-nodisp', '-autoexit', '-loglevel', 'quiet', path], 90_000);
|
|
112
|
+
try { unlinkSync(path); } catch { /* 删不掉就留着 */ }
|
|
113
|
+
return played;
|
|
99
114
|
}
|
|
100
115
|
|
|
101
116
|
/** Windows 系统声音。Linux/macOS 会失败,失败就当没这个引擎。 */
|
|
@@ -133,14 +148,62 @@ export function attach(api) {
|
|
|
133
148
|
+ '想用晓萱等音色请在该文件加 "voice": "zh-CN-XiaoxuanNeural"');
|
|
134
149
|
const rate = Number(cfg.rate) || 0;
|
|
135
150
|
const bin = edgeBin(cfg);
|
|
136
|
-
let chain = Promise.resolve(); //
|
|
151
|
+
let chain = Promise.resolve(); // 播放串行:两句绝不重叠着念
|
|
152
|
+
|
|
153
|
+
// **预合成**:核心在台词写好、还没到点时发 `scheduled`。这里趁这段时间把 mp3 合成好,
|
|
154
|
+
// 到点只播放;否则 due 才开始跑 edge-tts(CLI 冷启动 + 网络往返 + 完整 mp3),
|
|
155
|
+
// 第一声会晚 0.6~2 秒。没有 prefetch 的旧宿主仍然走 due 现场合成,不破坏兼容。
|
|
156
|
+
const MAX_PREFETCH = 6;
|
|
157
|
+
const prefetched = new Map(); // key -> { task, path, at }
|
|
158
|
+
let prefetchTail = Promise.resolve();
|
|
159
|
+
const keyOf = (e) => `${e.input ?? ''}|${e.segment ?? ''}|${String(e.text ?? '')}`;
|
|
160
|
+
const discard = (entry) => {
|
|
161
|
+
entry.task.then((r) => {
|
|
162
|
+
if (r?.ok && r.path) { try { unlinkSync(r.path); } catch { /* 已删 */ } }
|
|
163
|
+
}).catch(() => {});
|
|
164
|
+
};
|
|
165
|
+
const prefetch = (e) => {
|
|
166
|
+
// **没有 `at` 的事件一律不预取**。适配器是陪看和看屏幕两个插件共用的,
|
|
167
|
+
// 那边(`see-now`)的事件是 `at: null`(它没有时间轴)。而 `Number(null)` 是 0、
|
|
168
|
+
// `Number.isFinite(0)` 为真 —— 放进来会被当成"最早的一句"占满队列,之后
|
|
169
|
+
// `Number(e.at) < farthestAt` 永远是 `0 < 0`(假),新句子再也进不来,预取静默失效。
|
|
170
|
+
if (e.at === null || e.at === undefined) return;
|
|
171
|
+
if (!bin || !e.text || !Number.isFinite(Number(e.at))) return;
|
|
172
|
+
const key = keyOf(e);
|
|
173
|
+
if (prefetched.has(key)) return;
|
|
174
|
+
if (prefetched.size >= MAX_PREFETCH) {
|
|
175
|
+
// 队列满时只留更近的:远处的合成完了也大概率赶不上,别把近处的挤掉。
|
|
176
|
+
let farthestKey = null;
|
|
177
|
+
let farthestAt = -Infinity;
|
|
178
|
+
for (const [k, v] of prefetched) {
|
|
179
|
+
if (v.at > farthestAt) { farthestAt = v.at; farthestKey = k; }
|
|
180
|
+
}
|
|
181
|
+
if (!(Number(e.at) < farthestAt)) return;
|
|
182
|
+
const old = prefetched.get(farthestKey);
|
|
183
|
+
prefetched.delete(farthestKey);
|
|
184
|
+
if (old) discard(old);
|
|
185
|
+
}
|
|
186
|
+
const task = prefetchTail.then(() => synthEdge(e.text, { bin, voice, rate }));
|
|
187
|
+
prefetchTail = task.then(() => {}, () => {});
|
|
188
|
+
const entry = { task, at: Number(e.at) };
|
|
189
|
+
prefetched.set(key, entry);
|
|
190
|
+
task.then((r) => {
|
|
191
|
+
if (!r?.ok) {
|
|
192
|
+
if (prefetched.get(key) === entry) prefetched.delete(key);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
entry.path = r.path;
|
|
196
|
+
}).catch(() => {});
|
|
197
|
+
};
|
|
137
198
|
|
|
138
199
|
if (!bin) console.error('[voice] edge-tts 没找到,退回系统声音');
|
|
139
200
|
|
|
140
201
|
const off = api.onSpeech((e) => {
|
|
202
|
+
if (e.state === 'scheduled') {
|
|
203
|
+
prefetch(e);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
141
206
|
if (e.state !== 'due') return;
|
|
142
|
-
// **先打日志再念**:调试时关心的是"它什么时候吐字",不是"有没有声"
|
|
143
|
-
console.error(`[voice ${mmss(e.at)}] ${e.text}`);
|
|
144
207
|
// 「真的出声了」只报一次:edge 成功之后就不该再由 SAPI 兜底那条报第二遍。
|
|
145
208
|
// 展示层(悬浮窗)等的就是这个上报 —— 不是 `due`(见 src/chat-store.js)。
|
|
146
209
|
let reported = false;
|
|
@@ -168,17 +231,37 @@ export function attach(api) {
|
|
|
168
231
|
} catch { /* 上报失败不影响后面的话 */ }
|
|
169
232
|
return;
|
|
170
233
|
}
|
|
234
|
+
const key = keyOf(e);
|
|
235
|
+
const ready = prefetched.get(key);
|
|
236
|
+
if (ready) prefetched.delete(key);
|
|
237
|
+
const t0 = Date.now();
|
|
238
|
+
let audio = null;
|
|
171
239
|
if (bin) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
240
|
+
if (ready) {
|
|
241
|
+
audio = await ready.task.catch(() => ({ ok: false, reason: 'prefetch-failed' }));
|
|
242
|
+
} else {
|
|
243
|
+
audio = await synthEdge(e.text, { bin, voice, rate });
|
|
244
|
+
}
|
|
245
|
+
if (audio?.ok) {
|
|
246
|
+
console.error(`[voice ${mmss(e.at)}] ${ready ? 'prefetched' : 'synth'} `
|
|
247
|
+
+ `ready ${Date.now() - t0}ms (wait ${waited}ms): ${e.text}`);
|
|
248
|
+
if (await playEdge(audio.path, onStart)) return;
|
|
249
|
+
console.error('[voice] ffplay 失败,继续兜底');
|
|
250
|
+
} else {
|
|
251
|
+
console.error(`[voice] edge-tts 失败(${audio?.reason ?? 'unknown'}),退回系统声音`);
|
|
252
|
+
}
|
|
175
253
|
}
|
|
254
|
+
console.error(`[voice ${mmss(e.at)}] sapi ${Date.now() - t0}ms (wait ${waited}ms): ${e.text}`);
|
|
176
255
|
if (!(await speakSapi(e.text, rate, onStart))) console.error('[voice] 系统声音也不可用,只打日志');
|
|
177
256
|
}).catch((err) => console.error(`[voice] ${err?.message ?? err}`));
|
|
178
257
|
});
|
|
179
258
|
|
|
180
259
|
console.error(`[voice] 已接上(engine=${bin ? 'edge-tts' : 'sapi'},voice=${voice})`);
|
|
181
|
-
return () =>
|
|
260
|
+
return () => {
|
|
261
|
+
off();
|
|
262
|
+
for (const entry of prefetched.values()) discard(entry);
|
|
263
|
+
prefetched.clear();
|
|
264
|
+
};
|
|
182
265
|
}
|
|
183
266
|
|
|
184
267
|
export default attach;
|
package/package.json
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
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
|
-
],
|
|
71
|
-
"engines": {
|
|
72
|
-
"node": ">=20"
|
|
73
|
-
},
|
|
74
|
-
"scripts": {
|
|
75
|
-
"test": "node --test",
|
|
76
|
-
"pretest": "node scripts/sync-dep.mjs",
|
|
77
|
-
"sync:dep": "node scripts/sync-dep.mjs",
|
|
78
|
-
"prepublishOnly": "node scripts/check-syntax.mjs && node --test",
|
|
79
|
-
"check": "node scripts/check-syntax.mjs",
|
|
80
|
-
"doctor": "node bin/watch.mjs doctor",
|
|
81
|
-
"install:extension": "node bin/watch.mjs install-extension",
|
|
82
|
-
"sim": "node scripts/watch-sim.mjs",
|
|
83
|
-
"e2e": "node scripts/watch-e2e.mjs"
|
|
84
|
-
},
|
|
85
|
-
"dependencies": {
|
|
86
|
-
"dsh-video-storyboard": "^0.6.0"
|
|
87
|
-
},
|
|
88
|
-
"peerDependencies": {
|
|
89
|
-
"@deepseek-ai/dsh-tools": ">=0.1.0-rc.7"
|
|
90
|
-
},
|
|
91
|
-
"peerDependenciesMeta": {
|
|
92
|
-
"@deepseek-ai/dsh-tools": {
|
|
93
|
-
"optional": true
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
"dsh": {
|
|
97
|
-
"bundle": {
|
|
98
|
-
"patch": "./cordis.patch.yml"
|
|
99
|
-
},
|
|
100
|
-
"client": {
|
|
101
|
-
"platform": "web"
|
|
102
|
-
},
|
|
103
|
-
"catalog": {
|
|
104
|
-
"category": "tool",
|
|
105
|
-
"summary": {
|
|
106
|
-
"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.",
|
|
107
|
-
"zh": "和只有文字的智能体一起看视频:跟着你真实的播放位置,一段一段把画面和台词交到它手上,在每段结束前说完。"
|
|
108
|
-
},
|
|
109
|
-
"capabilities": [
|
|
110
|
-
"fs",
|
|
111
|
-
"shell"
|
|
112
|
-
]
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-watch-together",
|
|
3
|
+
"version": "0.2.6",
|
|
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
|
+
],
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=20"
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"test": "node --test",
|
|
76
|
+
"pretest": "node scripts/sync-dep.mjs",
|
|
77
|
+
"sync:dep": "node scripts/sync-dep.mjs",
|
|
78
|
+
"prepublishOnly": "node scripts/check-syntax.mjs && node --test",
|
|
79
|
+
"check": "node scripts/check-syntax.mjs",
|
|
80
|
+
"doctor": "node bin/watch.mjs doctor",
|
|
81
|
+
"install:extension": "node bin/watch.mjs install-extension",
|
|
82
|
+
"sim": "node scripts/watch-sim.mjs",
|
|
83
|
+
"e2e": "node scripts/watch-e2e.mjs"
|
|
84
|
+
},
|
|
85
|
+
"dependencies": {
|
|
86
|
+
"dsh-video-storyboard": "^0.6.0"
|
|
87
|
+
},
|
|
88
|
+
"peerDependencies": {
|
|
89
|
+
"@deepseek-ai/dsh-tools": ">=0.1.0-rc.7"
|
|
90
|
+
},
|
|
91
|
+
"peerDependenciesMeta": {
|
|
92
|
+
"@deepseek-ai/dsh-tools": {
|
|
93
|
+
"optional": true
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"dsh": {
|
|
97
|
+
"bundle": {
|
|
98
|
+
"patch": "./cordis.patch.yml"
|
|
99
|
+
},
|
|
100
|
+
"client": {
|
|
101
|
+
"platform": "web"
|
|
102
|
+
},
|
|
103
|
+
"catalog": {
|
|
104
|
+
"category": "tool",
|
|
105
|
+
"summary": {
|
|
106
|
+
"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.",
|
|
107
|
+
"zh": "和只有文字的智能体一起看视频:跟着你真实的播放位置,一段一段把画面和台词交到它手上,在每段结束前说完。"
|
|
108
|
+
},
|
|
109
|
+
"capabilities": [
|
|
110
|
+
"fs",
|
|
111
|
+
"shell"
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|