dsh-aiyayi 1.18.0 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/lib/client.js +138 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
> (`dev-ledger/`,不进公开仓、不随 npm 包发布)。
|
|
6
6
|
> 版本事实以 npm registry 为准。文中「坑 #N」指下方「已知坑」清单的编号。
|
|
7
7
|
|
|
8
|
+
## 1.19.0(2026-11-26)
|
|
9
|
+
- **Web 客户端:朗读引擎可切换,晓晓上线**:右键朗读开关(🔊/🔇)弹出引擎菜单,可在「✦ 晓晓(微软在线神经音色 zh-CN-XiaoxiaoNeural)」与「系统语音」之间一键互切;当前是晓晓时按钮带 ✦ 徽标。选晓晓需要本机跑着 edge-tts 合成服务(`python -m edge_tts` 生态,监听 `127.0.0.1:52123`,见仓库 tools 说明),没跑时朗读会红闪 ⚠ 提示并自动重试一次,之后静默回退无声——想回系统语音就右键切回去。
|
|
10
|
+
- **Web 客户端:晓晓模式不挑浏览器**:晓晓模式不走浏览器 `speechSynthesis`(文本发本地服务合成 mp3 回来播),所以没有语音合成能力的内嵌 WebView 也能出声;引擎菜单在哑窗口同样可右键呼出。
|
|
11
|
+
- **兼容性**:不装 edge-tts 服务时一切照旧——引擎开关默认「系统语音」,原自动朗读行为(1.17.0 引入)不变。
|
|
12
|
+
- 这版没有破坏性变更,你不需要做任何操作;升级后重启 DSH 生效(patchReload 不拾取 bundle 内变化,见坑 #37)。
|
|
13
|
+
|
|
8
14
|
## 1.18.0(2026-11-26)
|
|
9
15
|
- **新增:GET /api/aiyayi/auth-url 端点**:登录态保护(挂在 `/api` 认证栅栏后,未登录 401),返回带认证的完整 web URL;响应 `no-store`;基底 URL 优先 `--public-url` 指定的对外地址。
|
|
10
16
|
- **Web 客户端:哑窗口点击 🔊 现在能自救**:无 `speechSynthesis` 的内嵌 WebView 里,点击置灰的 🔊 按钮会自动复制带认证的完整 URL 到剪贴板(剪贴板不可用时降级为弹窗展示 URL 手动复制),粘到 Chrome / Edge / Firefox 打开即可自动朗读;文案含安全提示「此 URL 是长期有效的引擎钥匙,自用可以,别发给别人」。
|
package/README.md
CHANGED
|
@@ -131,7 +131,7 @@ npm 包为平铺结构(仓库若保留 bundle/ 子目录,发布时把其内
|
|
|
131
131
|
|
|
132
132
|
配置脚本(create-bot.js)、卡片渲染与历史修复等细节见 **[飞书接入与排障](./docs/飞书接入与排障.md)**。
|
|
133
133
|
|
|
134
|
-
- **自动朗读(TTS)需要带语音合成的浏览器**:dsh web 页面的 🔊 自动朗读开关依赖 `speechSynthesis`;内嵌 WebView(如 DSH-Go App 窗口)普遍没有它,自动朗读在里面天然无声——这不是 bug,请用 **Chrome / Edge / Firefox** 打开 dsh web 启动时打印的**带 token 的 URL**(1.18.0 起,在哑窗口里点 🔊 按钮可直接复制该 URL
|
|
134
|
+
- **自动朗读(TTS)需要带语音合成的浏览器**:dsh web 页面的 🔊 自动朗读开关依赖 `speechSynthesis`;内嵌 WebView(如 DSH-Go App 窗口)普遍没有它,自动朗读在里面天然无声——这不是 bug,请用 **Chrome / Edge / Firefox** 打开 dsh web 启动时打印的**带 token 的 URL**(1.18.0 起,在哑窗口里点 🔊 按钮可直接复制该 URL 到剪贴板)。不支持时开关按钮会置灰并弹提示。**1.19.0 起有第二条路**:右键朗读开关切「✦ 晓晓」引擎,文本发本机 edge-tts 服务(`127.0.0.1:52123`)合成 mp3 播放,不走 `speechSynthesis`,内嵌 WebView 也能出声;服务没跑时按钮红闪 ⚠ 提示。
|
|
135
135
|
|
|
136
136
|
## 更新日志
|
|
137
137
|
|
package/lib/client.js
CHANGED
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
// 复制到剪贴板并用弹窗提示正路(用 Chrome / Edge / Firefox 打开即可自动
|
|
16
16
|
// 朗读);剪贴板不可用时降级为 prompt 手动复制,接口失败弹失败说明。
|
|
17
17
|
// 朗读全链路不启动。支持时行为完全不变。
|
|
18
|
+
// - edge-tts 桥(1.19.0):localStorage["dsh-aiyayi-tts.engine"] === "edge" 时,
|
|
19
|
+
// 朗读文本转投本地合成服务(http://127.0.0.1:52123/tts,微软在线神经音色
|
|
20
|
+
// zh-CN-XiaoxiaoNeural 晓晓),mp3 用 <audio> 播放,不依赖 speechSynthesis;
|
|
21
|
+
// 服务不在/失败时静默回退无声,不炸页面。未设或其余值 = 原 Web Speech 逻辑。
|
|
18
22
|
|
|
19
23
|
window.__ModuleLoader__?.load({
|
|
20
24
|
id: "dsh-aiyayi",
|
|
@@ -25,6 +29,12 @@ window.__ModuleLoader__?.load({
|
|
|
25
29
|
const NS = "aiyayi-tts";
|
|
26
30
|
const STORE_KEY = "dsh-aiyayi-tts.enabled";
|
|
27
31
|
const MAX_SPEAK_CHARS = 2000;
|
|
32
|
+
// 1.19.0 edge-tts 桥:engine 开关切朗读后端。'edge' 走本地合成服务
|
|
33
|
+
// (G:\阿依娅伊\tools\edge_tts_server.py,127.0.0.1:52123,微软晓晓
|
|
34
|
+
// zh-CN-XiaoxiaoNeural);其余/未设 = 'default',原 speechSynthesis 兜底。
|
|
35
|
+
const ENGINE_KEY = "dsh-aiyayi-tts.engine";
|
|
36
|
+
const EDGE_TTS_ENDPOINT = "http://127.0.0.1:52123/tts";
|
|
37
|
+
const EDGE_TTS_RATE = "+10%"; // 原 rate 1.1 的 edge-tts 口径近似
|
|
28
38
|
|
|
29
39
|
//#region 开关状态
|
|
30
40
|
function readEnabled() {
|
|
@@ -40,6 +50,15 @@ window.__ModuleLoader__?.load({
|
|
|
40
50
|
} catch {}
|
|
41
51
|
}
|
|
42
52
|
let enabled = readEnabled();
|
|
53
|
+
|
|
54
|
+
/** 当前朗读引擎:localStorage[ENGINE_KEY] === 'edge' 时走 edge-tts 桥,否则 default。 */
|
|
55
|
+
function readEngine() {
|
|
56
|
+
try {
|
|
57
|
+
return localStorage.getItem(ENGINE_KEY) === "edge" ? "edge" : "default";
|
|
58
|
+
} catch {
|
|
59
|
+
return "default";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
43
62
|
//#endregion
|
|
44
63
|
|
|
45
64
|
//#region 文本清洗:把 markdown/URL 清成适合念出来的话
|
|
@@ -71,7 +90,9 @@ window.__ModuleLoader__?.load({
|
|
|
71
90
|
//#region 语音
|
|
72
91
|
// 能力检测(1.17.0):内嵌 WebView(如 DSH-Go App 窗口)常无 speechSynthesis,
|
|
73
92
|
// 直接打开会"点了开关也没声"。检测口径:对象不存在,或 speak 不是函数,都算不支持。
|
|
74
|
-
|
|
93
|
+
// 1.19.0:engine=edge 时走本地 edge-tts 服务,不依赖 speechSynthesis,也算支持。
|
|
94
|
+
const hasWebSpeech = typeof window !== "undefined" && typeof window.speechSynthesis !== "undefined" && typeof window.speechSynthesis?.speak === "function";
|
|
95
|
+
const ttsSupported = () => hasWebSpeech || readEngine() === "edge";
|
|
75
96
|
let cachedVoice;
|
|
76
97
|
if (typeof window !== "undefined" && window.speechSynthesis?.addEventListener) {
|
|
77
98
|
window.speechSynthesis.addEventListener("voiceschanged", () => {
|
|
@@ -88,11 +109,58 @@ window.__ModuleLoader__?.load({
|
|
|
88
109
|
cachedVoice = zh.find((voice) => (voice.lang || "").toLowerCase() === "zh-cn") ?? zh[0];
|
|
89
110
|
return cachedVoice;
|
|
90
111
|
}
|
|
112
|
+
//#region edge-tts 桥(1.19.0):文本 POST 给本地合成服务,mp3 回来用 <audio> 播
|
|
113
|
+
let edgeAudio;
|
|
114
|
+
function stopEdgeAudio() {
|
|
115
|
+
if (edgeAudio) {
|
|
116
|
+
try {
|
|
117
|
+
edgeAudio.pause();
|
|
118
|
+
} catch {}
|
|
119
|
+
edgeAudio = undefined;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async function speakViaEdge(cleanText) {
|
|
123
|
+
stopEdgeAudio();
|
|
124
|
+
const url = `${EDGE_TTS_ENDPOINT}?text=${encodeURIComponent(cleanText)}&rate=${encodeURIComponent(EDGE_TTS_RATE)}`;
|
|
125
|
+
const response = await fetch(url, { cache: "no-store" });
|
|
126
|
+
if (!response.ok) throw new Error(`edge-tts HTTP ${response.status}`);
|
|
127
|
+
const blob = await response.blob();
|
|
128
|
+
stopEdgeAudio(); // 合成期间可能有更新消息进来,播放前再掐一次
|
|
129
|
+
const audio = new Audio(URL.createObjectURL(blob));
|
|
130
|
+
edgeAudio = audio;
|
|
131
|
+
audio.play().catch(() => {});
|
|
132
|
+
}
|
|
133
|
+
/** edge 桥故障提示:开关上 ⚠ 红色一瞬(服务不在/合成失败给个看得见的信号,不弹窗不打扰)。 */
|
|
134
|
+
function flashEdgeFault() {
|
|
135
|
+
if (typeof document === "undefined") return;
|
|
136
|
+
const node = document.getElementById("dsh-aiyayi-tts-toggle");
|
|
137
|
+
if (!node) return;
|
|
138
|
+
node.textContent = `${node.textContent}⚠`;
|
|
139
|
+
node.style.color = "#e5484d";
|
|
140
|
+
setTimeout(() => {
|
|
141
|
+
node.style.color = "";
|
|
142
|
+
refreshButton(node);
|
|
143
|
+
}, 2500);
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
|
|
91
147
|
function speak(text) {
|
|
92
|
-
const synth = window.speechSynthesis;
|
|
93
|
-
if (!synth) return;
|
|
94
148
|
const clean = cleanForSpeech(text);
|
|
95
149
|
if (!clean) return;
|
|
150
|
+
if (readEngine() === "edge") {
|
|
151
|
+
// 服务不在/合成失败:红闪提示 + 1.5s 后重试一次(期间服务可能被自启机制拉起)。
|
|
152
|
+
// 注意:浏览器安全模型不允许页面拉起本机进程——"自动启动服务"做不到,
|
|
153
|
+
// 自愈闭环靠开机自启(Startup bat)或 set_tts_engine 的 ensureServer。
|
|
154
|
+
speakViaEdge(clean).catch(() => {
|
|
155
|
+
flashEdgeFault();
|
|
156
|
+
setTimeout(() => {
|
|
157
|
+
speakViaEdge(clean).catch(() => {});
|
|
158
|
+
}, 1500);
|
|
159
|
+
});
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const synth = window.speechSynthesis;
|
|
163
|
+
if (!synth) return;
|
|
96
164
|
// 新消息先掐掉上一条,避免叠音
|
|
97
165
|
synth.cancel();
|
|
98
166
|
const utterance = new SpeechSynthesisUtterance(clean);
|
|
@@ -104,6 +172,7 @@ window.__ModuleLoader__?.load({
|
|
|
104
172
|
synth.speak(utterance);
|
|
105
173
|
}
|
|
106
174
|
function stopSpeaking() {
|
|
175
|
+
stopEdgeAudio();
|
|
107
176
|
window.speechSynthesis?.cancel();
|
|
108
177
|
}
|
|
109
178
|
//#endregion
|
|
@@ -167,7 +236,7 @@ window.__ModuleLoader__?.load({
|
|
|
167
236
|
boxShadow: "0 2px 8px rgba(0,0,0,.15)",
|
|
168
237
|
transition: "opacity .15s"
|
|
169
238
|
});
|
|
170
|
-
if (!ttsSupported) {
|
|
239
|
+
if (!ttsSupported()) {
|
|
171
240
|
// 哑窗口:按钮置灰 + 禁用态样式,点击复制带认证的完整 URL(B 半逻辑)
|
|
172
241
|
button.style.cursor = "not-allowed";
|
|
173
242
|
button.style.filter = "grayscale(1)";
|
|
@@ -190,15 +259,73 @@ window.__ModuleLoader__?.load({
|
|
|
190
259
|
});
|
|
191
260
|
button.addEventListener("click", () => onToggle());
|
|
192
261
|
}
|
|
262
|
+
// 右键弹引擎切换菜单(晓晓/系统),哑窗口也能切到 edge 续命
|
|
263
|
+
button.addEventListener("contextmenu", (event) => {
|
|
264
|
+
event.preventDefault();
|
|
265
|
+
toggleEngineMenu();
|
|
266
|
+
});
|
|
193
267
|
document.body.appendChild(button);
|
|
194
268
|
refreshButton(button);
|
|
195
269
|
}
|
|
196
270
|
function refreshButton(button) {
|
|
197
271
|
const node = button ?? document.getElementById("dsh-aiyayi-tts-toggle");
|
|
198
272
|
if (!node) return;
|
|
199
|
-
|
|
200
|
-
node.
|
|
273
|
+
// ✦ 徽标:当前 engine=edge(晓晓在线合成)时挂在 🔊/🔇 后面
|
|
274
|
+
node.textContent = (enabled ? "🔊" : "🔇") + (readEngine() === "edge" ? "✦" : "");
|
|
275
|
+
node.style.opacity = !ttsSupported() ? "0.3" : enabled ? "1" : "0.55";
|
|
201
276
|
}
|
|
277
|
+
//#region 引擎切换小控件:右键朗读开关弹出,晓晓 ↔ 系统一键互切
|
|
278
|
+
function toggleEngineMenu() {
|
|
279
|
+
const existing = document.getElementById("dsh-aiyayi-tts-engine-menu");
|
|
280
|
+
if (existing) {
|
|
281
|
+
existing.remove();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const menu = document.createElement("div");
|
|
285
|
+
menu.id = "dsh-aiyayi-tts-engine-menu";
|
|
286
|
+
const current = readEngine();
|
|
287
|
+
const items = [
|
|
288
|
+
{ value: "edge", label: "✦ 晓晓(微软在线)" },
|
|
289
|
+
{ value: "default", label: "系统语音(兜底)" },
|
|
290
|
+
];
|
|
291
|
+
for (const item of items) {
|
|
292
|
+
const row = document.createElement("div");
|
|
293
|
+
row.textContent = `${current === item.value ? "●" : "○"} ${item.label}`;
|
|
294
|
+
Object.assign(row.style, {
|
|
295
|
+
padding: "6px 14px",
|
|
296
|
+
cursor: "pointer",
|
|
297
|
+
whiteSpace: "nowrap",
|
|
298
|
+
fontSize: "12px",
|
|
299
|
+
color: current === item.value ? "var(--dsw-alias-label-primary, #111)" : "var(--dsw-alias-label-secondary, #666)",
|
|
300
|
+
});
|
|
301
|
+
row.addEventListener("click", () => {
|
|
302
|
+
try {
|
|
303
|
+
localStorage.setItem(ENGINE_KEY, item.value);
|
|
304
|
+
} catch {}
|
|
305
|
+
menu.remove();
|
|
306
|
+
refreshButton();
|
|
307
|
+
});
|
|
308
|
+
menu.appendChild(row);
|
|
309
|
+
}
|
|
310
|
+
Object.assign(menu.style, {
|
|
311
|
+
position: "fixed",
|
|
312
|
+
right: "12px",
|
|
313
|
+
bottom: `${128 + BUTTON_SIZE + 6}px`,
|
|
314
|
+
background: "var(--dsw-alias-bg-base, #fff)",
|
|
315
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.4))",
|
|
316
|
+
borderRadius: "8px",
|
|
317
|
+
boxShadow: "0 2px 8px rgba(0,0,0,.15)",
|
|
318
|
+
padding: "4px 0",
|
|
319
|
+
zIndex: "61",
|
|
320
|
+
userSelect: "none",
|
|
321
|
+
});
|
|
322
|
+
document.body.appendChild(menu);
|
|
323
|
+
// 点菜单外面任意处收起(capture 先于菜单行自己的 click,contains 放行行内点击)
|
|
324
|
+
document.addEventListener("click", (event) => {
|
|
325
|
+
if (!menu.contains(event.target)) menu.remove();
|
|
326
|
+
}, { once: true, capture: true });
|
|
327
|
+
}
|
|
328
|
+
//#endregion
|
|
202
329
|
function mountButton(onToggle) {
|
|
203
330
|
if (typeof document === "undefined") return;
|
|
204
331
|
if (document.readyState === "loading") {
|
|
@@ -270,10 +397,14 @@ window.__ModuleLoader__?.load({
|
|
|
270
397
|
refreshButton();
|
|
271
398
|
if (!enabled) stopSpeaking();
|
|
272
399
|
});
|
|
400
|
+
// 验证/调试钩子:控制台 window.__aiyayiTts.speak("文本") 可直接触发一次朗读
|
|
401
|
+
try {
|
|
402
|
+
window.__aiyayiTts = { speak: (raw) => speak(raw) };
|
|
403
|
+
} catch {}
|
|
273
404
|
ctx.effect(() => () => {
|
|
274
405
|
stopSpeaking();
|
|
275
406
|
}, "aiyayi-tts: stop speech on teardown");
|
|
276
|
-
if (!ttsSupported) return; // 哑窗口:朗读全链路(事件订阅)不启动
|
|
407
|
+
if (!ttsSupported()) return; // 哑窗口:朗读全链路(事件订阅)不启动
|
|
277
408
|
await ctx.inject(["sessions"], (scope) => {
|
|
278
409
|
const sessions = scope.sessions ?? scope.get?.("sessions");
|
|
279
410
|
if (!sessions?.list || typeof sessions.binding !== "function") return;
|