dsh-voice-mode 0.7.22 → 0.7.24
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/README.en.md +53 -70
- package/README.md +31 -25
- package/THIRD_PARTY_NOTICES.md +4 -4
- package/assets/architecture.svg +35 -1
- package/lib/client.js +19 -6
- package/lib/index.js +24 -7
- package/lib/msedge-tts.cjs +679 -135
- package/package.json +4 -4
package/lib/client.js
CHANGED
|
@@ -1396,7 +1396,8 @@ var import_react = require("react");
|
|
|
1396
1396
|
var zh = {
|
|
1397
1397
|
stateVoiceMode: "\u8BED\u97F3\u6A21\u5F0F",
|
|
1398
1398
|
ttsNoticeFail: "\u6717\u8BFB\u8FDE\u63A5\u5931\u8D25\uFF1A\u6B63\u5728\u91CD\u8BD5\u2026",
|
|
1399
|
-
ttsSkipNotice: "\u6709\u4E00\u53E5\u6717\u8BFB\u5931\u8D25\uFF0C\u5DF2\u8DF3\u8FC7\uFF08\
|
|
1399
|
+
ttsSkipNotice: "\u6709\u4E00\u53E5\u6717\u8BFB\u5931\u8D25\uFF0C\u5DF2\u8DF3\u8FC7\uFF08\u53EF\u91CD\u53D1\u8FD9\u6761\u6D88\u606F\uFF09",
|
|
1400
|
+
ttsUnavailableNotice: "\u6717\u8BFB\u8FDE\u7EED\u5931\u8D25\uFF1A\u4E91\u7AEF\u6717\u8BFB\u6682\u4E0D\u53EF\u7528\u3002\u53EF\u7A0D\u540E\u518D\u8BD5\uFF0C\u6216\u5728\u8BBE\u7F6E\u91CC\u628A\u6717\u8BFB\u5F15\u64CE\u5207\u6362\u4E3A\u672C\u5730 VITS / Kokoro",
|
|
1400
1401
|
enterFail: "\u8FDB\u5165\u8BED\u97F3\u6A21\u5F0F\u5931\u8D25",
|
|
1401
1402
|
disabled: "\u8BED\u97F3\u6A21\u5F0F\u5DF2\u7981\u7528\uFF08\u63D2\u4EF6 enabled=false\uFF09",
|
|
1402
1403
|
sendFailKept: "\u53D1\u9001\u5931\u8D25\uFF0C\u5DF2\u4FDD\u7559\u5728\u8349\u7A3F",
|
|
@@ -1631,7 +1632,8 @@ var zh = {
|
|
|
1631
1632
|
var en = {
|
|
1632
1633
|
stateVoiceMode: "Voice Mode",
|
|
1633
1634
|
ttsNoticeFail: "Read-aloud connection failed: retrying\u2026",
|
|
1634
|
-
ttsSkipNotice: "One sentence failed to read and was skipped (
|
|
1635
|
+
ttsSkipNotice: "One sentence failed to read and was skipped (resend the message to retry)",
|
|
1636
|
+
ttsUnavailableNotice: "Read-aloud keeps failing: cloud TTS is unavailable. Try again later, or switch the read-aloud engine to local VITS / Kokoro in settings",
|
|
1635
1637
|
enterFail: "Failed to enter voice mode",
|
|
1636
1638
|
disabled: "Voice mode disabled (plugin enabled=false)",
|
|
1637
1639
|
sendFailKept: "Send failed; text kept in draft",
|
|
@@ -2751,7 +2753,7 @@ function EngineStatusInline() {
|
|
|
2751
2753
|
children: acting ? acting === "clean" ? t("ttsDeleting") : t("ttsDownloading") : action === "clean" ? t("ttsDelete") : t("ttsDownload")
|
|
2752
2754
|
}
|
|
2753
2755
|
),
|
|
2754
|
-
tts.error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: 11, color: "var(--dsw-alias-state-error-primary)", flexBasis: "100%" }, children: tts.errorCode === "kokoro_needs_node" ? t("errKokoroNeedsNode") :
|
|
2756
|
+
tts.error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: 11, color: "var(--dsw-alias-state-error-primary)", flexBasis: "100%" }, children: tts.errorCode === "kokoro_needs_node" ? t("errKokoroNeedsNode") : t("engineError") })
|
|
2755
2757
|
] });
|
|
2756
2758
|
}
|
|
2757
2759
|
function ModelStatusView() {
|
|
@@ -3101,7 +3103,7 @@ var TELEMETRY_VIEW = [
|
|
|
3101
3103
|
{ stage: "first-tts-chunk", key: "telFirstChunk" },
|
|
3102
3104
|
{ stage: "first-audio-played", key: "telFirstPlayed" }
|
|
3103
3105
|
];
|
|
3104
|
-
var BUILD_TAG = "
|
|
3106
|
+
var BUILD_TAG = "66b3fc0";
|
|
3105
3107
|
var TELEMETRY_FLAG = "dsh-voice-mode.telemetry";
|
|
3106
3108
|
var telemetryEnabled = typeof localStorage !== "undefined" && localStorage.getItem(TELEMETRY_FLAG) === "1";
|
|
3107
3109
|
console.log("[dsh-voice] build=" + BUILD_TAG);
|
|
@@ -3696,9 +3698,20 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
3696
3698
|
try {
|
|
3697
3699
|
const p = JSON.parse(e.data);
|
|
3698
3700
|
if (p.sessionId !== activeSessionId) return;
|
|
3699
|
-
|
|
3701
|
+
const down = (p.streak ?? 1) >= 2;
|
|
3702
|
+
const msg = down ? t("ttsUnavailableNotice") : t("ttsSkipNotice");
|
|
3703
|
+
ui.ttsNotice = msg;
|
|
3704
|
+
if (down && p.streak === 2) {
|
|
3705
|
+
ui.error = msg;
|
|
3706
|
+
setTimeout(() => {
|
|
3707
|
+
if (ui.error === msg) {
|
|
3708
|
+
ui.error = null;
|
|
3709
|
+
notify();
|
|
3710
|
+
}
|
|
3711
|
+
}, 8e3);
|
|
3712
|
+
}
|
|
3700
3713
|
notify();
|
|
3701
|
-
debugLog("tts-skip", { text: (p.text ?? "").slice(0, 40) });
|
|
3714
|
+
debugLog("tts-skip", { text: (p.text ?? "").slice(0, 40), streak: p.streak });
|
|
3702
3715
|
} catch {
|
|
3703
3716
|
}
|
|
3704
3717
|
});
|
package/lib/index.js
CHANGED
|
@@ -205,7 +205,8 @@ async function ensureModelFile(opts) {
|
|
|
205
205
|
lastError = String(e);
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
|
-
|
|
208
|
+
if (lastError) console.warn(`[dsh-voice-mode] model download failed: ${spec.file}: ${lastError}`);
|
|
209
|
+
broadcast("asr-error", { file: spec.file, reason: "checksum_or_download_failed" });
|
|
209
210
|
return false;
|
|
210
211
|
}
|
|
211
212
|
async function downloadVerified(opts) {
|
|
@@ -267,6 +268,11 @@ async function downloadVerified(opts) {
|
|
|
267
268
|
await rename(partPath, localPath);
|
|
268
269
|
return true;
|
|
269
270
|
}
|
|
271
|
+
function isSafeModelRel(rel, subdir) {
|
|
272
|
+
if (!rel.startsWith(subdir + "/")) return false;
|
|
273
|
+
if (rel.includes("\\") || rel.includes("\0")) return false;
|
|
274
|
+
return !rel.split("/").some((seg) => seg === "" || seg === "." || seg === "..");
|
|
275
|
+
}
|
|
270
276
|
async function ensureModelTree(opts) {
|
|
271
277
|
const { repo, repoDir, subdir, primaryHost, allowCustomHost, broadcast } = opts;
|
|
272
278
|
const hosts = [...new Set([primaryHost, HOST_PRIMARY, HOST_FALLBACK].filter(Boolean))];
|
|
@@ -278,7 +284,7 @@ async function ensureModelTree(opts) {
|
|
|
278
284
|
const res = await fetch(host + "/api/models/" + repo + "?blobs=true", { headers: { "user-agent": "dsh-voice-mode" } });
|
|
279
285
|
if (res.ok) {
|
|
280
286
|
const j = await res.json();
|
|
281
|
-
tree = (j.siblings ?? []).map((s) => s.rfilename ?? "").filter((f) =>
|
|
287
|
+
tree = (j.siblings ?? []).map((s) => s.rfilename ?? "").filter((f) => isSafeModelRel(f, subdir));
|
|
282
288
|
if (tree.length > 0) break;
|
|
283
289
|
}
|
|
284
290
|
} catch {
|
|
@@ -1181,7 +1187,7 @@ var TtsQueue = class {
|
|
|
1181
1187
|
enqueue(sessionId, text) {
|
|
1182
1188
|
let q = this.queues.get(sessionId);
|
|
1183
1189
|
if (!q) {
|
|
1184
|
-
q = { pending: [], busy: false, seq: 0, epoch: 0, errorNotified: false, backoff: 0 };
|
|
1190
|
+
q = { pending: [], busy: false, seq: 0, epoch: 0, errorNotified: false, backoff: 0, failStreak: 0 };
|
|
1185
1191
|
this.queues.set(sessionId, q);
|
|
1186
1192
|
}
|
|
1187
1193
|
if (q.pending.length >= 500) {
|
|
@@ -1234,10 +1240,12 @@ var TtsQueue = class {
|
|
|
1234
1240
|
}
|
|
1235
1241
|
if (item.epoch !== q.epoch) continue;
|
|
1236
1242
|
if (buf === null) {
|
|
1237
|
-
|
|
1243
|
+
q.failStreak++;
|
|
1244
|
+
this.onSkip?.(sessionId, item.text, q.failStreak);
|
|
1238
1245
|
continue;
|
|
1239
1246
|
}
|
|
1240
1247
|
q.errorNotified = false;
|
|
1248
|
+
q.failStreak = 0;
|
|
1241
1249
|
q.backoff = 0;
|
|
1242
1250
|
const sentenceId = q.seq++;
|
|
1243
1251
|
const mime = this.engine.mime;
|
|
@@ -1942,7 +1950,8 @@ var RateLimiter = class {
|
|
|
1942
1950
|
var en = {
|
|
1943
1951
|
stateVoiceMode: "Voice Mode",
|
|
1944
1952
|
ttsNoticeFail: "Read-aloud connection failed: retrying\u2026",
|
|
1945
|
-
ttsSkipNotice: "One sentence failed to read and was skipped (
|
|
1953
|
+
ttsSkipNotice: "One sentence failed to read and was skipped (resend the message to retry)",
|
|
1954
|
+
ttsUnavailableNotice: "Read-aloud keeps failing: cloud TTS is unavailable. Try again later, or switch the read-aloud engine to local VITS / Kokoro in settings",
|
|
1946
1955
|
enterFail: "Failed to enter voice mode",
|
|
1947
1956
|
disabled: "Voice mode disabled (plugin enabled=false)",
|
|
1948
1957
|
sendFailKept: "Send failed; text kept in draft",
|
|
@@ -2295,7 +2304,7 @@ function readLegacyVoiceSettings(dir, keys) {
|
|
|
2295
2304
|
var name = "voice-mode";
|
|
2296
2305
|
var NS_VOICE_MODE = "voice-mode";
|
|
2297
2306
|
var BASE_PATH = "/voice-mode";
|
|
2298
|
-
var PREVIEW_NETWORK_PATTERN = /fetch failed|ECONN|ENOTFOUND|getaddrinfo|ETIMEDOUT|EAI_AGAIN|network|unreachable|socket hang up|aborted/i;
|
|
2307
|
+
var PREVIEW_NETWORK_PATTERN = /fetch failed|ECONN|ENOTFOUND|getaddrinfo|ETIMEDOUT|EAI_AGAIN|network|unreachable|socket hang up|aborted|WebSocket error/i;
|
|
2299
2308
|
var PREVIEW_ENGINE_PATTERN = /model download|model verify|init failed|child exited|tts child|local TTS|prepare|sherpa|local Kokoro/i;
|
|
2300
2309
|
var PREVIEW_TEXT_PATTERN = /empty or invalid audio|invalid audio|invalid text|too long|truncat/i;
|
|
2301
2310
|
function classifyPreviewError(msg) {
|
|
@@ -2663,7 +2672,8 @@ function apply(ctx, config) {
|
|
|
2663
2672
|
engine: makeEngine(engineKind),
|
|
2664
2673
|
onError: (sessionId) => broadcast("tts-error", { sessionId }),
|
|
2665
2674
|
// 单句重试耗尽被跳过:显式下行(客户端提示 + 诊断),不再静默丢句。
|
|
2666
|
-
|
|
2675
|
+
// streak = 连续被跳过的句数:客户端据此区分偶发抖动与「云端整体不可用」(如服务端拒绝握手)。
|
|
2676
|
+
onSkip: (sessionId, text, streak) => broadcast("tts-skip", { sessionId, text: text.slice(0, 80), streak })
|
|
2667
2677
|
});
|
|
2668
2678
|
queue.updateVoice(vset.voice, vset.rate);
|
|
2669
2679
|
const unsubscribe = queue.subscribe((frame) => broadcast("audio", frame));
|
|
@@ -2951,6 +2961,13 @@ function apply(ctx, config) {
|
|
|
2951
2961
|
path: `${base}/models/retry`,
|
|
2952
2962
|
handler: (req, res) => {
|
|
2953
2963
|
if (denyNonLoopback(req, res)) return;
|
|
2964
|
+
if (req.method !== "POST") {
|
|
2965
|
+
res.statusCode = 405;
|
|
2966
|
+
res.setHeader("allow", "POST");
|
|
2967
|
+
res.end();
|
|
2968
|
+
return;
|
|
2969
|
+
}
|
|
2970
|
+
if (denyCrossOrigin(req, res)) return;
|
|
2954
2971
|
if (!config.enabled) {
|
|
2955
2972
|
respondJson2(res, 403, { code: "voice_disabled", error: "voice mode disabled" });
|
|
2956
2973
|
return;
|