dsh-voice-mode 0.7.26 → 0.7.28
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 +21 -11
- package/README.md +34 -11
- package/lib/client.js +1234 -111
- package/lib/index.js +472 -56
- package/lib/msedge-tts.cjs +11 -5
- package/package.json +3 -2
package/lib/client.js
CHANGED
|
@@ -510,6 +510,7 @@ function createAsrEngine(config, sessionId) {
|
|
|
510
510
|
let preRollStartWall = 0;
|
|
511
511
|
let preRollSeedWall = null;
|
|
512
512
|
let wasPlaying = false;
|
|
513
|
+
let gateQueryScope = false;
|
|
513
514
|
let partialFailStreak = 0;
|
|
514
515
|
let detectFailStreak = 0;
|
|
515
516
|
let salvagedSegment = false;
|
|
@@ -560,6 +561,14 @@ function createAsrEngine(config, sessionId) {
|
|
|
560
561
|
return out;
|
|
561
562
|
};
|
|
562
563
|
const sliceSince = (from) => sliceChunks(segment, from);
|
|
564
|
+
const deliverIsSpeech = (speech) => {
|
|
565
|
+
gateQueryScope = true;
|
|
566
|
+
try {
|
|
567
|
+
config.onIsSpeech?.(speech);
|
|
568
|
+
} finally {
|
|
569
|
+
gateQueryScope = false;
|
|
570
|
+
}
|
|
571
|
+
};
|
|
563
572
|
const requestPartial = async () => {
|
|
564
573
|
if (partialInFlight || segment.length === 0) return;
|
|
565
574
|
await resetGate;
|
|
@@ -624,6 +633,7 @@ function createAsrEngine(config, sessionId) {
|
|
|
624
633
|
if (epoch !== segmentEpoch) return;
|
|
625
634
|
if (state === "wake" && wakeEnabled) {
|
|
626
635
|
uploadedSamples = Math.max(uploadedSamples, from + samples.length);
|
|
636
|
+
partialFailStreak = 0;
|
|
627
637
|
emit(partialListeners, out.text ?? "");
|
|
628
638
|
if (matchWakeWord(out.text ?? "", wakeWord)) {
|
|
629
639
|
wakeConsumed = true;
|
|
@@ -633,7 +643,7 @@ function createAsrEngine(config, sessionId) {
|
|
|
633
643
|
}
|
|
634
644
|
return;
|
|
635
645
|
}
|
|
636
|
-
if (out.isSpeech !== void 0)
|
|
646
|
+
if (out.isSpeech !== void 0) deliverIsSpeech(out.isSpeech);
|
|
637
647
|
if (state === "loading-model") setState("speech");
|
|
638
648
|
uploadedSamples = Math.max(uploadedSamples, from + samples.length);
|
|
639
649
|
partialFailStreak = 0;
|
|
@@ -683,8 +693,8 @@ function createAsrEngine(config, sessionId) {
|
|
|
683
693
|
if (!res.ok) return;
|
|
684
694
|
const out = await res.json();
|
|
685
695
|
if (epoch !== segmentEpoch || gen !== detectGeneration) return;
|
|
686
|
-
if (out.isSpeech !== void 0) config.onIsSpeech?.(out.isSpeech);
|
|
687
696
|
if (out.isSpeech === true && preRollSeedWall === null) preRollSeedWall = reqBodyStartWall - 250;
|
|
697
|
+
if (out.isSpeech !== void 0) deliverIsSpeech(out.isSpeech);
|
|
688
698
|
detectFailStreak = 0;
|
|
689
699
|
detectSent += samples.length;
|
|
690
700
|
while (detectChunks.length > 0 && detectSent >= detectChunks[0].length) {
|
|
@@ -883,8 +893,20 @@ function createAsrEngine(config, sessionId) {
|
|
|
883
893
|
data = echo.process(data, ref);
|
|
884
894
|
}
|
|
885
895
|
let sum = 0;
|
|
886
|
-
|
|
887
|
-
|
|
896
|
+
let nonFinite = 0;
|
|
897
|
+
for (let i = 0; i < data.length; i++) {
|
|
898
|
+
const v = data[i];
|
|
899
|
+
if (Number.isFinite(v)) sum += v * v;
|
|
900
|
+
else nonFinite++;
|
|
901
|
+
}
|
|
902
|
+
let rms = Math.sqrt(sum / data.length);
|
|
903
|
+
if (nonFinite > 0) {
|
|
904
|
+
const clean = new Float32Array(data);
|
|
905
|
+
for (let i = 0; i < clean.length; i++) if (!Number.isFinite(clean[i])) clean[i] = 0;
|
|
906
|
+
data = clean;
|
|
907
|
+
if (!Number.isFinite(rms)) rms = 0;
|
|
908
|
+
}
|
|
909
|
+
const frameValid = nonFinite === 0;
|
|
888
910
|
const durationMs = data.length / SAMPLE_RATE2 * 1e3;
|
|
889
911
|
for (const fn of levelListeners) {
|
|
890
912
|
try {
|
|
@@ -896,14 +918,18 @@ function createAsrEngine(config, sessionId) {
|
|
|
896
918
|
const gateRatio = Math.pow(10, (config.echoGateDb ?? 6) / 20);
|
|
897
919
|
const peakDecay = Math.pow(0.9, durationMs / 64);
|
|
898
920
|
const floorAlpha = 1 - Math.pow(0.98, durationMs / 64);
|
|
899
|
-
if (
|
|
921
|
+
if (!Number.isFinite(echoFloorRms)) echoFloorRms = 0;
|
|
922
|
+
if (!Number.isFinite(echoPeak)) echoPeak = 0;
|
|
923
|
+
if (playingNow && frameValid) {
|
|
900
924
|
latestResidualRms = rms;
|
|
901
925
|
echoPeak = Math.max(echoPeak * peakDecay, rms);
|
|
902
926
|
}
|
|
903
927
|
const doubleTalk = playingNow && echoFloorRms > 0 && rms > echoFloorRms * gateRatio;
|
|
904
928
|
if (playingNow) {
|
|
905
|
-
if (
|
|
906
|
-
|
|
929
|
+
if (frameValid) {
|
|
930
|
+
if (echoFloorRms === 0) echoFloorRms = rms;
|
|
931
|
+
else if (!doubleTalk) echoFloorRms = echoFloorRms * (1 - floorAlpha) + rms * floorAlpha;
|
|
932
|
+
}
|
|
907
933
|
} else {
|
|
908
934
|
echoPeak = 0;
|
|
909
935
|
}
|
|
@@ -1192,10 +1218,21 @@ function createAsrEngine(config, sessionId) {
|
|
|
1192
1218
|
get holding() {
|
|
1193
1219
|
return holdActive;
|
|
1194
1220
|
},
|
|
1195
|
-
/** A2.5 回声门控:当前残差是否明显高于回声地板(marginDb 默认 6dB)——判用户人声而非回声。
|
|
1221
|
+
/** A2.5 回声门控:当前残差是否明显高于回声地板(marginDb 默认 6dB)——判用户人声而非回声。
|
|
1222
|
+
* Issue #15 R15-5:本方法是客户端回声门控的**唯一询问点**——客户端在「本次检测达到
|
|
1223
|
+
* 打断确认帧数」的瞬间问本方法,答 false 即「放弃本次检测(判为回声,不打断)」。
|
|
1224
|
+
* 引擎据此作废抢救种子:被拒检测的窗口不得成为下次真打断的锚点(种子陈旧会被
|
|
1225
|
+
* Math.max 钳到环起点 → 整环 2s AI 音频并入用户消息)。作用域限定见 gateQueryScope。 */
|
|
1196
1226
|
aboveEchoFloor(marginDb = 6) {
|
|
1197
|
-
|
|
1198
|
-
|
|
1227
|
+
const pass = echoFloorRms > 0 && echoPeak > echoFloorRms * Math.pow(10, marginDb / 20);
|
|
1228
|
+
if (!pass && gateQueryScope) preRollSeedWall = null;
|
|
1229
|
+
return pass;
|
|
1230
|
+
},
|
|
1231
|
+
/** 作废抢救种子(客户端放弃本次检测时调用——语义见 AsrEngine.invalidateSalvageSeed)。
|
|
1232
|
+
* Issue #15 R15-5:补「从未问过门控」的放弃路径(确认帧数未达门槛 / 迟滞衰减归零):
|
|
1233
|
+
* 这类检测不会触发上面的门控询问点,引擎只能由客户端显式告知。 */
|
|
1234
|
+
invalidateSalvageSeed() {
|
|
1235
|
+
preRollSeedWall = null;
|
|
1199
1236
|
},
|
|
1200
1237
|
echoLevels() {
|
|
1201
1238
|
return { floorRms: echoFloorRms, residualRms: latestResidualRms, peakRms: echoPeak };
|
|
@@ -1444,7 +1481,9 @@ var NlmsAec = class {
|
|
|
1444
1481
|
const bufLen = xBuf.length;
|
|
1445
1482
|
let cursor = this.cursor;
|
|
1446
1483
|
for (let i = 0; i < n; i++) {
|
|
1447
|
-
|
|
1484
|
+
let r = i < ref.length ? ref[i] : 0;
|
|
1485
|
+
if (!Number.isFinite(r) && !Number.isNaN(r)) r = 0;
|
|
1486
|
+
xBuf[cursor] = r;
|
|
1448
1487
|
cursor = (cursor + 1) % bufLen;
|
|
1449
1488
|
this.filled = Math.min(this.filled + 1, bufLen);
|
|
1450
1489
|
const d = mic[i];
|
|
@@ -1459,10 +1498,11 @@ var NlmsAec = class {
|
|
|
1459
1498
|
idx = (idx - 1 + bufLen) % bufLen;
|
|
1460
1499
|
}
|
|
1461
1500
|
const e = d - y;
|
|
1462
|
-
|
|
1501
|
+
const eSafe = Number.isFinite(e) ? e : 0;
|
|
1502
|
+
out[i] = eSafe;
|
|
1463
1503
|
if (norm > MIN_REF_NORM && !this.frozen) {
|
|
1464
1504
|
const denom = norm + this.eps;
|
|
1465
|
-
const gain = this.mu *
|
|
1505
|
+
const gain = this.mu * eSafe / denom;
|
|
1466
1506
|
idx = (cursor - this.delay + bufLen) % bufLen;
|
|
1467
1507
|
for (let t3 = 0; t3 < this.filterLength; t3++) {
|
|
1468
1508
|
this.w[t3] += gain * xBuf[idx];
|
|
@@ -1470,10 +1510,16 @@ var NlmsAec = class {
|
|
|
1470
1510
|
}
|
|
1471
1511
|
}
|
|
1472
1512
|
} else {
|
|
1473
|
-
out[i] = d;
|
|
1513
|
+
out[i] = Number.isFinite(d) ? d : 0;
|
|
1474
1514
|
}
|
|
1475
1515
|
}
|
|
1476
1516
|
this.cursor = cursor;
|
|
1517
|
+
for (let t3 = 0; t3 < this.filterLength; t3++) {
|
|
1518
|
+
if (!Number.isFinite(this.w[t3])) {
|
|
1519
|
+
this.w.fill(0);
|
|
1520
|
+
break;
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1477
1523
|
return out;
|
|
1478
1524
|
}
|
|
1479
1525
|
};
|
|
@@ -1546,6 +1592,7 @@ var ERROR_I18N_KEY = {
|
|
|
1546
1592
|
unknown_session: "errUnknownSession",
|
|
1547
1593
|
forbidden: "errForbidden",
|
|
1548
1594
|
bad_request: "errBadRequest",
|
|
1595
|
+
method_not_allowed: "errMethodNotAllowed",
|
|
1549
1596
|
engine_not_active: "errEngineNotActive",
|
|
1550
1597
|
model_download_failed: "errModelDownload",
|
|
1551
1598
|
too_many_streams: "errTooManyStreams",
|
|
@@ -1611,7 +1658,7 @@ var zh = {
|
|
|
1611
1658
|
startFail: "\u8BED\u97F3\u6A21\u5F0F\u542F\u52A8\u5931\u8D25\uFF1A{err}",
|
|
1612
1659
|
holdDots: "\u6309\u4F4F\u8BF4\u8BDD\u2026",
|
|
1613
1660
|
exit: "\u9000\u51FA",
|
|
1614
|
-
configUnavailableNote: "\uFF08\u8BBE\u7F6E\u6587\u6863\u672A\u5C31\u7EEA\uFF0C\u9762\u677F\u5C31\u7EEA\u540E\u4F1A\u81EA\u52A8\u51FA\u73B0\uFF09\u3002",
|
|
1661
|
+
configUnavailableNote: "\uFF08\u8BBE\u7F6E\u6587\u6863\u672A\u5C31\u7EEA\uFF0C\u6B63\u5728\u91CD\u8BD5\uFF1B\u9762\u677F\u5C31\u7EEA\u540E\u4F1A\u81EA\u52A8\u51FA\u73B0\uFF09\u3002",
|
|
1615
1662
|
// settings-form
|
|
1616
1663
|
previewNameFirst: "\u8BF7\u5148\u586B\u5199\u97F3\u8272\u540D\uFF08ShortName\uFF09",
|
|
1617
1664
|
previewDisabled: "\u8BED\u97F3\u6A21\u5F0F\u5DF2\u7981\u7528\uFF08\u63D2\u4EF6 enabled=false\uFF09\uFF0C\u65E0\u6CD5\u8BD5\u542C",
|
|
@@ -1653,6 +1700,17 @@ var zh = {
|
|
|
1653
1700
|
// R1 收尾(fix-client 直连 tk() 调用):连续 3 次回声拒断的解释出口 + 快捷键非法停用提示。
|
|
1654
1701
|
echoRejectHint: "\u56DE\u58F0\u8F83\u5F3A\uFF0C\u6253\u65AD\u53EF\u80FD\u4E0D\u7075\u654F\u2014\u2014\u8FD9\u662F\u56DE\u58F0\u9632\u62A4\u5728\u751F\u6548\uFF0C\u53EF\u6234\u8033\u673A\u6216\u6539\u7528\u300C\u624B\u52A8\u6253\u65AD\u300D",
|
|
1655
1702
|
shortcutInvalid: "\u5FEB\u6377\u952E\u65E0\u6548\uFF0C\u5DF2\u505C\u7528\uFF08\u53EF\u5728\u8BBE\u7F6E\u91CC\u6539\u4E3A\u5982 Ctrl+Shift+V\uFF1B\u7559\u7A7A\u8868\u793A\u53EA\u7528\u9EA6\u514B\u98CE\u6309\u94AE\uFF09",
|
|
1703
|
+
descComposerShortcut: "\u8F93\u5165\u6846\u6709\u7126\u70B9\u65F6\u7684\u5207\u6362\u5FEB\u6377\u952E\uFF08\u9ED8\u8BA4 Alt/Option+Enter\uFF1B\u7559\u7A7A\u5219\u53EA\u5728\u8F93\u5165\u6846\u5916\u751F\u6548\uFF09",
|
|
1704
|
+
composerShortcutLabel: "\u8FDB\u5165 / \u9000\u51FA\u8BED\u97F3\u6A21\u5F0F\uFF08\u8F93\u5165\u6846\u5185\uFF09",
|
|
1705
|
+
shortcutRecord: "\u5F55\u5236",
|
|
1706
|
+
shortcutRecording: "\u6309\u4E0B\u7EC4\u5408\u952E\u2026",
|
|
1707
|
+
shortcutCancel: "\u53D6\u6D88",
|
|
1708
|
+
shortcutNeedModifier: "\u9700\u8981\u81F3\u5C11\u4E00\u4E2A\u4FEE\u9970\u952E",
|
|
1709
|
+
shortcutUnsupportedKey: "\u53EA\u652F\u6301\u5B57\u6BCD\u3001\u6570\u5B57\u3001Enter\u3001Space\u3001Tab",
|
|
1710
|
+
shortcutPlaceholder: "\u70B9\u5F55\u5236\u540E\u6309\u7EC4\u5408\u952E",
|
|
1711
|
+
shortcutReset: "\u6062\u590D\u9ED8\u8BA4",
|
|
1712
|
+
shortcutNote: "\u8F93\u5165\u6846\u5185\u53EF\u7528 Alt/Option+Enter \u5207\u6362\uFF1B\u652F\u6301 Cmd / Ctrl / Alt / Shift \u7EC4\u5408\uFF1B\u7559\u7A7A\u8868\u793A\u53EA\u7528\u9EA6\u514B\u98CE\u6309\u94AE\u3002\u5F55\u5236\u65F6 Backspace \u6E05\u7A7A\u3001Esc \u53D6\u6D88\uFF1B\u907F\u514D\u6D4F\u89C8\u5668\u5360\u7528\u7684\u7EC4\u5408\uFF08\u5982 Cmd+W / T / N / L\uFF09\u3002\u4FEE\u6539\u540E\u7ACB\u5373\u751F\u6548\uFF0C\u65E0\u9700\u5237\u65B0\u3002",
|
|
1713
|
+
secShortcut: "\u5FEB\u6377\u952E",
|
|
1656
1714
|
elapsedHint: "\u5F53\u524D\u8BED\u97F3\u4F1A\u8BDD\u5DF2\u7528\u65F6\u957F",
|
|
1657
1715
|
botLevelsHint: "AI \u6717\u8BFB\u97F3\u91CF\uFF08\u84DD\u8272\u6761 = \u6717\u8BFB\uFF0C\u7EFF\u8272\u6761 = \u9EA6\u514B\u98CE\uFF09",
|
|
1658
1716
|
interruptConfirm: "\u6253\u65AD\u786E\u8BA4",
|
|
@@ -1690,13 +1748,24 @@ var zh = {
|
|
|
1690
1748
|
descBargeInSalvage: "AI \u6717\u8BFB\u65F6\u4F60\u5F00\u53E3\u6253\u65AD\uFF1A\u81EA\u52A8\u4FDD\u7559\u4ECE\u5F00\u53E3\u5230\u6253\u65AD\u751F\u6548\u4E4B\u95F4\u4F60\u8BF4\u7684\u8BDD\uFF0C\u5E76\u5165\u8BC6\u522B\u7EE7\u7EED\u53D1\u9001\uFF08\u4FEE\u300C\u6253\u65AD\u5403\u53E5\u300D\uFF1B\u5173 = \u4E22\u5F03\u6253\u65AD\u524D\u8BED\u97F3\u2014\u2014\u4EC5\u5916\u653E\u4E14\u65E0\u56DE\u58F0\u6D88\u9664\u7684\u73AF\u5883\u5EFA\u8BAE\u5173\uFF09",
|
|
1691
1749
|
descLlmCorrect: "\u53D1\u9001\u524D\u7528\u5927\u6A21\u578B\u5BF9\u6574\u6761\u8BED\u97F3\u6587\u672C\u505A\u4E00\u6B21\u7EA0\u9519\uFF08\u53EA\u6539\u9519\u522B\u5B57/\u540C\u97F3\u5B57/\u6807\u70B9\uFF0C\u4FDD\u6301\u539F\u610F\uFF1B\u9700\u5BBF\u4E3B\u5DF2\u914D\u7F6E\u9ED8\u8BA4\u6A21\u578B\uFF0C\u672A\u914D\u7F6E\u5219\u81EA\u52A8\u7528\u539F\u6587\uFF09\u3002\u5F00 = \u6BCF\u6761\u6D88\u606F\u591A\u4E00\u6B21\u7EA0\u9519\u7B49\u5F85\uFF1A\u901A\u5E38 1 \u79D2\u5185\uFF0C\u6700\u957F\u7EA6 10 \u79D2\uFF1B\u6BCF\u5206\u949F\u6700\u591A 10 \u6B21\uFF0C\u8BED\u97F3\u6A21\u5F0F\u5173\u95ED\u6216\u89E6\u53D1\u9650\u6D41\u65F6\u6309\u539F\u6587\u53D1\u9001\u3002\u7EA0\u9519\u5931\u8D25\u6216\u8F93\u51FA\u5F02\u5E38\u540C\u6837\u81EA\u52A8\u7528\u539F\u6587",
|
|
1692
1750
|
descYieldMs: "\u8BA9\u4F4D\u8BED\u4E49\u89E6\u53D1\u540E\u7B49\u5F85\u65F6\u957F\uFF08\u6BEB\u79D2\uFF0C500-3000\uFF0C\u9ED8\u8BA4 1500\uFF1B\u7A97\u53E3\u5185\u7528\u6237\u771F\u8981\u8BF4\u5219\u539F hardBreak \u63A5\u7BA1\uFF0C\u7A97\u53E3\u5230\u70B9\u81EA\u52A8\u6062\u590D\u64AD\u653E\uFF09\u3002\u4EC5\u300C\u6309\u4F4F\u8BF4\u8BDD\u300D\u6A21\u5F0F\u64AD\u653E\u671F\u53EF\u89E6\u53D1",
|
|
1693
|
-
descMode: "\u4EA4\u4E92\u6A21\u5F0F\uFF08toggle \u6301\u7EED\u8046\u542C+\u9759\u97F3\u65AD\u53E5 / hold \u6309\u4F4F\u8BF4\u8BDD\uFF09",
|
|
1751
|
+
descMode: "\u4EA4\u4E92\u6A21\u5F0F\uFF08toggle \u6301\u7EED\u8046\u542C+\u9759\u97F3\u65AD\u53E5 / hold \u6309\u4F4F\u8BF4\u8BDD / once \u8BF4\u5B8C\u4E00\u6BB5\u3001\u7B49\u56DE\u590D\u6717\u8BFB\u5B8C\u518D\u81EA\u52A8\u9000\u51FA\uFF09",
|
|
1694
1752
|
modeToggle: "\u6301\u7EED\u8046\u542C",
|
|
1695
1753
|
modeHold: "\u6309\u4F4F\u8BF4\u8BDD",
|
|
1754
|
+
modeOnce: "\u8BF4\u5B8C\u5C31\u5173",
|
|
1755
|
+
stopReading: "\u505C\u6B62\u6717\u8BFB",
|
|
1756
|
+
readAloudLabel: "\u6717\u8BFB\u56DE\u590D",
|
|
1757
|
+
readAloudVoice: "\u8BED\u97F3\u6A21\u5F0F",
|
|
1758
|
+
readAloudAlways: "\u603B\u662F",
|
|
1759
|
+
readAloudOff: "\u5173\u95ED",
|
|
1760
|
+
descReadAloud: "\u8BED\u97F3\u6A21\u5F0F=\u53EA\u5728\u8BED\u97F3\u6A21\u5F0F\u91CC\u6717\u8BFB\uFF08\u9ED8\u8BA4\uFF09\uFF1B\u603B\u662F=\u5F53\u524D\u4F1A\u8BDD\u7684\u6BCF\u6761\u56DE\u590D\u90FD\u6717\u8BFB\uFF08\u542B\u6253\u5B57\u53D1\u9001\u7684\uFF09\uFF1B\u5173\u95ED=\u4ECE\u4E0D\u6717\u8BFB",
|
|
1761
|
+
showCaptionsLabel: "\u5B57\u5E55\u6D6E\u5C42",
|
|
1762
|
+
descShowCaptions: "\u6717\u8BFB\u65F6\u5728\u53F3\u4E0B\u89D2\u663E\u793A\u5F53\u524D\u53E5\u5B50\u7684\u5B57\u5E55\u6D6E\u5C42",
|
|
1763
|
+
showStatusBarLabel: "\u72B6\u6001\u6761",
|
|
1764
|
+
descShowStatusBar: "\u5728\u8F93\u5165\u6846\u4E0A\u65B9\u663E\u793A\u8BED\u97F3\u72B6\u6001\u6761\uFF08\u6CE2\u5F62\u3001\u8BC6\u522B\u6587\u5B57\u3001\u8BA1\u65F6\u3001\u63D0\u793A\u3001\u9000\u51FA\uFF09\uFF1B\u5173\u95ED\u540E\u72B6\u6001\u53EA\u5728\u9EA6\u514B\u98CE\u6309\u94AE\u4E0A\u663E\u793A",
|
|
1696
1765
|
descWakeWord: "\u5524\u9192\u8BCD\uFF08\u9ED8\u8BA4\u5173\uFF1B\u5982\u300C\u4F60\u597D\u5C0FD\u300D\uFF09\uFF1A\u8BF4\u51FA\u8BCD\u5934\u624D\u8FDB\u5165\u8BC6\u522B\uFF0C\u907F\u514D\u8BEF\u89E6\u3002\u53EF\u4E0E\u547D\u4EE4\u8FDE\u8BF4\uFF08\u300C\u4F60\u597D\u5C0FD\uFF0C\u5E2E\u6211\u67E5\u5929\u6C14\u300D\u2014\u2014\u8BCD\u5934\u4F1A\u81EA\u52A8\u5265\u6389\u3001\u4E0D\u8FDB\u6D88\u606F\uFF09\uFF1B\u6BCF\u53E5\u65AD\u53E5\u6216\u6253\u65AD\u540E\u9700\u91CD\u8BF4\uFF1B\u4EC5 toggle \u6A21\u5F0F\u751F\u6548\uFF08hold / \u624B\u52A8\u6253\u65AD\u4E0B\u4E0D\u751F\u6548\uFF1Bdetect \u81EA\u52A8\u63A2\u6D4B\u672A\u751F\u6548\u3001\u56DE\u843D manual \u65F6\u540C\u6837\u4E0D\u751F\u6548\u2014\u2014Safari \u7B49\u65E0\u539F\u751F\u56DE\u58F0\u6D88\u9664\u7684\u673A\u5668\u4F1A\u9ED8\u8BA4\u843D\u5230\u8FD9\u4E00\u6863\uFF09\uFF1B\u6717\u8BFB\u671F\u8BF4\u5524\u9192\u8BCD\u4E0D\u89E6\u53D1\uFF08\u6253\u65AD\u4ECD\u6309 VAD \u5F00\u53E3\u5373\u6253\u65AD\uFF09\u3002\u5339\u914D\u5E26\u5BB9\u9519\uFF08\u540C\u97F3\u5B57 / \u524D\u5BFC\u8BED\u6C14\u8BCD\uFF09\uFF0C\u5EFA\u8BAE 3-4 \u5B57\uFF1B\u975E\u4E13\u7528 KWS \u5F15\u64CE\uFF0C\u5608\u6742\u73AF\u5883\u53EF\u80FD\u5EF6\u8FDF\u6216\u8BEF\u6FC0\u6D3B",
|
|
1697
1766
|
wakePlaceholder: "\u5982\uFF1A\u4F60\u597D\u5C0FD",
|
|
1698
|
-
settingsCardDesc: "\u6717\u8BFB\u5F15\u64CE / \u97F3\u8272 / \u8BED\u901F / \u6253\u65AD\u7075\u654F\u5EA6 / \u6253\u65AD\u65B9\u5F0F / \u56DE\u58F0\u95E8\u63A7 / \u9759\u97F3\u505C\u987F / \u7A7A\u95F2\u8D85\u65F6 / \u6A21\u578B\u955C\u50CF / \u81EA\u52A8\u53D1\u9001 / \u81EA\u52A8\u6062\u590D / \u4EA4\u4E92\u6A21\u5F0F / \u5524\u9192\u8BCD / \u5DE5\u5177\u63D0\u793A\u97F3 / \u9006\u6587\u672C\u5F52\u4E00\u5316 / \u5B57\u5E55\u5B57\u53F7 / \u5B57\u5E55\u5BBD\u5EA6 / \u77ED\u5E94\u7B54\u8BA9\u4F4D / \u8BA9\u4F4D\u7A97\u53E3 / \u6253\u65AD\u8BED\u97F3\u62A2\u6551 / LLM \u7EA0\u9519",
|
|
1699
|
-
settingsEffectiveNote: "\u751F\u6548\u65F6\u673A\u5206\u56DB\u6863\uFF1A\u2460 \u5373\u65F6\u2014\u2014\u6717\u8BFB\u5F15\u64CE / \u97F3\u8272 / \u8BED\u901F / Kokoro \u6A21\u578B\u7CBE\u5EA6\uFF08\u5DF2\u7F13\u5B58\u5219\u5373\u65F6\uFF0C\u5426\u5219\u4E0B\u6B21\u4E0B\u8F7D\uFF09/ \u53E3\u8BED\u5316\u63D0\u793A\u8BCD\uFF08\u5BF9\u540E\u7EED\u56DE\u590D\u751F\u6548\uFF09/ \u6A21\u578B\u955C\u50CF\uFF08\u4E0B\u6B21\u4E0B\u8F7D\u5C1D\u8BD5\u5373\u751F\u6548\uFF09\uFF1B\u2461 \u4E0B\u6B21\u8BC6\u522B\u65F6\u2014\u2014\u5B9A\u7A3F\u91CD\u8BD1\uFF08SenseVoice\uFF09/ \u9006\u6587\u672C\u5F52\u4E00\u5316\uFF1B\u2462 \u4E0B\u4E00\u6BB5\u8BDD\u2014\u2014\u9759\u97F3\u5224\u5B9A\u65F6\u957F\uFF08\u65AD\u53E5\u7AEF\u70B9\uFF1B\u53D1\u9001\u7B49\u5F85\u56FA\u5B9A 1.2 \u79D2\u4E0D\u53D7\u5F71\u54CD\uFF09\uFF1B\u2463 \u4E0B\u6B21\u8FDB\u5165\u8BED\u97F3\u6A21\u5F0F\u2014\u2014\u6253\u65AD\u7075\u654F\u5EA6 / \u6253\u65AD\u65B9\u5F0F / \u56DE\u58F0\u95E8\u63A7 / \u5FEB\u6377\u952E / \u81EA\u52A8\u53D1\u9001 / \u81EA\u52A8\u6062\u590D / \u4EA4\u4E92\u6A21\u5F0F / \u5524\u9192\u8BCD / \u5DE5\u5177\u63D0\u793A\u97F3 / \u5B57\u5E55\u5B57\u53F7 / \u5B57\u5E55\u5BBD\u5EA6 / \u77ED\u5E94\u7B54\u8BA9\u4F4D / \u8BA9\u4F4D\u7A97\u53E3 / \u6253\u65AD\u8BED\u97F3\u62A2\u6551 / LLM \u7EA0\u9519 / \u7A7A\u95F2\u65F6\u957F\u3002\u4E0B\u6B21\u8FDB\u5165\u8BED\u97F3\u6A21\u5F0F\u624D\u751F\u6548\u7684\u9879\u4F1A\u5217\u5728\u5361\u7247\u9876\u90E8\uFF08\u542B\u5F53\u524D\u751F\u6548\u503C\uFF09\u3002",
|
|
1767
|
+
settingsCardDesc: "\u6717\u8BFB\u5F15\u64CE / \u97F3\u8272 / \u8BED\u901F / \u6253\u65AD\u7075\u654F\u5EA6 / \u6253\u65AD\u65B9\u5F0F / \u56DE\u58F0\u95E8\u63A7 / \u9759\u97F3\u505C\u987F / \u7A7A\u95F2\u8D85\u65F6 / \u6A21\u578B\u955C\u50CF / \u81EA\u52A8\u53D1\u9001 / \u6717\u8BFB\u56DE\u590D / \u72B6\u6001\u6761 / \u5B57\u5E55\u6D6E\u5C42 / \u81EA\u52A8\u6062\u590D / \u4EA4\u4E92\u6A21\u5F0F / \u5524\u9192\u8BCD / \u5DE5\u5177\u63D0\u793A\u97F3 / \u9006\u6587\u672C\u5F52\u4E00\u5316 / \u5B57\u5E55\u5B57\u53F7 / \u5B57\u5E55\u5BBD\u5EA6 / \u77ED\u5E94\u7B54\u8BA9\u4F4D / \u8BA9\u4F4D\u7A97\u53E3 / \u6253\u65AD\u8BED\u97F3\u62A2\u6551 / LLM \u7EA0\u9519",
|
|
1768
|
+
settingsEffectiveNote: "\u751F\u6548\u65F6\u673A\u5206\u56DB\u6863\uFF1A\u2460 \u5373\u65F6\u2014\u2014\u6717\u8BFB\u5F15\u64CE / \u97F3\u8272 / \u8BED\u901F / Kokoro \u6A21\u578B\u7CBE\u5EA6\uFF08\u5DF2\u7F13\u5B58\u5219\u5373\u65F6\uFF0C\u5426\u5219\u4E0B\u6B21\u4E0B\u8F7D\uFF09/ \u53E3\u8BED\u5316\u63D0\u793A\u8BCD\uFF08\u5BF9\u540E\u7EED\u56DE\u590D\u751F\u6548\uFF09/ \u6717\u8BFB\u56DE\u590D / \u72B6\u6001\u6761 / \u5B57\u5E55\u6D6E\u5C42 / \u6A21\u578B\u955C\u50CF\uFF08\u4E0B\u6B21\u4E0B\u8F7D\u5C1D\u8BD5\u5373\u751F\u6548\uFF09\uFF1B\u2461 \u4E0B\u6B21\u8BC6\u522B\u65F6\u2014\u2014\u5B9A\u7A3F\u91CD\u8BD1\uFF08SenseVoice\uFF09/ \u9006\u6587\u672C\u5F52\u4E00\u5316\uFF1B\u2462 \u4E0B\u4E00\u6BB5\u8BDD\u2014\u2014\u9759\u97F3\u5224\u5B9A\u65F6\u957F\uFF08\u65AD\u53E5\u7AEF\u70B9\uFF1B\u53D1\u9001\u7B49\u5F85\u56FA\u5B9A 1.2 \u79D2\u4E0D\u53D7\u5F71\u54CD\uFF09\uFF1B\u2463 \u4E0B\u6B21\u8FDB\u5165\u8BED\u97F3\u6A21\u5F0F\u2014\u2014\u6253\u65AD\u7075\u654F\u5EA6 / \u6253\u65AD\u65B9\u5F0F / \u56DE\u58F0\u95E8\u63A7 / \u5FEB\u6377\u952E / \u81EA\u52A8\u53D1\u9001 / \u81EA\u52A8\u6062\u590D / \u4EA4\u4E92\u6A21\u5F0F / \u5524\u9192\u8BCD / \u5DE5\u5177\u63D0\u793A\u97F3 / \u5B57\u5E55\u5B57\u53F7 / \u5B57\u5E55\u5BBD\u5EA6 / \u77ED\u5E94\u7B54\u8BA9\u4F4D / \u8BA9\u4F4D\u7A97\u53E3 / \u6253\u65AD\u8BED\u97F3\u62A2\u6551 / LLM \u7EA0\u9519 / \u7A7A\u95F2\u65F6\u957F\u3002\u4E0B\u6B21\u8FDB\u5165\u8BED\u97F3\u6A21\u5F0F\u624D\u751F\u6548\u7684\u9879\u4F1A\u5217\u5728\u5361\u7247\u9876\u90E8\uFF08\u542B\u5F53\u524D\u751F\u6548\u503C\uFF09\u3002",
|
|
1700
1769
|
effectivePending: "\u6709 {count} \u9879\u4FEE\u6539\u5C06\u5728\u4E0B\u6B21\u8FDB\u5165\u8BED\u97F3\u6A21\u5F0F\u65F6\u751F\u6548\uFF1A{items}",
|
|
1701
1770
|
valueOn: "\u5F00",
|
|
1702
1771
|
valueOff: "\u5173",
|
|
@@ -1779,7 +1848,7 @@ var zh = {
|
|
|
1779
1848
|
bargeInModeLabel: "\u6253\u65AD\u65B9\u5F0F",
|
|
1780
1849
|
echoGateDbLabel: "\u56DE\u58F0\u95E8\u63A7",
|
|
1781
1850
|
modeLabel: "\u4EA4\u4E92\u6A21\u5F0F",
|
|
1782
|
-
shortcutLabel: "\
|
|
1851
|
+
shortcutLabel: "\u8FDB\u5165 / \u9000\u51FA\u8BED\u97F3\u6A21\u5F0F\uFF08\u5E94\u7528\u5185\uFF09",
|
|
1783
1852
|
wakeWordLabel: "\u5524\u9192\u8BCD",
|
|
1784
1853
|
toolBeepLabel: "\u5DE5\u5177\u63D0\u793A\u97F3",
|
|
1785
1854
|
autoSendLabel: "\u81EA\u52A8\u53D1\u9001",
|
|
@@ -1815,6 +1884,7 @@ var zh = {
|
|
|
1815
1884
|
errUnknownSession: "\u8BED\u97F3\u4F1A\u8BDD\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u5F00\u542F\u8BED\u97F3\u6A21\u5F0F",
|
|
1816
1885
|
errForbidden: "\u8BF7\u6C42\u88AB\u62D2\u7EDD\uFF08\u4EC5\u9650\u672C\u673A\u8BBF\u95EE\uFF0C\u6216\u6765\u6E90\u4E0D\u7B26\uFF09",
|
|
1817
1886
|
errBadRequest: "\u8BF7\u6C42\u65E0\u6548",
|
|
1887
|
+
errMethodNotAllowed: "\u8BF7\u6C42\u65B9\u6CD5\u4E0D\u88AB\u652F\u6301",
|
|
1818
1888
|
errEngineNotActive: "\u8BE5\u6717\u8BFB\u5F15\u64CE\u5F53\u524D\u672A\u542F\u7528",
|
|
1819
1889
|
errModelDownload: "\u6A21\u578B\u4E0B\u8F7D\u5931\u8D25\uFF1A\u8BF7\u68C0\u67E5\u7F51\u7EDC",
|
|
1820
1890
|
errTooManyStreams: "\u8BED\u97F3\u8FDE\u63A5\u8FC7\u591A\uFF0C\u8BF7\u5173\u95ED\u5176\u5B83\u8BED\u97F3\u9875\u9762\u540E\u91CD\u8BD5",
|
|
@@ -1874,7 +1944,7 @@ var en = {
|
|
|
1874
1944
|
startFail: "Voice mode failed to start: {err}",
|
|
1875
1945
|
holdDots: "Hold to talk\u2026",
|
|
1876
1946
|
exit: "Exit",
|
|
1877
|
-
configUnavailableNote: " (settings document not ready; the panel will appear when it is).",
|
|
1947
|
+
configUnavailableNote: " (settings document not ready; retrying \u2014 the panel will appear when it is).",
|
|
1878
1948
|
previewNameFirst: "Enter a voice ShortName first",
|
|
1879
1949
|
previewDisabled: "Voice mode disabled (plugin enabled=false); preview unavailable",
|
|
1880
1950
|
// 批 G 任务 6:本地 TTS 引擎未下载模型时禁用试听按钮 + 提示。
|
|
@@ -1914,6 +1984,17 @@ var en = {
|
|
|
1914
1984
|
// R1 收尾(fix-client 直连 tk() 调用):连续 3 次回声拒断的解释出口 + 快捷键非法停用提示。
|
|
1915
1985
|
echoRejectHint: "Strong echo detected \u2014 barge-in is limited by echo protection. Use headphones or switch to manual barge-in",
|
|
1916
1986
|
shortcutInvalid: "Invalid shortcut, disabled. Fix it in settings (e.g. Ctrl+Shift+V); leave empty to use the mic button only",
|
|
1987
|
+
descComposerShortcut: "Shortcut to toggle voice mode while the composer has focus (default Alt/Option+Enter)",
|
|
1988
|
+
composerShortcutLabel: "Enter / exit voice mode (in composer)",
|
|
1989
|
+
shortcutRecord: "Record",
|
|
1990
|
+
shortcutRecording: "Press a key combo\u2026",
|
|
1991
|
+
shortcutCancel: "Cancel",
|
|
1992
|
+
shortcutNeedModifier: "At least one modifier is required",
|
|
1993
|
+
shortcutUnsupportedKey: "Only letters, digits, Enter, Space and Tab are supported",
|
|
1994
|
+
shortcutPlaceholder: "Click Record, then press a combo",
|
|
1995
|
+
shortcutReset: "Reset to default",
|
|
1996
|
+
shortcutNote: "Alt/Option+Enter toggles inside the composer; Cmd / Ctrl / Alt / Shift combos are supported; leaving it empty means mic button only. While recording, Backspace clears and Esc cancels; avoid browser-reserved combos (Cmd+W / T / N / L). Changes apply immediately.",
|
|
1997
|
+
secShortcut: "Shortcut",
|
|
1917
1998
|
elapsedHint: "Current voice session duration",
|
|
1918
1999
|
botLevelsHint: "AI playback level (blue bar = TTS playback, green bar = microphone)",
|
|
1919
2000
|
interruptConfirm: "interrupt confirm",
|
|
@@ -1950,13 +2031,24 @@ var en = {
|
|
|
1950
2031
|
descBargeInSalvage: "When you speak to interrupt while the agent is reading aloud, keep what you said from speech onset to break confirmation and merge it into recognition (fixes swallowed break-in speech; off = discard pre-break audio; recommended off only on speakers without echo cancellation)",
|
|
1951
2032
|
descLlmCorrect: "Before sending, run one LLM pass over the whole transcribed text (typos/homophones/punctuation only, meaning preserved; requires a default model configured in the host \u2014 otherwise the original text is sent as-is). On = one extra correction round trip per message: usually under 1 second, at most ~10 seconds; at most 10 times per minute \u2014 when voice mode is off or the limit is hit, the original text is sent. Failed or abnormal output also falls back to the original text",
|
|
1952
2033
|
descYieldMs: "How long (ms) to drop frames after a yield trigger (500-3000, default 1500; within the window the existing hardBreak takes over if the user really wants to speak; auto-resume after the window expires). Hold-to-talk mode only, during playback",
|
|
1953
|
-
descMode: "Interaction mode (toggle: continuous listen + auto-send / hold: press to talk)",
|
|
2034
|
+
descMode: "Interaction mode (toggle: continuous listen + auto-send / hold: press to talk / once: one utterance, then exit after the reply is read aloud)",
|
|
1954
2035
|
modeToggle: "Continuous listening",
|
|
1955
2036
|
modeHold: "Hold to talk",
|
|
2037
|
+
modeOnce: "One-shot",
|
|
2038
|
+
stopReading: "Stop reading",
|
|
2039
|
+
readAloudLabel: "Read replies",
|
|
2040
|
+
readAloudVoice: "Voice mode",
|
|
2041
|
+
readAloudAlways: "Always",
|
|
2042
|
+
readAloudOff: "Off",
|
|
2043
|
+
descReadAloud: "Voice mode = read replies only in voice mode (default); Always = read every reply in the current session, typed ones included; Off = never read aloud",
|
|
2044
|
+
showCaptionsLabel: "Caption overlay",
|
|
2045
|
+
descShowCaptions: "Show a floating caption of the current sentence while reading aloud",
|
|
2046
|
+
showStatusBarLabel: "Status bar",
|
|
2047
|
+
descShowStatusBar: "Show the voice status bar above the composer (waveform, transcript, timer, notices, exit); when off, state shows only on the mic button",
|
|
1956
2048
|
descWakeWord: 'Wake word (default off; e.g. "Hey D"): recognition starts only after you say it, to avoid accidental triggers. You may say it together with your command ("Hey D, check the weather" \u2014 the wake word is stripped and never sent); it must be repeated after each utterance split or barge-in; toggle mode only (inactive in hold / manual barge-in \u2014 and equally inactive when the detect probe fails and falls back to manual, the default on machines without native echo cancellation such as Safari); saying it while the agent is reading does not trigger (barge-in stays VAD-based). Fault-tolerant matching (homophones / leading fillers); 3-4 characters recommended; not a dedicated KWS engine \u2014 noisy environments may delay or falsely trigger',
|
|
1957
2049
|
wakePlaceholder: "e.g. Hey D",
|
|
1958
|
-
settingsCardDesc: "Engine / voice / rate / interrupt / barge-in / echo gate / silence / idle / model host / auto-send / auto-resume / mode / wake word / tool beep / ITN / caption font / caption width / yielding / yield window / barge-in salvage / LLM correction",
|
|
1959
|
-
settingsEffectiveNote: "When settings apply, in four tiers: \u2460 immediately \u2014 engine / voice / rate / Kokoro model precision (immediate when cached, else next download) / spoken format (applies to later replies) / model mirror (next download attempt); \u2461 next recognition \u2014 finalization re-transcription (SenseVoice) / ITN; \u2462 next utterance \u2014 silence threshold (endpoint; the send wait stays a fixed 1.2s); \u2463 next time you enter voice mode \u2014 interrupt sensitivity / barge-in mode / echo gate / shortcut / auto-send / auto-resume / interaction mode / wake word / tool beep / caption font / caption width / backchannel yielding / yield window / barge-in salvage / LLM correction / idle timeout. Items that take effect next time you enter voice mode are listed at the top of this card with their current effective values.",
|
|
2050
|
+
settingsCardDesc: "Engine / voice / rate / interrupt / barge-in / echo gate / silence / idle / model host / auto-send / read replies / status bar / caption overlay / auto-resume / mode / wake word / tool beep / ITN / caption font / caption width / yielding / yield window / barge-in salvage / LLM correction",
|
|
2051
|
+
settingsEffectiveNote: "When settings apply, in four tiers: \u2460 immediately \u2014 engine / voice / rate / Kokoro model precision (immediate when cached, else next download) / spoken format (applies to later replies) / read replies / status bar / caption overlay / model mirror (next download attempt); \u2461 next recognition \u2014 finalization re-transcription (SenseVoice) / ITN; \u2462 next utterance \u2014 silence threshold (endpoint; the send wait stays a fixed 1.2s); \u2463 next time you enter voice mode \u2014 interrupt sensitivity / barge-in mode / echo gate / shortcut / auto-send / auto-resume / interaction mode / wake word / tool beep / caption font / caption width / backchannel yielding / yield window / barge-in salvage / LLM correction / idle timeout. Items that take effect next time you enter voice mode are listed at the top of this card with their current effective values.",
|
|
1960
2052
|
effectivePending: "{count} change(s) will apply next time you enter voice mode: {items}",
|
|
1961
2053
|
valueOn: "On",
|
|
1962
2054
|
valueOff: "Off",
|
|
@@ -2033,7 +2125,7 @@ var en = {
|
|
|
2033
2125
|
bargeInModeLabel: "Interrupt mode",
|
|
2034
2126
|
echoGateDbLabel: "Echo gate",
|
|
2035
2127
|
modeLabel: "Interaction mode",
|
|
2036
|
-
shortcutLabel: "
|
|
2128
|
+
shortcutLabel: "Enter / exit voice mode (app-wide)",
|
|
2037
2129
|
wakeWordLabel: "Wake word",
|
|
2038
2130
|
toolBeepLabel: "Tool-call beep",
|
|
2039
2131
|
autoSendLabel: "Auto-send",
|
|
@@ -2069,6 +2161,7 @@ var en = {
|
|
|
2069
2161
|
errUnknownSession: "Voice session expired \u2014 re-enter voice mode",
|
|
2070
2162
|
errForbidden: "Request denied (local access only, or origin mismatch)",
|
|
2071
2163
|
errBadRequest: "Invalid request",
|
|
2164
|
+
errMethodNotAllowed: "Request method not allowed",
|
|
2072
2165
|
errEngineNotActive: "That read-aloud engine is not active",
|
|
2073
2166
|
errModelDownload: "Model download failed \u2014 check your network",
|
|
2074
2167
|
errTooManyStreams: "Too many voice connections \u2014 close other voice tabs and retry",
|
|
@@ -2191,6 +2284,176 @@ function shouldWritePartial(state) {
|
|
|
2191
2284
|
return state !== "wake";
|
|
2192
2285
|
}
|
|
2193
2286
|
|
|
2287
|
+
// src/mic-gesture.ts
|
|
2288
|
+
function isEditingShortcut(combo, mac) {
|
|
2289
|
+
const primary = mac ? combo.meta && !combo.ctrl : combo.ctrl && !combo.meta;
|
|
2290
|
+
return primary && !combo.alt && combo.key.length === 1 && "acvxzy".includes(combo.key);
|
|
2291
|
+
}
|
|
2292
|
+
function takeToggleSlot(history, now) {
|
|
2293
|
+
while (history.length > 0 && now - history[0] >= 2e3) history.shift();
|
|
2294
|
+
if (history.length >= 2) return false;
|
|
2295
|
+
if (history.length > 0 && now - history[history.length - 1] < 250) return false;
|
|
2296
|
+
history.push(now);
|
|
2297
|
+
return true;
|
|
2298
|
+
}
|
|
2299
|
+
function onceFinished(o, running, ttsDrained, playing) {
|
|
2300
|
+
return o.sawRun && !running && ttsDrained && !playing;
|
|
2301
|
+
}
|
|
2302
|
+
function isPrimaryPress(button, opts) {
|
|
2303
|
+
if (button !== 0) return false;
|
|
2304
|
+
if (opts.mac && opts.ctrlKey) return false;
|
|
2305
|
+
return true;
|
|
2306
|
+
}
|
|
2307
|
+
function eqPaintMode(reducedMotion) {
|
|
2308
|
+
return reducedMotion ? "static-full" : "animated";
|
|
2309
|
+
}
|
|
2310
|
+
function menuFocusIndex(i, len, dir) {
|
|
2311
|
+
if (len <= 0) return -1;
|
|
2312
|
+
if (i < 0) return dir === 1 ? 0 : len - 1;
|
|
2313
|
+
return (i + dir + len) % len;
|
|
2314
|
+
}
|
|
2315
|
+
function handleReplaced(o) {
|
|
2316
|
+
if (o.staleBus) {
|
|
2317
|
+
o.retire();
|
|
2318
|
+
return;
|
|
2319
|
+
}
|
|
2320
|
+
o.reconnect(o.renewTabId());
|
|
2321
|
+
}
|
|
2322
|
+
function decayConfirmCount(count, abandon) {
|
|
2323
|
+
const next = Math.max(0, count - 1);
|
|
2324
|
+
if (next === 0) abandon();
|
|
2325
|
+
return next;
|
|
2326
|
+
}
|
|
2327
|
+
function shouldReleaseStopLine(o) {
|
|
2328
|
+
if (!o.hasStopLine) return false;
|
|
2329
|
+
if (o.untilNextRun) return false;
|
|
2330
|
+
if (o.turn !== void 0 && o.lastTurn !== void 0) return o.turn !== o.lastTurn;
|
|
2331
|
+
if (o.sameRoundContinuation) return false;
|
|
2332
|
+
return true;
|
|
2333
|
+
}
|
|
2334
|
+
function applyTurnEvent(o) {
|
|
2335
|
+
const release = shouldReleaseStopLine({
|
|
2336
|
+
hasStopLine: o.hasStopLine,
|
|
2337
|
+
untilNextRun: o.untilNextRun,
|
|
2338
|
+
turn: o.turn,
|
|
2339
|
+
lastTurn: o.identity.lastTurn,
|
|
2340
|
+
sameRoundContinuation: o.sameRoundContinuation
|
|
2341
|
+
});
|
|
2342
|
+
return {
|
|
2343
|
+
identity: o.turn !== void 0 ? { lastTurn: o.turn } : o.identity,
|
|
2344
|
+
release
|
|
2345
|
+
};
|
|
2346
|
+
}
|
|
2347
|
+
function cancelPayload(o) {
|
|
2348
|
+
return JSON.stringify({ sessionId: o.sessionId, keepAsr: o.keepAsr, reason: o.reason });
|
|
2349
|
+
}
|
|
2350
|
+
function auxClickPending(button, opts) {
|
|
2351
|
+
return button === 0 && opts.mac && opts.ctrlKey;
|
|
2352
|
+
}
|
|
2353
|
+
function isAuxClickToIgnore(pending, clickDetail) {
|
|
2354
|
+
return pending && clickDetail !== 0;
|
|
2355
|
+
}
|
|
2356
|
+
function isGestureEnd(armed, up) {
|
|
2357
|
+
if (!armed) return false;
|
|
2358
|
+
return armed.id === up.id && armed.button === up.button;
|
|
2359
|
+
}
|
|
2360
|
+
function pointerUpAction(armed, up) {
|
|
2361
|
+
if (!armed) return "unarmed";
|
|
2362
|
+
if (!isGestureEnd(armed, up)) return "ignore";
|
|
2363
|
+
return "finish";
|
|
2364
|
+
}
|
|
2365
|
+
function focusFailureAction(status, attempt) {
|
|
2366
|
+
if (status !== 403) return "silent";
|
|
2367
|
+
return attempt === 1 ? "retry-later" : "report-once";
|
|
2368
|
+
}
|
|
2369
|
+
async function reportFocus(o) {
|
|
2370
|
+
const wait = o.wait ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
2371
|
+
const warn = o.warn ?? (() => {
|
|
2372
|
+
});
|
|
2373
|
+
const retryMs = o.retryMs ?? 800;
|
|
2374
|
+
let attempts = 0;
|
|
2375
|
+
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
2376
|
+
attempts++;
|
|
2377
|
+
let status;
|
|
2378
|
+
try {
|
|
2379
|
+
status = (await o.fetchImpl()).status;
|
|
2380
|
+
} catch {
|
|
2381
|
+
return { ok: false, reported: false, attempts, skipped: false };
|
|
2382
|
+
}
|
|
2383
|
+
const action = focusFailureAction(status, attempt);
|
|
2384
|
+
if (action === "silent") return { ok: status >= 200 && status < 300, reported: false, attempts, skipped: false };
|
|
2385
|
+
if (action === "retry-later") {
|
|
2386
|
+
if (o.sessionId === null) return { ok: false, reported: false, attempts, skipped: false };
|
|
2387
|
+
await wait(retryMs);
|
|
2388
|
+
if (o.stillRelevant && !o.stillRelevant()) {
|
|
2389
|
+
return { ok: false, reported: false, attempts, skipped: true };
|
|
2390
|
+
}
|
|
2391
|
+
continue;
|
|
2392
|
+
}
|
|
2393
|
+
warn({ sessionId: o.sessionId, status });
|
|
2394
|
+
return { ok: false, reported: true, attempts, skipped: false };
|
|
2395
|
+
}
|
|
2396
|
+
return { ok: false, reported: false, attempts, skipped: false };
|
|
2397
|
+
}
|
|
2398
|
+
var FOCUS_OWNER_DEFAULT = "default";
|
|
2399
|
+
function focusSession(owners) {
|
|
2400
|
+
let last = null;
|
|
2401
|
+
for (const sessionId of owners.values()) last = sessionId;
|
|
2402
|
+
return last;
|
|
2403
|
+
}
|
|
2404
|
+
function focusClaim(owners, owner, sessionId) {
|
|
2405
|
+
owners.delete(owner);
|
|
2406
|
+
owners.set(owner, sessionId);
|
|
2407
|
+
}
|
|
2408
|
+
function focusRelease(owners, owner) {
|
|
2409
|
+
const before = focusSession(owners);
|
|
2410
|
+
owners.delete(owner);
|
|
2411
|
+
const focused = focusSession(owners);
|
|
2412
|
+
return { changed: before !== focused, focused };
|
|
2413
|
+
}
|
|
2414
|
+
function registerScopeDispose(host, raw) {
|
|
2415
|
+
host.effect(() => raw.dispose);
|
|
2416
|
+
}
|
|
2417
|
+
function createScopeBridge(raw) {
|
|
2418
|
+
const listeners = [];
|
|
2419
|
+
let off = null;
|
|
2420
|
+
function resubscribe() {
|
|
2421
|
+
off?.();
|
|
2422
|
+
off = raw.subscribe(forward);
|
|
2423
|
+
}
|
|
2424
|
+
function forward() {
|
|
2425
|
+
for (const entry of [...listeners]) entry.fn();
|
|
2426
|
+
}
|
|
2427
|
+
const scope = {
|
|
2428
|
+
getSnapshot: () => raw.getSnapshot(),
|
|
2429
|
+
subscribe(fn) {
|
|
2430
|
+
const entry = { fn };
|
|
2431
|
+
listeners.push(entry);
|
|
2432
|
+
if (listeners.length === 1) off = raw.subscribe(forward);
|
|
2433
|
+
return () => {
|
|
2434
|
+
const i = listeners.indexOf(entry);
|
|
2435
|
+
if (i >= 0) listeners.splice(i, 1);
|
|
2436
|
+
if (listeners.length === 0 && off !== null) {
|
|
2437
|
+
off();
|
|
2438
|
+
off = null;
|
|
2439
|
+
}
|
|
2440
|
+
};
|
|
2441
|
+
},
|
|
2442
|
+
set: (field, value) => raw.set(field, value)
|
|
2443
|
+
};
|
|
2444
|
+
return {
|
|
2445
|
+
scope,
|
|
2446
|
+
invalidate() {
|
|
2447
|
+
if (typeof raw.invalidate === "function") {
|
|
2448
|
+
raw.invalidate();
|
|
2449
|
+
return;
|
|
2450
|
+
}
|
|
2451
|
+
if (listeners.length === 0) return;
|
|
2452
|
+
resubscribe();
|
|
2453
|
+
}
|
|
2454
|
+
};
|
|
2455
|
+
}
|
|
2456
|
+
|
|
2194
2457
|
// src/runtime-boot.ts
|
|
2195
2458
|
var runtimeBoot = null;
|
|
2196
2459
|
function setRuntimeBoot(boot) {
|
|
@@ -2597,6 +2860,114 @@ function TextField({
|
|
|
2597
2860
|
}
|
|
2598
2861
|
);
|
|
2599
2862
|
}
|
|
2863
|
+
function ShortcutField({
|
|
2864
|
+
score,
|
|
2865
|
+
field,
|
|
2866
|
+
value
|
|
2867
|
+
}) {
|
|
2868
|
+
const [draft, setDraft] = (0, import_react2.useState)(String(value ?? ""));
|
|
2869
|
+
const [recording, setRecording] = (0, import_react2.useState)(false);
|
|
2870
|
+
const [err, setErr] = (0, import_react2.useState)("");
|
|
2871
|
+
(0, import_react2.useEffect)(() => {
|
|
2872
|
+
setDraft((d) => d === String(value ?? "") ? d : String(value ?? ""));
|
|
2873
|
+
}, [value]);
|
|
2874
|
+
const notify = () => {
|
|
2875
|
+
try {
|
|
2876
|
+
window.dispatchEvent(new Event("dshvm-settings-changed"));
|
|
2877
|
+
} catch {
|
|
2878
|
+
}
|
|
2879
|
+
};
|
|
2880
|
+
const commit = () => {
|
|
2881
|
+
void score.set(field, draft.trim());
|
|
2882
|
+
notify();
|
|
2883
|
+
};
|
|
2884
|
+
(0, import_react2.useEffect)(() => {
|
|
2885
|
+
if (!recording) return;
|
|
2886
|
+
const onKey = (e) => {
|
|
2887
|
+
e.preventDefault();
|
|
2888
|
+
e.stopPropagation();
|
|
2889
|
+
if (e.key === "Escape") {
|
|
2890
|
+
setRecording(false);
|
|
2891
|
+
setErr("");
|
|
2892
|
+
return;
|
|
2893
|
+
}
|
|
2894
|
+
if (e.key === "Backspace" || e.key === "Delete") {
|
|
2895
|
+
setDraft("");
|
|
2896
|
+
void score.set(field, "");
|
|
2897
|
+
notify();
|
|
2898
|
+
setRecording(false);
|
|
2899
|
+
return;
|
|
2900
|
+
}
|
|
2901
|
+
if (e.key === "Control" || e.key === "Alt" || e.key === "Shift" || e.key === "Meta") return;
|
|
2902
|
+
const mods = [];
|
|
2903
|
+
if (e.metaKey) mods.push("Cmd");
|
|
2904
|
+
else if (e.ctrlKey) mods.push("Ctrl");
|
|
2905
|
+
if (e.altKey) mods.push("Alt");
|
|
2906
|
+
if (e.shiftKey) mods.push("Shift");
|
|
2907
|
+
if (mods.length === 0) {
|
|
2908
|
+
setErr(t("shortcutNeedModifier"));
|
|
2909
|
+
return;
|
|
2910
|
+
}
|
|
2911
|
+
const named = e.key === "Enter" ? "Enter" : e.key === " " ? "Space" : e.key === "Tab" ? "Tab" : "";
|
|
2912
|
+
const codeKey = (e.code || "").replace(/^Key/, "").replace(/^Digit/, "");
|
|
2913
|
+
const k = named || (/^[A-Za-z0-9]$/.test(codeKey) ? codeKey.toUpperCase() : /^[A-Za-z0-9]$/.test(e.key) ? e.key.toUpperCase() : "");
|
|
2914
|
+
if (!k) {
|
|
2915
|
+
setErr(t("shortcutUnsupportedKey"));
|
|
2916
|
+
return;
|
|
2917
|
+
}
|
|
2918
|
+
const combo = [...mods, k].join("+");
|
|
2919
|
+
setDraft(combo);
|
|
2920
|
+
void score.set(field, combo);
|
|
2921
|
+
notify();
|
|
2922
|
+
setRecording(false);
|
|
2923
|
+
setErr("");
|
|
2924
|
+
};
|
|
2925
|
+
window.addEventListener("keydown", onKey, true);
|
|
2926
|
+
return () => window.removeEventListener("keydown", onKey, true);
|
|
2927
|
+
}, [recording, score, field]);
|
|
2928
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { display: "inline-flex", flexDirection: "column", alignItems: "flex-end", gap: 3 }, children: [
|
|
2929
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { display: "inline-flex", alignItems: "center", gap: 6 }, children: [
|
|
2930
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2931
|
+
"input",
|
|
2932
|
+
{
|
|
2933
|
+
style: { ...inputStyle, width: 150 },
|
|
2934
|
+
value: draft,
|
|
2935
|
+
placeholder: t("shortcutPlaceholder"),
|
|
2936
|
+
onChange: (e) => {
|
|
2937
|
+
setDraft(e.target.value);
|
|
2938
|
+
if (err) setErr("");
|
|
2939
|
+
},
|
|
2940
|
+
onBlur: commit,
|
|
2941
|
+
onKeyDown: (e) => {
|
|
2942
|
+
if (e.key === "Enter") commit();
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
),
|
|
2946
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2947
|
+
"button",
|
|
2948
|
+
{
|
|
2949
|
+
type: "button",
|
|
2950
|
+
onClick: () => {
|
|
2951
|
+
setRecording((r) => !r);
|
|
2952
|
+
setErr("");
|
|
2953
|
+
},
|
|
2954
|
+
style: {
|
|
2955
|
+
height: 28,
|
|
2956
|
+
padding: "0 10px",
|
|
2957
|
+
borderRadius: 6,
|
|
2958
|
+
border: "1px solid var(--dsw-alias-border-l3)",
|
|
2959
|
+
background: "transparent",
|
|
2960
|
+
color: "var(--dsw-alias-label-secondary)",
|
|
2961
|
+
fontSize: 12,
|
|
2962
|
+
cursor: "pointer"
|
|
2963
|
+
},
|
|
2964
|
+
children: recording ? t("shortcutCancel") : t("shortcutRecord")
|
|
2965
|
+
}
|
|
2966
|
+
)
|
|
2967
|
+
] }),
|
|
2968
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: 11, lineHeight: "14px", color: err ? "var(--dsw-alias-state-error-primary)" : "var(--dsw-alias-label-tertiary)" }, children: recording ? t("shortcutRecording") : err })
|
|
2969
|
+
] });
|
|
2970
|
+
}
|
|
2600
2971
|
function SelectField({
|
|
2601
2972
|
score,
|
|
2602
2973
|
field,
|
|
@@ -2895,7 +3266,7 @@ var NEXT_ENTRY_FIELDS = [
|
|
|
2895
3266
|
{ key: "echoGateDb", label: "echoGateDbLabel", fmt: (v) => `${v} ${t("unitDb")}` },
|
|
2896
3267
|
{ key: "autoSend", label: "autoSendLabel", fmt: (v) => v ? t("valueOn") : t("valueOff") },
|
|
2897
3268
|
{ key: "autoResume", label: "autoResumeLabel", fmt: (v) => v ? t("valueOn") : t("valueOff") },
|
|
2898
|
-
{ key: "mode", label: "modeLabel", fmt: (v) => t(v === "hold" ? "modeHold" : "modeToggle") },
|
|
3269
|
+
{ key: "mode", label: "modeLabel", fmt: (v) => t(v === "hold" ? "modeHold" : v === "once" ? "modeOnce" : "modeToggle") },
|
|
2899
3270
|
{ key: "wakeWord", label: "wakeWordLabel", fmt: (v) => v ? t("valueQuoted").replace("{value}", String(v)) : t("valueOff") },
|
|
2900
3271
|
{ key: "toolBeep", label: "toolBeepLabel", fmt: (v) => v ? t("valueOn") : t("valueOff") },
|
|
2901
3272
|
{ key: "captionFontSize", label: "captionFontSizeLabel", fmt: (v) => t(v === 1 ? "captionSizeM" : v === 2 ? "captionSizeL" : v === 3 ? "captionSizeXL" : "captionSizeS") },
|
|
@@ -3270,14 +3641,29 @@ function VoiceSettingsCard({ scope, defaultOpen = false }) {
|
|
|
3270
3641
|
value: value.mode,
|
|
3271
3642
|
options: [
|
|
3272
3643
|
{ v: "toggle", label: t("modeToggle") },
|
|
3273
|
-
{ v: "hold", label: t("modeHold") }
|
|
3644
|
+
{ v: "hold", label: t("modeHold") },
|
|
3645
|
+
{ v: "once", label: t("modeOnce") }
|
|
3274
3646
|
]
|
|
3275
3647
|
}
|
|
3276
3648
|
) }),
|
|
3277
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "shortcut", desc: t("descShortcut"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TextField, { score: scope, field: "shortcut", value: value.shortcut ?? "Ctrl+Shift+V", placeholder: "Ctrl+Shift+V" }) }),
|
|
3278
3649
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "wakeWord", desc: t("descWakeWord"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TextField, { score: scope, field: "wakeWord", value: value.wakeWord ?? "", placeholder: t("wakePlaceholder") }) }),
|
|
3279
3650
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "toolBeep", desc: t("descToolBeep"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: Boolean(value.toolBeep), onChange: (e) => void scope.set("toolBeep", e.target.checked) }) }),
|
|
3280
3651
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "autoSend", desc: t("descAutoSend"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: Boolean(value.autoSend), onChange: (e) => void scope.set("autoSend", e.target.checked) }) }),
|
|
3652
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "readAloud", desc: t("descReadAloud"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3653
|
+
SegGroup,
|
|
3654
|
+
{
|
|
3655
|
+
score: scope,
|
|
3656
|
+
field: "readAloud",
|
|
3657
|
+
value: value.readAloud ?? "voice",
|
|
3658
|
+
options: [
|
|
3659
|
+
{ v: "voice", label: t("readAloudVoice") },
|
|
3660
|
+
{ v: "always", label: t("readAloudAlways") },
|
|
3661
|
+
{ v: "off", label: t("readAloudOff") }
|
|
3662
|
+
]
|
|
3663
|
+
}
|
|
3664
|
+
) }),
|
|
3665
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "showStatusBar", desc: t("descShowStatusBar"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: value.showStatusBar !== false, onChange: (e) => void scope.set("showStatusBar", e.target.checked) }) }),
|
|
3666
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "showCaptions", desc: t("descShowCaptions"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: value.showCaptions !== false, onChange: (e) => void scope.set("showCaptions", e.target.checked) }) }),
|
|
3281
3667
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "autoResume", desc: t("descAutoResume"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: Boolean(value.autoResume), onChange: (e) => void scope.set("autoResume", e.target.checked) }) }),
|
|
3282
3668
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "captionFontSize", desc: t("descCaptionFontSize"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3283
3669
|
SegGroup,
|
|
@@ -3311,6 +3697,39 @@ function VoiceSettingsCard({ scope, defaultOpen = false }) {
|
|
|
3311
3697
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "llmCorrect", desc: t("descLlmCorrect"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: value.llmCorrect === true, onChange: (e) => void scope.set("llmCorrect", e.target.checked) }) }),
|
|
3312
3698
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "yieldMs", desc: t("descYieldMs"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NumberField, { score: scope, field: "yieldMs", value: value.yieldMs ?? 1500, min: 500, max: 3e3, step: 100 }) })
|
|
3313
3699
|
] }),
|
|
3700
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Section, { title: t("secShortcut"), children: [
|
|
3701
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "shortcut", desc: t("descShortcut"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ShortcutField, { score: scope, field: "shortcut", value: value.shortcut ?? "" }) }),
|
|
3702
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "composerShortcut", desc: t("descComposerShortcut"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ShortcutField, { score: scope, field: "composerShortcut", value: value.composerShortcut ?? "Alt+Enter" }) }),
|
|
3703
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "flex-start", gap: 10, padding: "2px 0 6px" }, children: [
|
|
3704
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { flex: 1, fontSize: 11, lineHeight: "17px", color: "var(--dsw-alias-label-tertiary)" }, children: t("shortcutNote") }),
|
|
3705
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3706
|
+
"button",
|
|
3707
|
+
{
|
|
3708
|
+
type: "button",
|
|
3709
|
+
onClick: () => {
|
|
3710
|
+
void scope.set("shortcut", "Ctrl+Shift+V");
|
|
3711
|
+
void scope.set("composerShortcut", "Alt+Enter");
|
|
3712
|
+
try {
|
|
3713
|
+
window.dispatchEvent(new Event("dshvm-settings-changed"));
|
|
3714
|
+
} catch {
|
|
3715
|
+
}
|
|
3716
|
+
},
|
|
3717
|
+
style: {
|
|
3718
|
+
flexShrink: 0,
|
|
3719
|
+
height: 26,
|
|
3720
|
+
padding: "0 10px",
|
|
3721
|
+
borderRadius: 6,
|
|
3722
|
+
border: "1px solid var(--dsw-alias-border-l3)",
|
|
3723
|
+
background: "transparent",
|
|
3724
|
+
color: "var(--dsw-alias-label-secondary)",
|
|
3725
|
+
fontSize: 12,
|
|
3726
|
+
cursor: "pointer"
|
|
3727
|
+
},
|
|
3728
|
+
children: t("shortcutReset")
|
|
3729
|
+
}
|
|
3730
|
+
)
|
|
3731
|
+
] })
|
|
3732
|
+
] }),
|
|
3314
3733
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Section, { title: t("secRecognition"), children: [
|
|
3315
3734
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "senseVoice", desc: t("descSenseVoice"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: Boolean(value.senseVoice), onChange: (e) => void scope.set("senseVoice", e.target.checked) }) }),
|
|
3316
3735
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "senseITN", desc: t("descSenseITN"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: value.senseITN !== false, onChange: (e) => void scope.set("senseITN", e.target.checked) }) }),
|
|
@@ -3328,39 +3747,94 @@ function VoiceSettingsCard({ scope, defaultOpen = false }) {
|
|
|
3328
3747
|
|
|
3329
3748
|
// src/settings-http-scope.ts
|
|
3330
3749
|
var SETTINGS_URL = "/voice-mode/settings";
|
|
3750
|
+
var RETRY_BASE_MS = 500;
|
|
3751
|
+
var RETRY_MAX_MS = 1e4;
|
|
3331
3752
|
function createHttpScope(origin = location.origin, fetchImpl = fetch) {
|
|
3332
3753
|
let snap = { status: "loading", value: {} };
|
|
3333
3754
|
const subs = /* @__PURE__ */ new Set();
|
|
3334
|
-
let
|
|
3755
|
+
let inFlight = false;
|
|
3756
|
+
let writing = 0;
|
|
3757
|
+
let writeGen = 0;
|
|
3758
|
+
let pendingReload = false;
|
|
3759
|
+
let disposed = false;
|
|
3760
|
+
let retryTimer = null;
|
|
3761
|
+
let retryDelay = 0;
|
|
3335
3762
|
const emit = (next) => {
|
|
3336
3763
|
snap = next;
|
|
3337
|
-
for (const fn of [...subs])
|
|
3764
|
+
for (const fn of [...subs]) {
|
|
3765
|
+
try {
|
|
3766
|
+
fn();
|
|
3767
|
+
} catch (e) {
|
|
3768
|
+
console.warn("[dsh-voice-mode] settings scope subscriber failed: " + String(e));
|
|
3769
|
+
}
|
|
3770
|
+
}
|
|
3771
|
+
};
|
|
3772
|
+
const clearRetry = () => {
|
|
3773
|
+
if (retryTimer !== null) {
|
|
3774
|
+
clearTimeout(retryTimer);
|
|
3775
|
+
retryTimer = null;
|
|
3776
|
+
}
|
|
3338
3777
|
};
|
|
3339
3778
|
const load = async () => {
|
|
3779
|
+
if (disposed) return;
|
|
3780
|
+
if (inFlight) {
|
|
3781
|
+
pendingReload = true;
|
|
3782
|
+
return;
|
|
3783
|
+
}
|
|
3784
|
+
inFlight = true;
|
|
3785
|
+
clearRetry();
|
|
3786
|
+
const myGen = writeGen;
|
|
3340
3787
|
try {
|
|
3341
3788
|
const res = await fetchImpl(origin + SETTINGS_URL);
|
|
3342
3789
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
3343
3790
|
const data = await res.json();
|
|
3344
|
-
|
|
3791
|
+
retryDelay = 0;
|
|
3792
|
+
if (writing === 0 && myGen === writeGen) emit({ status: "ready", value: data.value ?? {} });
|
|
3345
3793
|
} catch {
|
|
3346
3794
|
emit({ status: "unavailable", value: snap.value });
|
|
3795
|
+
scheduleRetry();
|
|
3796
|
+
} finally {
|
|
3797
|
+
inFlight = false;
|
|
3798
|
+
if (pendingReload) {
|
|
3799
|
+
pendingReload = false;
|
|
3800
|
+
if (!disposed && subs.size > 0) void load();
|
|
3801
|
+
}
|
|
3347
3802
|
}
|
|
3348
3803
|
};
|
|
3349
|
-
|
|
3804
|
+
const scheduleRetry = () => {
|
|
3805
|
+
if (disposed || subs.size === 0 || retryTimer !== null) return;
|
|
3806
|
+
retryDelay = retryDelay === 0 ? RETRY_BASE_MS : Math.min(retryDelay * 2, RETRY_MAX_MS);
|
|
3807
|
+
retryTimer = setTimeout(() => {
|
|
3808
|
+
retryTimer = null;
|
|
3809
|
+
void load();
|
|
3810
|
+
}, retryDelay);
|
|
3811
|
+
};
|
|
3812
|
+
const onFocus = () => {
|
|
3813
|
+
if (subs.size > 0) void load();
|
|
3814
|
+
};
|
|
3815
|
+
if (typeof window !== "undefined" && typeof window.addEventListener === "function") {
|
|
3816
|
+
window.addEventListener("focus", onFocus);
|
|
3817
|
+
}
|
|
3818
|
+
const scope = {
|
|
3350
3819
|
getSnapshot: () => snap,
|
|
3351
3820
|
subscribe(fn) {
|
|
3821
|
+
const first = subs.size === 0;
|
|
3352
3822
|
subs.add(fn);
|
|
3353
|
-
if (
|
|
3354
|
-
|
|
3823
|
+
if (first) {
|
|
3824
|
+
retryDelay = 0;
|
|
3355
3825
|
void load();
|
|
3356
3826
|
}
|
|
3357
3827
|
return () => {
|
|
3358
3828
|
subs.delete(fn);
|
|
3829
|
+
if (subs.size === 0) clearRetry();
|
|
3359
3830
|
};
|
|
3360
3831
|
},
|
|
3361
3832
|
async set(field, value) {
|
|
3833
|
+
if (disposed) return;
|
|
3362
3834
|
const before = snap;
|
|
3835
|
+
writing++;
|
|
3363
3836
|
emit({ status: "ready", value: { ...snap.value, [field]: value } });
|
|
3837
|
+
let ok = false;
|
|
3364
3838
|
try {
|
|
3365
3839
|
const res = await fetchImpl(origin + SETTINGS_URL, {
|
|
3366
3840
|
method: "POST",
|
|
@@ -3370,12 +3844,25 @@ function createHttpScope(origin = location.origin, fetchImpl = fetch) {
|
|
|
3370
3844
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
3371
3845
|
const data = await res.json();
|
|
3372
3846
|
emit({ status: "ready", value: data.value ?? before.value });
|
|
3847
|
+
ok = true;
|
|
3373
3848
|
} catch {
|
|
3374
3849
|
emit(before);
|
|
3375
|
-
|
|
3850
|
+
} finally {
|
|
3851
|
+
writing--;
|
|
3852
|
+
writeGen++;
|
|
3376
3853
|
}
|
|
3854
|
+
if (!ok) await load();
|
|
3855
|
+
},
|
|
3856
|
+
dispose: () => {
|
|
3857
|
+
disposed = true;
|
|
3858
|
+
pendingReload = false;
|
|
3859
|
+
if (typeof window !== "undefined" && typeof window.removeEventListener === "function") {
|
|
3860
|
+
window.removeEventListener("focus", onFocus);
|
|
3861
|
+
}
|
|
3862
|
+
clearRetry();
|
|
3377
3863
|
}
|
|
3378
3864
|
};
|
|
3865
|
+
return scope;
|
|
3379
3866
|
}
|
|
3380
3867
|
|
|
3381
3868
|
// src/client.tsx
|
|
@@ -3409,7 +3896,7 @@ function telemetryDeltas(tel) {
|
|
|
3409
3896
|
}
|
|
3410
3897
|
return out;
|
|
3411
3898
|
}
|
|
3412
|
-
var BUILD_TAG = "
|
|
3899
|
+
var BUILD_TAG = "dc828c8";
|
|
3413
3900
|
var TELEMETRY_FLAG = "dsh-voice-mode.telemetry";
|
|
3414
3901
|
var telemetryEnabled = typeof localStorage !== "undefined" && localStorage.getItem(TELEMETRY_FLAG) === "1";
|
|
3415
3902
|
console.log("[dsh-voice] build=" + BUILD_TAG);
|
|
@@ -3446,20 +3933,32 @@ var ECHO_TAIL_MS = 400;
|
|
|
3446
3933
|
var HOLD_CLEAR_FRAMES = 2;
|
|
3447
3934
|
var WAVE_BARS = 14;
|
|
3448
3935
|
var BASE_PATH2 = "/voice-mode";
|
|
3449
|
-
function
|
|
3936
|
+
function displaySettings(c) {
|
|
3937
|
+
return {
|
|
3938
|
+
readAloud: c.readAloud === "always" || c.readAloud === "off" ? c.readAloud : "voice",
|
|
3939
|
+
showCaptions: c.showCaptions !== false,
|
|
3940
|
+
showStatusBar: c.showStatusBar !== false
|
|
3941
|
+
};
|
|
3942
|
+
}
|
|
3943
|
+
var STOP_READING_LINE = Number.MAX_SAFE_INTEGER;
|
|
3944
|
+
function getTabId(fresh = false) {
|
|
3945
|
+
const KEY = "dshvm-tabId";
|
|
3946
|
+
const make = () => typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : Math.random().toString(36).slice(2) + Date.now().toString(36);
|
|
3450
3947
|
try {
|
|
3451
|
-
|
|
3452
|
-
let id = sessionStorage.getItem(KEY);
|
|
3948
|
+
let id = fresh ? null : sessionStorage.getItem(KEY);
|
|
3453
3949
|
if (!id) {
|
|
3454
|
-
id =
|
|
3950
|
+
id = make();
|
|
3455
3951
|
sessionStorage.setItem(KEY, id);
|
|
3456
3952
|
}
|
|
3457
3953
|
return id;
|
|
3458
3954
|
} catch {
|
|
3459
|
-
return
|
|
3955
|
+
return make();
|
|
3460
3956
|
}
|
|
3461
3957
|
}
|
|
3462
3958
|
var TAB_ID = getTabId();
|
|
3959
|
+
var BUS_GEN_KEY = "__dshvmBusGen";
|
|
3960
|
+
var focusOwnerSeq = 0;
|
|
3961
|
+
var settingsScopeInvalidate = null;
|
|
3463
3962
|
function parseShortcut(s) {
|
|
3464
3963
|
const parts = (s || "").split("+");
|
|
3465
3964
|
const mods = { ctrl: false, shift: false, alt: false, meta: false };
|
|
@@ -3473,6 +3972,9 @@ function parseShortcut(s) {
|
|
|
3473
3972
|
else if (t3.length === 1 && /^[a-z0-9]$/.test(t3)) {
|
|
3474
3973
|
if (key) return null;
|
|
3475
3974
|
key = t3;
|
|
3975
|
+
} else if (t3 === "enter" || t3 === "space" || t3 === "tab") {
|
|
3976
|
+
if (key) return null;
|
|
3977
|
+
key = t3;
|
|
3476
3978
|
} else return null;
|
|
3477
3979
|
}
|
|
3478
3980
|
if (!key) return null;
|
|
@@ -3501,6 +4003,55 @@ function apply(ctx) {
|
|
|
3501
4003
|
document.addEventListener("pointerdown", resumeAudio, { passive: true });
|
|
3502
4004
|
document.addEventListener("keydown", resumeAudio, { passive: true });
|
|
3503
4005
|
}
|
|
4006
|
+
const activity = { declared: false, mounted: 0, listeners: /* @__PURE__ */ new Set() };
|
|
4007
|
+
const activityChanged = () => activity.listeners.forEach((fn) => fn());
|
|
4008
|
+
const ActivityMic = (props) => {
|
|
4009
|
+
(0, import_react3.useEffect)(() => {
|
|
4010
|
+
activity.mounted++;
|
|
4011
|
+
activityChanged();
|
|
4012
|
+
return () => {
|
|
4013
|
+
activity.mounted--;
|
|
4014
|
+
activityChanged();
|
|
4015
|
+
};
|
|
4016
|
+
}, []);
|
|
4017
|
+
return React.createElement(MicButton, props);
|
|
4018
|
+
};
|
|
4019
|
+
const RightMic = (props) => {
|
|
4020
|
+
const [show, setShow] = (0, import_react3.useState)(() => !activity.declared);
|
|
4021
|
+
(0, import_react3.useEffect)(() => {
|
|
4022
|
+
let timer;
|
|
4023
|
+
const evaluate = () => {
|
|
4024
|
+
clearTimeout(timer);
|
|
4025
|
+
if (!activity.declared) setShow(true);
|
|
4026
|
+
else if (activity.mounted > 0) setShow(false);
|
|
4027
|
+
else timer = setTimeout(() => setShow(!activity.declared || activity.mounted === 0), 1500);
|
|
4028
|
+
};
|
|
4029
|
+
activity.listeners.add(evaluate);
|
|
4030
|
+
evaluate();
|
|
4031
|
+
return () => {
|
|
4032
|
+
activity.listeners.delete(evaluate);
|
|
4033
|
+
clearTimeout(timer);
|
|
4034
|
+
};
|
|
4035
|
+
}, []);
|
|
4036
|
+
return show ? React.createElement(MicButton, props) : null;
|
|
4037
|
+
};
|
|
4038
|
+
ctx.slots.inject("conversation.input.activity", () => {
|
|
4039
|
+
activity.declared = true;
|
|
4040
|
+
activityChanged();
|
|
4041
|
+
const dispose = ctx.slots.register(
|
|
4042
|
+
{
|
|
4043
|
+
name: "conversation.input.activity",
|
|
4044
|
+
id: "voice-mode",
|
|
4045
|
+
inject: () => ({ bus, scope })
|
|
4046
|
+
},
|
|
4047
|
+
ActivityMic
|
|
4048
|
+
);
|
|
4049
|
+
return () => {
|
|
4050
|
+
activity.declared = false;
|
|
4051
|
+
activityChanged();
|
|
4052
|
+
dispose?.();
|
|
4053
|
+
};
|
|
4054
|
+
});
|
|
3504
4055
|
ctx.slots.inject(
|
|
3505
4056
|
"conversation.input.right",
|
|
3506
4057
|
() => ctx.slots.register(
|
|
@@ -3508,9 +4059,9 @@ function apply(ctx) {
|
|
|
3508
4059
|
name: "conversation.input.right",
|
|
3509
4060
|
id: "voice-mode",
|
|
3510
4061
|
order: 80,
|
|
3511
|
-
inject: () => ({ bus })
|
|
4062
|
+
inject: () => ({ bus, scope })
|
|
3512
4063
|
},
|
|
3513
|
-
|
|
4064
|
+
RightMic
|
|
3514
4065
|
)
|
|
3515
4066
|
);
|
|
3516
4067
|
ctx.slots.inject(
|
|
@@ -3538,7 +4089,17 @@ function apply(ctx) {
|
|
|
3538
4089
|
)
|
|
3539
4090
|
);
|
|
3540
4091
|
const settingsScope = ctx.get?.("settingsScope");
|
|
3541
|
-
|
|
4092
|
+
let scope;
|
|
4093
|
+
if (settingsScope) {
|
|
4094
|
+
scope = settingsScope.bind({ namespace: "voice-mode" });
|
|
4095
|
+
settingsScopeInvalidate = null;
|
|
4096
|
+
} else {
|
|
4097
|
+
const raw = createHttpScope();
|
|
4098
|
+
const bridge = createScopeBridge(raw);
|
|
4099
|
+
scope = bridge.scope;
|
|
4100
|
+
settingsScopeInvalidate = bridge.invalidate;
|
|
4101
|
+
registerScopeDispose(ctx, raw);
|
|
4102
|
+
}
|
|
3542
4103
|
ctx.slots.inject(
|
|
3543
4104
|
"settings.plugin.item",
|
|
3544
4105
|
() => ctx.slots.register(
|
|
@@ -3575,6 +4136,8 @@ function createAudioEngine(setUi, onPlayed, onPlaybackRef, onAllPlayed) {
|
|
|
3575
4136
|
let fallback = false;
|
|
3576
4137
|
let ctx = null;
|
|
3577
4138
|
let duckGain = null;
|
|
4139
|
+
let analyser = null;
|
|
4140
|
+
let levelBuf = null;
|
|
3578
4141
|
let nextEndAt = 0;
|
|
3579
4142
|
const activeSrcs = /* @__PURE__ */ new Set();
|
|
3580
4143
|
let decoding = false;
|
|
@@ -3589,7 +4152,15 @@ function createAudioEngine(setUi, onPlayed, onPlaybackRef, onAllPlayed) {
|
|
|
3589
4152
|
ctx = new AC();
|
|
3590
4153
|
duckGain = ctx.createGain();
|
|
3591
4154
|
duckGain.gain.value = 1;
|
|
3592
|
-
|
|
4155
|
+
try {
|
|
4156
|
+
analyser = ctx.createAnalyser();
|
|
4157
|
+
analyser.fftSize = 256;
|
|
4158
|
+
duckGain.connect(analyser);
|
|
4159
|
+
analyser.connect(ctx.destination);
|
|
4160
|
+
} catch {
|
|
4161
|
+
analyser = null;
|
|
4162
|
+
duckGain.connect(ctx.destination);
|
|
4163
|
+
}
|
|
3593
4164
|
void ctx.resume?.();
|
|
3594
4165
|
} catch {
|
|
3595
4166
|
ctx = null;
|
|
@@ -3721,11 +4292,54 @@ function createAudioEngine(setUi, onPlayed, onPlaybackRef, onAllPlayed) {
|
|
|
3721
4292
|
const now = ctx.currentTime;
|
|
3722
4293
|
duckGain.gain.cancelScheduledValues(now);
|
|
3723
4294
|
duckGain.gain.setTargetAtTime(1, now, 0.035);
|
|
4295
|
+
},
|
|
4296
|
+
level() {
|
|
4297
|
+
if (!analyser) return 0;
|
|
4298
|
+
if (!levelBuf || levelBuf.length !== analyser.fftSize) levelBuf = new Float32Array(analyser.fftSize);
|
|
4299
|
+
analyser.getFloatTimeDomainData(levelBuf);
|
|
4300
|
+
let sum = 0;
|
|
4301
|
+
for (const v of levelBuf) sum += v * v;
|
|
4302
|
+
return Math.min(1, Math.sqrt(sum / levelBuf.length) / 0.2);
|
|
3724
4303
|
}
|
|
3725
4304
|
};
|
|
3726
4305
|
}
|
|
3727
4306
|
function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
3728
4307
|
let activeSessionId = null;
|
|
4308
|
+
let focusedSessionId = null;
|
|
4309
|
+
const focusOwners = /* @__PURE__ */ new Map();
|
|
4310
|
+
let focusOwnerTab = null;
|
|
4311
|
+
let voiceActive = null;
|
|
4312
|
+
let voiceOwnerTab = null;
|
|
4313
|
+
const busGen = globalThis[BUS_GEN_KEY] = (globalThis[BUS_GEN_KEY] ?? 0) + 1;
|
|
4314
|
+
const focusWarned = /* @__PURE__ */ new Set();
|
|
4315
|
+
const postFocus = (sessionId) => {
|
|
4316
|
+
void reportFocus({
|
|
4317
|
+
sessionId,
|
|
4318
|
+
fetchImpl: () => fetch(`${location.origin}${basePath}/focus`, {
|
|
4319
|
+
method: "POST",
|
|
4320
|
+
headers: { "content-type": "application/json" },
|
|
4321
|
+
body: JSON.stringify({ sessionId, tabId: TAB_ID }),
|
|
4322
|
+
signal: AbortSignal.timeout(3e3)
|
|
4323
|
+
}).then((r) => ({ status: r.status })),
|
|
4324
|
+
// 补报前复核焦点是否已变:403 → 等 800ms 期间用户切到别的会话 → 补报会把**旧**
|
|
4325
|
+
// 会话重新 POST → host 的焦点归属指回旧会话(当前会话不朗读、旧会话被朗读)。
|
|
4326
|
+
stillRelevant: () => focusedSessionId === sessionId,
|
|
4327
|
+
// 留痕文案放在 client.tsx(mic-gesture.ts 不在 strings-coverage 白名单里)。
|
|
4328
|
+
// 日志文案用英文:本仓红线禁止 console.* 里出现中文字面量(见 strings-coverage)。
|
|
4329
|
+
// 含义:/focus 被 host 拒绝(host 不认识这个会话 = 会话表滞后)→ 焦点静默失败,
|
|
4330
|
+
// readAloud=always 可能整页不朗读而用户看不到原因。
|
|
4331
|
+
// 每会话只留一次痕:反复切标签页/可见性变化会反复触发 postFocus。
|
|
4332
|
+
warn: ({ sessionId: warnedSession, status }) => {
|
|
4333
|
+
if (warnedSession !== null) {
|
|
4334
|
+
if (focusWarned.has(warnedSession)) return;
|
|
4335
|
+
focusWarned.add(warnedSession);
|
|
4336
|
+
}
|
|
4337
|
+
console.warn(
|
|
4338
|
+
"[dsh-voice-mode] /focus rejected by host (" + status + " unknown_session): session " + String(warnedSession) + " is not in the host session table -> focus silently failed, readAloud=always may not play at all"
|
|
4339
|
+
);
|
|
4340
|
+
}
|
|
4341
|
+
});
|
|
4342
|
+
};
|
|
3729
4343
|
const DEFAULT_BOOT = {
|
|
3730
4344
|
basePath: BASE_PATH2,
|
|
3731
4345
|
silenceMs: 1500,
|
|
@@ -3734,10 +4348,14 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
3734
4348
|
autoSend: true,
|
|
3735
4349
|
autoResume: false,
|
|
3736
4350
|
mode: "toggle",
|
|
4351
|
+
readAloud: "voice",
|
|
4352
|
+
showCaptions: true,
|
|
4353
|
+
showStatusBar: true,
|
|
3737
4354
|
// 批 7O(ADR-0006):默认 detect(与 src/index.ts VOICE_SETTINGS_DEFAULTS 对齐)。
|
|
3738
4355
|
bargeInMode: "detect",
|
|
3739
4356
|
echoGateDb: 6,
|
|
3740
4357
|
shortcut: "Ctrl+Shift+V",
|
|
4358
|
+
composerShortcut: "Alt+Enter",
|
|
3741
4359
|
wakeWord: "",
|
|
3742
4360
|
toolBeep: false,
|
|
3743
4361
|
captionFontSize: 0,
|
|
@@ -3947,6 +4565,39 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
3947
4565
|
ui.sseDown = false;
|
|
3948
4566
|
notify();
|
|
3949
4567
|
}
|
|
4568
|
+
if (focusedSessionId && (typeof document === "undefined" || document.visibilityState === "visible")) {
|
|
4569
|
+
postFocus(focusedSessionId);
|
|
4570
|
+
}
|
|
4571
|
+
});
|
|
4572
|
+
source.addEventListener("replaced", () => {
|
|
4573
|
+
source?.close();
|
|
4574
|
+
source = null;
|
|
4575
|
+
handleReplaced({
|
|
4576
|
+
staleBus: globalThis[BUS_GEN_KEY] !== busGen,
|
|
4577
|
+
renewTabId: () => {
|
|
4578
|
+
TAB_ID = getTabId(true);
|
|
4579
|
+
return TAB_ID;
|
|
4580
|
+
},
|
|
4581
|
+
reconnect: () => connect(),
|
|
4582
|
+
retire: () => {
|
|
4583
|
+
ui.sseDown = true;
|
|
4584
|
+
notify();
|
|
4585
|
+
}
|
|
4586
|
+
});
|
|
4587
|
+
});
|
|
4588
|
+
source.addEventListener("display", (e) => {
|
|
4589
|
+
try {
|
|
4590
|
+
ui.boot = { ...ui.boot, ...displaySettings(JSON.parse(e.data)) };
|
|
4591
|
+
notify();
|
|
4592
|
+
} catch {
|
|
4593
|
+
}
|
|
4594
|
+
settingsScopeInvalidate?.();
|
|
4595
|
+
});
|
|
4596
|
+
source.addEventListener("focus", (e) => {
|
|
4597
|
+
try {
|
|
4598
|
+
focusOwnerTab = JSON.parse(e.data).tabId ?? null;
|
|
4599
|
+
} catch {
|
|
4600
|
+
}
|
|
3950
4601
|
});
|
|
3951
4602
|
source.addEventListener("error", () => {
|
|
3952
4603
|
if (!ui.sseDown) {
|
|
@@ -3959,6 +4610,8 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
3959
4610
|
const data = JSON.parse(e.data);
|
|
3960
4611
|
const active = data.active ?? null;
|
|
3961
4612
|
const ownerTabId = data.ownerTabId ?? null;
|
|
4613
|
+
voiceActive = active;
|
|
4614
|
+
voiceOwnerTab = ownerTabId;
|
|
3962
4615
|
const preempted = active !== activeSessionId || ownerTabId !== null && activeSessionId !== null && ownerTabId !== TAB_ID;
|
|
3963
4616
|
if (activeSessionId !== null && preempted) {
|
|
3964
4617
|
const prev = activeSessionId;
|
|
@@ -3987,8 +4640,33 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
3987
4640
|
source.addEventListener("turn", (e) => {
|
|
3988
4641
|
try {
|
|
3989
4642
|
const ev = JSON.parse(e.data);
|
|
4643
|
+
if (ev.state === "agent-speaking" && ev.sessionId) {
|
|
4644
|
+
const sameRoundContinuation = toolPending.has(ev.sessionId);
|
|
4645
|
+
toolPending.delete(ev.sessionId);
|
|
4646
|
+
const turn = typeof ev.turn === "number" ? ev.turn : void 0;
|
|
4647
|
+
const r = applyTurnEvent({
|
|
4648
|
+
turn,
|
|
4649
|
+
identity: { lastTurn: currentTurn.get(ev.sessionId) },
|
|
4650
|
+
hasStopLine: rejectSeqUpTo.get(ev.sessionId) === STOP_READING_LINE,
|
|
4651
|
+
untilNextRun: stopUntilRun.has(ev.sessionId),
|
|
4652
|
+
sameRoundContinuation
|
|
4653
|
+
});
|
|
4654
|
+
if (r.identity.lastTurn !== void 0) currentTurn.set(ev.sessionId, r.identity.lastTurn);
|
|
4655
|
+
if (r.release) rejectSeqUpTo.delete(ev.sessionId);
|
|
4656
|
+
}
|
|
3990
4657
|
if (ev.sessionId === activeSessionId && ev.state) {
|
|
3991
4658
|
ui.turn = ev.state;
|
|
4659
|
+
if (ev.state === "agent-speaking") ui.ttsDrained = false;
|
|
4660
|
+
notify();
|
|
4661
|
+
}
|
|
4662
|
+
} catch {
|
|
4663
|
+
}
|
|
4664
|
+
});
|
|
4665
|
+
source.addEventListener("tts-idle", (e) => {
|
|
4666
|
+
try {
|
|
4667
|
+
const ev = JSON.parse(e.data);
|
|
4668
|
+
if (ev.sessionId === activeSessionId && !ui.ttsDrained) {
|
|
4669
|
+
ui.ttsDrained = true;
|
|
3992
4670
|
notify();
|
|
3993
4671
|
}
|
|
3994
4672
|
} catch {
|
|
@@ -4067,6 +4745,7 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4067
4745
|
source.addEventListener("tool", (e) => {
|
|
4068
4746
|
try {
|
|
4069
4747
|
const p = JSON.parse(e.data);
|
|
4748
|
+
if (p.sessionId) toolPending.add(p.sessionId);
|
|
4070
4749
|
if (p.sessionId === activeSessionId && ui.boot.toolBeep === true) playToolBeep();
|
|
4071
4750
|
} catch {
|
|
4072
4751
|
}
|
|
@@ -4074,13 +4753,23 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4074
4753
|
};
|
|
4075
4754
|
connect();
|
|
4076
4755
|
const rejectSeqUpTo = /* @__PURE__ */ new Map();
|
|
4756
|
+
const stopUntilRun = /* @__PURE__ */ new Set();
|
|
4757
|
+
const toolPending = /* @__PURE__ */ new Set();
|
|
4758
|
+
const currentTurn = /* @__PURE__ */ new Map();
|
|
4077
4759
|
const lastFinalSeq = /* @__PURE__ */ new Map();
|
|
4078
4760
|
let curSentenceId = null;
|
|
4079
4761
|
let curChunks = [];
|
|
4080
4762
|
let curBytes = 0;
|
|
4081
4763
|
let curChunkCount = 0;
|
|
4082
4764
|
audioListeners.add((frame) => {
|
|
4083
|
-
if (frame.sessionId
|
|
4765
|
+
if (frame.sessionId === activeSessionId && ui.ttsDrained) {
|
|
4766
|
+
ui.ttsDrained = false;
|
|
4767
|
+
notify();
|
|
4768
|
+
}
|
|
4769
|
+
const readAloud = ui.boot.readAloud ?? "voice";
|
|
4770
|
+
if (readAloud === "off") return;
|
|
4771
|
+
const alwaysHere = readAloud === "always" && frame.sessionId === focusedSessionId && focusOwnerTab === TAB_ID && !(voiceActive === frame.sessionId && voiceOwnerTab !== null && voiceOwnerTab !== TAB_ID);
|
|
4772
|
+
if (frame.sessionId !== activeSessionId && !alwaysHere) return;
|
|
4084
4773
|
const rejectLine = rejectSeqUpTo.get(frame.sessionId);
|
|
4085
4774
|
if (rejectLine !== void 0 && frame.sentenceId <= rejectLine) return;
|
|
4086
4775
|
if (backchannelHoldUntil && Date.now() < backchannelHoldUntil) {
|
|
@@ -4140,7 +4829,7 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4140
4829
|
curChunkCount += 1;
|
|
4141
4830
|
});
|
|
4142
4831
|
const doSkipAudio = (sidArg) => {
|
|
4143
|
-
const sid = sidArg ?? activeSessionId;
|
|
4832
|
+
const sid = sidArg ?? activeSessionId ?? focusedSessionId;
|
|
4144
4833
|
if (sid) {
|
|
4145
4834
|
rejectSeqUpTo.set(sid, Math.max(lastFinalSeq.get(sid) ?? -1, curSentenceId ?? -1));
|
|
4146
4835
|
}
|
|
@@ -4265,6 +4954,46 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4265
4954
|
resetTelemetry,
|
|
4266
4955
|
warmAudio() {
|
|
4267
4956
|
engine.warm();
|
|
4957
|
+
},
|
|
4958
|
+
playbackLevel() {
|
|
4959
|
+
return engine.level();
|
|
4960
|
+
},
|
|
4961
|
+
runStarted(sessionId) {
|
|
4962
|
+
if (rejectSeqUpTo.get(sessionId) === STOP_READING_LINE) rejectSeqUpTo.delete(sessionId);
|
|
4963
|
+
stopUntilRun.delete(sessionId);
|
|
4964
|
+
},
|
|
4965
|
+
setFocusedSession(sessionId, owner = FOCUS_OWNER_DEFAULT) {
|
|
4966
|
+
if (sessionId === null) {
|
|
4967
|
+
const { changed, focused } = focusRelease(focusOwners, owner);
|
|
4968
|
+
if (!changed) return;
|
|
4969
|
+
focusedSessionId = focused;
|
|
4970
|
+
if (focused !== null) {
|
|
4971
|
+
if (typeof document === "undefined" || document.visibilityState === "visible") postFocus(focused);
|
|
4972
|
+
return;
|
|
4973
|
+
}
|
|
4974
|
+
if (focusOwnerTab === TAB_ID) postFocus(null);
|
|
4975
|
+
return;
|
|
4976
|
+
}
|
|
4977
|
+
focusClaim(focusOwners, owner, sessionId);
|
|
4978
|
+
focusedSessionId = sessionId;
|
|
4979
|
+
if (typeof document === "undefined" || document.visibilityState === "visible") postFocus(sessionId);
|
|
4980
|
+
},
|
|
4981
|
+
stopReading(untilNextRun = false) {
|
|
4982
|
+
const sid = activeSessionId ?? focusedSessionId;
|
|
4983
|
+
doSkipAudio(sid);
|
|
4984
|
+
if (!sid) return;
|
|
4985
|
+
rejectSeqUpTo.set(sid, STOP_READING_LINE);
|
|
4986
|
+
if (untilNextRun) stopUntilRun.add(sid);
|
|
4987
|
+
else stopUntilRun.delete(sid);
|
|
4988
|
+
void fetch(`${location.origin}${basePath}/cancel`, {
|
|
4989
|
+
method: "POST",
|
|
4990
|
+
headers: { "content-type": "application/json" },
|
|
4991
|
+
// reason=stop-reading:host 据此**不**动回合闸门(否则「停止朗读」后的排空分支
|
|
4992
|
+
// 会补发 tts-idle → mode:once 提前退出,R15 Important-1 回归)。
|
|
4993
|
+
body: cancelPayload({ sessionId: sid, keepAsr: true, reason: "stop-reading" }),
|
|
4994
|
+
signal: AbortSignal.timeout(3e3)
|
|
4995
|
+
}).catch(() => {
|
|
4996
|
+
});
|
|
4268
4997
|
}
|
|
4269
4998
|
};
|
|
4270
4999
|
}
|
|
@@ -4291,12 +5020,125 @@ html.dshvm-holding, html.dshvm-holding * {
|
|
|
4291
5020
|
}
|
|
4292
5021
|
/* \u6279 3\uFF1A\u5B57\u5E55\u4E2D\u6587\u957F\u8BCD/URL \u6362\u884C\uFF08\u5916\u5C42 maxHeight:30vh + overflow:hidden \u63A7\u5236\u9AD8\u5EA6\u4E0D\u6EA2\u51FA\uFF09\u3002 */
|
|
4293
5022
|
.dshvm-caption { word-break: break-word; overflow-wrap: anywhere; }
|
|
5023
|
+
/* \u9EA6\u514B\u98CE\u6309\u94AE\uFF08PR #16 by dyguests\uFF09\uFF1A\u72B6\u6001\u5168\u5728\u6309\u94AE\u4E0A\u2014\u2014\u989C\u8272\u533A\u5206\u6A21\u5F0F\uFF0C\u7AD6\u6761\u8DDF\u968F\u7535\u5E73\uFF0C
|
|
5024
|
+
\u7B49\u5F85\u8F6C\u5708\u3001\u6536\u5C3E\u5BF9\u52FE\u3001\u53F3\u4E0A\u6A59\u70B9=\u68C0\u6D4B\u5230\u8BF4\u8BDD\u3001\u5DE6\u4E0A\u7EA2\u70B9=\u51FA\u9519\u3002\u989C\u8272\u8D70 dsw \u53D8\u91CF\uFF0C\u65E7\u5BBF\u4E3B\u65E0\u53D8\u91CF\u65F6\u7528\u515C\u5E95\u8272\u3002 */
|
|
5025
|
+
.dshvm-mic {
|
|
5026
|
+
position: relative; flex: none; width: 34px; height: 34px; padding: 0;
|
|
5027
|
+
display: grid; place-items: center; border: none; border-radius: 999px;
|
|
5028
|
+
background: transparent; color: var(--dsw-alias-label-secondary, #8b949e); cursor: pointer;
|
|
5029
|
+
transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
|
|
5030
|
+
touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
|
|
5031
|
+
}
|
|
5032
|
+
.dshvm-mic:hover { background: var(--dsw-alias-interactive-bg-hover, rgba(139,148,158,.14)); }
|
|
5033
|
+
.dshvm-mic:focus-visible { outline: 2px solid var(--dsw-alias-state-business-primary, #58a6ff); outline-offset: -2px; }
|
|
5034
|
+
.dshvm-mic svg { display: block; }
|
|
5035
|
+
.dshvm-mic[data-state="pending"] { --c: var(--dsw-alias-state-business-primary, #58a6ff); }
|
|
5036
|
+
.dshvm-mic[data-state="on"] { --c: var(--dsw-alias-state-success-primary, #2ea043); }
|
|
5037
|
+
.dshvm-mic[data-state="hold"] { --c: var(--dsw-alias-state-business-primary, #58a6ff); }
|
|
5038
|
+
.dshvm-mic[data-state="holding"] { --c: var(--dsw-alias-state-error-primary, #f85149); }
|
|
5039
|
+
.dshvm-mic[data-state="reading"] { --c: var(--dsw-alias-state-business-primary, #58a6ff); }
|
|
5040
|
+
.dshvm-mic[data-state="waiting"], .dshvm-mic[data-state="ending"] { --c: var(--dsw-alias-label-tertiary, #8b949e); }
|
|
5041
|
+
.dshvm-mic[data-state]:not([data-state="off"]) { color: var(--c); background: color-mix(in srgb, var(--c) 13%, transparent); }
|
|
5042
|
+
.dshvm-mic[data-state="on"], .dshvm-mic[data-state="reading"] { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 10%, transparent); }
|
|
5043
|
+
.dshvm-mic[data-state]:not([data-state="off"]):hover { background: color-mix(in srgb, var(--c) 20%, transparent); }
|
|
5044
|
+
.dshvm-eq { display: inline-flex; align-items: center; justify-content: center; gap: 2px; width: 16px; height: 16px; pointer-events: none; }
|
|
5045
|
+
.dshvm-eq i { display: block; width: 3px; border-radius: 2px; background: currentColor; }
|
|
5046
|
+
.dshvm-eq-out { gap: 1.5px; }
|
|
5047
|
+
.dshvm-eq-out i { width: 2px; }
|
|
5048
|
+
.dshvm-mic-dot { position: absolute; top: 0; width: 7px; height: 7px; border-radius: 999px; pointer-events: none;
|
|
5049
|
+
box-shadow: 0 0 0 2px var(--dsw-specific-input-major, transparent); }
|
|
5050
|
+
.dshvm-mic-dot[data-kind="vad"] { right: 0; background: var(--dsw-alias-state-warn-primary, #d29922); }
|
|
5051
|
+
.dshvm-mic-dot[data-kind="error"] { left: 0; background: var(--dsw-alias-state-error-primary, #f85149); }
|
|
5052
|
+
.dshvm-mic-timer { position: absolute; left: 50%; top: calc(100% + 2px); transform: translateX(-50%); padding: 0 3px; border-radius: 4px;
|
|
5053
|
+
background: var(--dsw-specific-input-major, transparent); font-size: 9.5px; line-height: 12px; color: var(--dsw-alias-label-tertiary, #8b949e);
|
|
5054
|
+
font-variant-numeric: tabular-nums; white-space: nowrap; pointer-events: none; }
|
|
5055
|
+
.dshvm-spin { animation: dshvm-spin 0.9s linear infinite; }
|
|
5056
|
+
.dshvm-menu { display: flex; flex-direction: column; gap: 2px; padding: 6px; border-radius: 10px;
|
|
5057
|
+
background: var(--dsw-alias-bg-layer-3, #fff); border: 1px solid var(--dsw-alias-border-l2, rgba(139,148,158,.35));
|
|
5058
|
+
box-shadow: 0 8px 24px rgba(15, 17, 21, 0.14); color: var(--dsw-alias-label-primary, inherit);
|
|
5059
|
+
font-family: inherit; font-size: 12px; animation: dshvm-fadein 0.12s ease; }
|
|
5060
|
+
.dshvm-menu-label { padding: 2px 8px 4px; font-size: 11px; color: var(--dsw-alias-label-tertiary, #8b949e); }
|
|
5061
|
+
.dshvm-menu-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 5px 8px;
|
|
5062
|
+
border: none; border-radius: 6px; background: transparent; color: inherit; cursor: pointer; font: inherit; font-size: 12px; text-align: left; }
|
|
5063
|
+
.dshvm-menu-item:hover, .dshvm-menu-item:focus-visible { background: var(--dsw-alias-interactive-bg-hover, rgba(139,148,158,.14)); outline: none; }
|
|
5064
|
+
.dshvm-menu-check { color: var(--dsw-alias-state-business-primary, #58a6ff); font-size: 11px; }
|
|
5065
|
+
.dshvm-menu-sep { height: 1px; margin: 4px 2px; background: var(--dsw-alias-border-l1, rgba(139,148,158,.25)); }
|
|
5066
|
+
@media (prefers-reduced-motion: reduce) { .dshvm-spin, .dshvm-menu { animation: none; } }
|
|
4294
5067
|
`;
|
|
4295
5068
|
document.head.appendChild(el);
|
|
4296
5069
|
}, []);
|
|
4297
5070
|
}
|
|
5071
|
+
var IS_MAC = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent || "");
|
|
5072
|
+
var ONCE_SETTLE_MS = 1200;
|
|
5073
|
+
var ONCE_NO_START_MS = 3e4;
|
|
5074
|
+
var ONCE_STALL_MS = 1e4;
|
|
5075
|
+
function MicMenu({ scope, anchor, onClose }) {
|
|
5076
|
+
const [snap, setSnap] = (0, import_react3.useState)(() => scope.getSnapshot());
|
|
5077
|
+
(0, import_react3.useEffect)(() => scope.subscribe(() => setSnap({ ...scope.getSnapshot() })), [scope]);
|
|
5078
|
+
const menuRef = (0, import_react3.useRef)(null);
|
|
5079
|
+
(0, import_react3.useEffect)(() => {
|
|
5080
|
+
menuRef.current?.querySelector("button")?.focus();
|
|
5081
|
+
const onDown = (e) => {
|
|
5082
|
+
if (e.target instanceof Node && menuRef.current?.contains(e.target)) return;
|
|
5083
|
+
onClose(false);
|
|
5084
|
+
};
|
|
5085
|
+
const onKey = (e) => {
|
|
5086
|
+
if (e.key === "Escape") {
|
|
5087
|
+
e.preventDefault();
|
|
5088
|
+
onClose(true);
|
|
5089
|
+
return;
|
|
5090
|
+
}
|
|
5091
|
+
if (e.key !== "ArrowDown" && e.key !== "ArrowUp") return;
|
|
5092
|
+
e.preventDefault();
|
|
5093
|
+
const items = Array.from(menuRef.current?.querySelectorAll("button") ?? []);
|
|
5094
|
+
const i = items.indexOf(document.activeElement);
|
|
5095
|
+
const next = menuFocusIndex(i, items.length, e.key === "ArrowDown" ? 1 : -1);
|
|
5096
|
+
if (next >= 0) items[next]?.focus();
|
|
5097
|
+
};
|
|
5098
|
+
document.addEventListener("pointerdown", onDown, true);
|
|
5099
|
+
document.addEventListener("keydown", onKey, true);
|
|
5100
|
+
return () => {
|
|
5101
|
+
document.removeEventListener("pointerdown", onDown, true);
|
|
5102
|
+
document.removeEventListener("keydown", onKey, true);
|
|
5103
|
+
};
|
|
5104
|
+
}, [onClose]);
|
|
5105
|
+
const v = snap.value ?? {};
|
|
5106
|
+
const width = 208;
|
|
5107
|
+
const r = anchor?.getBoundingClientRect();
|
|
5108
|
+
const below = !r || r.top < 340;
|
|
5109
|
+
const pos = {
|
|
5110
|
+
position: "fixed",
|
|
5111
|
+
zIndex: 9999,
|
|
5112
|
+
width,
|
|
5113
|
+
left: r ? Math.max(8, Math.min(window.innerWidth - width - 8, Math.round(r.right - width))) : 8,
|
|
5114
|
+
...below ? { top: r ? Math.round(r.bottom + 8) : 96 } : { bottom: Math.round(window.innerHeight - r.top + 8) }
|
|
5115
|
+
};
|
|
5116
|
+
const item = (role, checked, label, onPick) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", role, "aria-checked": checked, className: "dshvm-menu-item", onClick: onPick, children: [
|
|
5117
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: label }),
|
|
5118
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dshvm-menu-check", children: checked ? "\u2713" : "" })
|
|
5119
|
+
] }, label);
|
|
5120
|
+
const set = (field, value) => void scope.set(field, value);
|
|
5121
|
+
const mode = v.mode === "hold" || v.mode === "once" ? v.mode : "toggle";
|
|
5122
|
+
const read = v.readAloud === "always" || v.readAloud === "off" ? v.readAloud : "voice";
|
|
5123
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { ref: menuRef, className: "dshvm-menu", role: "menu", "aria-label": t("stateVoiceMode"), style: pos, children: [
|
|
5124
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dshvm-menu-label", children: t("modeLabel") }),
|
|
5125
|
+
["toggle", "hold", "once"].map(
|
|
5126
|
+
(m) => item("menuitemradio", mode === m, t(m === "toggle" ? "modeToggle" : m === "hold" ? "modeHold" : "modeOnce"), () => set("mode", m))
|
|
5127
|
+
),
|
|
5128
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dshvm-menu-sep" }),
|
|
5129
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dshvm-menu-label", children: t("readAloudLabel") }),
|
|
5130
|
+
["voice", "always", "off"].map(
|
|
5131
|
+
(m) => item("menuitemradio", read === m, t(m === "voice" ? "readAloudVoice" : m === "always" ? "readAloudAlways" : "readAloudOff"), () => set("readAloud", m))
|
|
5132
|
+
),
|
|
5133
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dshvm-menu-sep" }),
|
|
5134
|
+
item("menuitemcheckbox", v.showCaptions !== false, t("showCaptionsLabel"), () => set("showCaptions", v.showCaptions === false)),
|
|
5135
|
+
item("menuitemcheckbox", v.showStatusBar !== false, t("showStatusBarLabel"), () => set("showStatusBar", v.showStatusBar === false)),
|
|
5136
|
+
item("menuitemcheckbox", v.autoSend !== false, t("autoSendLabel"), () => set("autoSend", v.autoSend === false))
|
|
5137
|
+
] });
|
|
5138
|
+
}
|
|
4298
5139
|
function MicButton({
|
|
4299
5140
|
bus,
|
|
5141
|
+
scope,
|
|
4300
5142
|
sessionId,
|
|
4301
5143
|
useSession,
|
|
4302
5144
|
useInput,
|
|
@@ -4321,6 +5163,13 @@ function MicButton({
|
|
|
4321
5163
|
const manualHoldRef = (0, import_react3.useRef)(false);
|
|
4322
5164
|
const breakRef = (0, import_react3.useRef)(null);
|
|
4323
5165
|
const pausedForHiddenRef = (0, import_react3.useRef)(false);
|
|
5166
|
+
const focusOwnerRef = (0, import_react3.useRef)(null);
|
|
5167
|
+
if (focusOwnerRef.current === null) focusOwnerRef.current = `mic-${++focusOwnerSeq}`;
|
|
5168
|
+
const focusOwner = focusOwnerRef.current;
|
|
5169
|
+
const onceRef = (0, import_react3.useRef)(null);
|
|
5170
|
+
const [onceWaiting, setOnceWaiting] = (0, import_react3.useState)(false);
|
|
5171
|
+
const [onceEnding, setOnceEnding] = (0, import_react3.useState)(false);
|
|
5172
|
+
const toggleHistRef = (0, import_react3.useRef)([]);
|
|
4324
5173
|
const bootNow = () => bus.ui.boot ?? {
|
|
4325
5174
|
basePath: "/voice-mode",
|
|
4326
5175
|
silenceMs: 1500,
|
|
@@ -4329,10 +5178,14 @@ function MicButton({
|
|
|
4329
5178
|
autoSend: true,
|
|
4330
5179
|
autoResume: false,
|
|
4331
5180
|
mode: "toggle",
|
|
5181
|
+
readAloud: "voice",
|
|
5182
|
+
showCaptions: true,
|
|
5183
|
+
showStatusBar: true,
|
|
4332
5184
|
// 批 7O(ADR-0006):bootNow 兜底默认与 VOICE_SETTINGS_DEFAULTS 对齐为 detect。
|
|
4333
5185
|
bargeInMode: "detect",
|
|
4334
5186
|
echoGateDb: 6,
|
|
4335
5187
|
shortcut: "Ctrl+Shift+V",
|
|
5188
|
+
composerShortcut: "Alt+Enter",
|
|
4336
5189
|
wakeWord: "",
|
|
4337
5190
|
toolBeep: false,
|
|
4338
5191
|
captionFontSize: 0,
|
|
@@ -4351,7 +5204,7 @@ function MicButton({
|
|
|
4351
5204
|
const uiKeyRef = (0, import_react3.useRef)("");
|
|
4352
5205
|
(0, import_react3.useEffect)(
|
|
4353
5206
|
() => bus.subscribe(({ active, ui: u }) => {
|
|
4354
|
-
const key = `${active}|${u.state}|${u.error ?? ""}|${u.notice ?? ""}|${u.mode}|${u.wakeWord}|${u.ttsNotice ?? ""}`;
|
|
5207
|
+
const key = `${active}|${u.state}|${u.error ?? ""}|${u.notice ?? ""}|${u.mode}|${u.wakeWord}|${u.ttsNotice ?? ""}|${u.playing}|${u.turn}|${u.sseDown}|${u.idleWarn}|${u.boot?.showStatusBar}`;
|
|
4355
5208
|
if (key === uiKeyRef.current) return;
|
|
4356
5209
|
uiKeyRef.current = key;
|
|
4357
5210
|
bumpUi((t3) => t3 + 1);
|
|
@@ -4375,10 +5228,12 @@ function MicButton({
|
|
|
4375
5228
|
idleTimeoutMinutes: c.idleTimeoutMinutes ?? cur.idleTimeoutMinutes,
|
|
4376
5229
|
autoSend: c.autoSend ?? cur.autoSend,
|
|
4377
5230
|
autoResume: c.autoResume === true,
|
|
4378
|
-
mode: c.mode === "hold"
|
|
5231
|
+
mode: c.mode === "hold" || c.mode === "once" ? c.mode : "toggle",
|
|
5232
|
+
...displaySettings(c),
|
|
4379
5233
|
bargeInMode: c.bargeInMode === "manual" ? "manual" : c.bargeInMode === "detect" ? "detect" : "auto",
|
|
4380
5234
|
echoGateDb: typeof c.echoGateDb === "number" ? Math.min(12, Math.max(3, c.echoGateDb)) : cur.echoGateDb,
|
|
4381
5235
|
shortcut: typeof c.shortcut === "string" ? c.shortcut : cur.shortcut,
|
|
5236
|
+
composerShortcut: typeof c.composerShortcut === "string" ? c.composerShortcut : cur.composerShortcut,
|
|
4382
5237
|
wakeWord: typeof c.wakeWord === "string" ? c.wakeWord : cur.wakeWord,
|
|
4383
5238
|
toolBeep: c.toolBeep === true,
|
|
4384
5239
|
// 批 3:fetchConfig 是白名单拼接(plan §5.2 措辞「通用透传」与此处源码不符——见 commit message)
|
|
@@ -4469,6 +5324,7 @@ function MicButton({
|
|
|
4469
5324
|
isSpeechFalseRun = 0;
|
|
4470
5325
|
submitInFlightRef.current = false;
|
|
4471
5326
|
correctCycleRef.current++;
|
|
5327
|
+
clearOnce();
|
|
4472
5328
|
breakRef.current = null;
|
|
4473
5329
|
manualHoldRef.current = false;
|
|
4474
5330
|
holdCtrlRef.current = false;
|
|
@@ -4530,6 +5386,7 @@ function MicButton({
|
|
|
4530
5386
|
}
|
|
4531
5387
|
const runSubmit = (submitText) => {
|
|
4532
5388
|
submitInFlightRef.current = true;
|
|
5389
|
+
if (bootNow().mode === "once") beginOnceWait();
|
|
4533
5390
|
const snapshot = submitText.trim() || draftSnapshot;
|
|
4534
5391
|
let wroteBack = false;
|
|
4535
5392
|
if (snapshot !== draftSnapshot && typeof actions?.setDraft === "function") {
|
|
@@ -4602,13 +5459,74 @@ function MicButton({
|
|
|
4602
5459
|
const eng = engineRef.current;
|
|
4603
5460
|
if (eng && (eng.state === "speech" || eng.holding)) return;
|
|
4604
5461
|
if (bus.ui.playing) return;
|
|
4605
|
-
if (bootNow().autoSend === false)
|
|
5462
|
+
if (bootNow().autoSend === false) {
|
|
5463
|
+
if (bootNow().mode === "once") void exitModeRef.current("manual");
|
|
5464
|
+
return;
|
|
5465
|
+
}
|
|
4606
5466
|
submitDraftNow();
|
|
4607
5467
|
}, AUTO_SEND_EXTRA_MS);
|
|
4608
5468
|
};
|
|
5469
|
+
const clearOnce = () => {
|
|
5470
|
+
const o = onceRef.current;
|
|
5471
|
+
if (!o) return;
|
|
5472
|
+
onceRef.current = null;
|
|
5473
|
+
clearTimeout(o.noStart);
|
|
5474
|
+
if (o.settle) clearTimeout(o.settle);
|
|
5475
|
+
if (o.stall) clearTimeout(o.stall);
|
|
5476
|
+
setOnceWaiting(false);
|
|
5477
|
+
setOnceEnding(false);
|
|
5478
|
+
};
|
|
5479
|
+
const checkOnce = () => {
|
|
5480
|
+
const o = onceRef.current;
|
|
5481
|
+
if (!o) return;
|
|
5482
|
+
const running = useSession ? runningRef.current : bus.ui.turn === "agent-speaking";
|
|
5483
|
+
if (running) o.sawRun = true;
|
|
5484
|
+
const quiet = o.sawRun && !running && !bus.ui.playing;
|
|
5485
|
+
const done = onceFinished(o, running, bus.ui.ttsDrained === true, bus.ui.playing);
|
|
5486
|
+
if (done && !o.settle) {
|
|
5487
|
+
setOnceEnding(true);
|
|
5488
|
+
o.settle = setTimeout(() => {
|
|
5489
|
+
if (onceRef.current === o) void exitModeRef.current("manual");
|
|
5490
|
+
}, ONCE_SETTLE_MS);
|
|
5491
|
+
} else if (!done && o.settle) {
|
|
5492
|
+
setOnceEnding(false);
|
|
5493
|
+
clearTimeout(o.settle);
|
|
5494
|
+
o.settle = null;
|
|
5495
|
+
}
|
|
5496
|
+
if (quiet && !o.stall) {
|
|
5497
|
+
o.stall = setTimeout(() => {
|
|
5498
|
+
if (onceRef.current === o) void exitModeRef.current("manual");
|
|
5499
|
+
}, ONCE_STALL_MS);
|
|
5500
|
+
} else if (!quiet && o.stall) {
|
|
5501
|
+
clearTimeout(o.stall);
|
|
5502
|
+
o.stall = null;
|
|
5503
|
+
}
|
|
5504
|
+
};
|
|
5505
|
+
const beginOnceWait = () => {
|
|
5506
|
+
if (onceRef.current || localRef.current !== "on") return;
|
|
5507
|
+
cancelAutoSend();
|
|
5508
|
+
clearIdle();
|
|
5509
|
+
const o = {
|
|
5510
|
+
sawRun: false,
|
|
5511
|
+
settle: null,
|
|
5512
|
+
stall: null,
|
|
5513
|
+
noStart: setTimeout(() => {
|
|
5514
|
+
if (onceRef.current === o && !o.sawRun) void exitModeRef.current("manual");
|
|
5515
|
+
}, ONCE_NO_START_MS)
|
|
5516
|
+
};
|
|
5517
|
+
onceRef.current = o;
|
|
5518
|
+
setOnceWaiting(true);
|
|
5519
|
+
void engineRef.current?.stop();
|
|
5520
|
+
bus.setUi({ partial: "", levels: [], isSpeech: void 0 });
|
|
5521
|
+
checkOnce();
|
|
5522
|
+
};
|
|
4609
5523
|
const exitMode = async (reason) => {
|
|
4610
5524
|
if (localRef.current === "off") return;
|
|
5525
|
+
pendingHoldRef.current = false;
|
|
5526
|
+
pendingHoldReleaseRef.current = false;
|
|
5527
|
+
clearHoldExit();
|
|
4611
5528
|
setLocalMode("off");
|
|
5529
|
+
clearOnce();
|
|
4612
5530
|
clearIdle();
|
|
4613
5531
|
cancelPendingSubmit();
|
|
4614
5532
|
cancelAutoSend();
|
|
@@ -4686,7 +5604,13 @@ function MicButton({
|
|
|
4686
5604
|
method: "POST",
|
|
4687
5605
|
headers: { "content-type": "application/json" },
|
|
4688
5606
|
// hold 按压中保留 host ASR 段(松手定稿续传前半句,防吃句)。
|
|
4689
|
-
|
|
5607
|
+
// reason=interrupt:host 据此可收口回合闸门(abandonTurn)——用户打断与
|
|
5608
|
+
// 「停止朗读」靠它区分(两者 keepAsr 都可能是 true,载荷本身区分不了)。
|
|
5609
|
+
body: cancelPayload({
|
|
5610
|
+
sessionId: sidRef.current,
|
|
5611
|
+
keepAsr: engineRef.current?.holding === true,
|
|
5612
|
+
reason: "interrupt"
|
|
5613
|
+
}),
|
|
4690
5614
|
signal: AbortSignal.timeout(3e3)
|
|
4691
5615
|
}).catch(() => {
|
|
4692
5616
|
});
|
|
@@ -4704,7 +5628,8 @@ function MicButton({
|
|
|
4704
5628
|
{
|
|
4705
5629
|
silenceMs,
|
|
4706
5630
|
basePath,
|
|
4707
|
-
|
|
5631
|
+
// once 的采音/断句/唤醒词与 toggle 完全一致,区别只在定稿后的收尾(见 onSegment)
|
|
5632
|
+
mode: cfg.mode === "hold" ? "hold" : "toggle",
|
|
4708
5633
|
wakeWord: cfg.wakeWord,
|
|
4709
5634
|
echoGateDb: cfg.echoGateDb,
|
|
4710
5635
|
// 批 7N(ADR-0006):打断方式透传——manual 时 handleAudio 仅在 holdActive 期间入流。
|
|
@@ -4777,7 +5702,10 @@ function MicButton({
|
|
|
4777
5702
|
isSpeechFalseRun++;
|
|
4778
5703
|
if (isSpeechFalseRun >= 2) {
|
|
4779
5704
|
isSpeechFalseRun = 0;
|
|
4780
|
-
isSpeechTrueCount =
|
|
5705
|
+
isSpeechTrueCount = decayConfirmCount(
|
|
5706
|
+
isSpeechTrueCount,
|
|
5707
|
+
() => engineRef.current?.invalidateSalvageSeed()
|
|
5708
|
+
);
|
|
4781
5709
|
if (isSpeechTrueCount === 0) interruptFirstAt = 0;
|
|
4782
5710
|
}
|
|
4783
5711
|
}
|
|
@@ -4843,7 +5771,7 @@ function MicButton({
|
|
|
4843
5771
|
engine.onState((s) => {
|
|
4844
5772
|
bus.setUi({ state: s });
|
|
4845
5773
|
if (s === "speech") cancelAutoSend();
|
|
4846
|
-
if (s === "idle") resetIdle();
|
|
5774
|
+
if (s === "idle" && !onceRef.current) resetIdle();
|
|
4847
5775
|
});
|
|
4848
5776
|
engine.onError((key) => {
|
|
4849
5777
|
bus.setUi({ error: t(key) });
|
|
@@ -4869,7 +5797,7 @@ function MicButton({
|
|
|
4869
5797
|
bus.setUi({ levels: next });
|
|
4870
5798
|
});
|
|
4871
5799
|
engine.onPartial((text) => {
|
|
4872
|
-
if (engineRef.current !== engine) return;
|
|
5800
|
+
if (engineRef.current !== engine || onceRef.current) return;
|
|
4873
5801
|
bus.setUi({ partial: text });
|
|
4874
5802
|
if (!text) return;
|
|
4875
5803
|
if (submitInFlightRef.current) {
|
|
@@ -4889,9 +5817,20 @@ function MicButton({
|
|
|
4889
5817
|
}
|
|
4890
5818
|
});
|
|
4891
5819
|
engine.onSegment((text, meta) => {
|
|
5820
|
+
if (onceRef.current) return;
|
|
4892
5821
|
resetIdle();
|
|
4893
5822
|
submitInFlightRef.current = false;
|
|
4894
5823
|
bus.setUi({ partial: "" });
|
|
5824
|
+
if (holdReleaseExitRef.current && meta?.force) {
|
|
5825
|
+
clearHoldExit();
|
|
5826
|
+
if (bootNow().autoSend === false) {
|
|
5827
|
+
setTimeout(() => {
|
|
5828
|
+
if (!holdPtrRef.current) void exitModeRef.current("manual");
|
|
5829
|
+
}, 300);
|
|
5830
|
+
} else {
|
|
5831
|
+
beginOnceWait();
|
|
5832
|
+
}
|
|
5833
|
+
}
|
|
4895
5834
|
const actions = actionsRef.current;
|
|
4896
5835
|
const trimmed = text.trim();
|
|
4897
5836
|
if (!trimmed) return;
|
|
@@ -4907,12 +5846,13 @@ function MicButton({
|
|
|
4907
5846
|
}
|
|
4908
5847
|
if (meta?.force) {
|
|
4909
5848
|
cancelAutoSend();
|
|
5849
|
+
if (bootNow().mode === "hold" && bootNow().autoSend === false) return;
|
|
4910
5850
|
submitDraftNow(nextDraft);
|
|
4911
5851
|
return;
|
|
4912
5852
|
}
|
|
4913
5853
|
if (bootNow().mode === "hold") return;
|
|
4914
5854
|
if (bus.ui.playing) return;
|
|
4915
|
-
if (bootNow().autoSend === false) return;
|
|
5855
|
+
if (bootNow().autoSend === false && bootNow().mode !== "once") return;
|
|
4916
5856
|
scheduleAutoSend();
|
|
4917
5857
|
});
|
|
4918
5858
|
bus.setUi({ state: "idle", partial: "", levels: [], botLevels: [], error: null, model: null, ttsNotice: null });
|
|
@@ -4937,7 +5877,24 @@ function MicButton({
|
|
|
4937
5877
|
micReadyRef.current = true;
|
|
4938
5878
|
setLocalMode("on");
|
|
4939
5879
|
resetIdle();
|
|
5880
|
+
if (pendingHoldRef.current) {
|
|
5881
|
+
pendingHoldRef.current = false;
|
|
5882
|
+
if (holdPtrRef.current) {
|
|
5883
|
+
setHolding(true);
|
|
5884
|
+
engineRef.current?.beginHeld();
|
|
5885
|
+
} else if (pendingHoldReleaseRef.current) {
|
|
5886
|
+
pendingHoldReleaseRef.current = false;
|
|
5887
|
+
engineRef.current?.endHeld(true);
|
|
5888
|
+
if (holdReleaseExitRef.current) {
|
|
5889
|
+
clearHoldExit();
|
|
5890
|
+
void exitModeRef.current("manual");
|
|
5891
|
+
}
|
|
5892
|
+
}
|
|
5893
|
+
}
|
|
4940
5894
|
} catch (e) {
|
|
5895
|
+
pendingHoldRef.current = false;
|
|
5896
|
+
pendingHoldReleaseRef.current = false;
|
|
5897
|
+
clearHoldExit();
|
|
4941
5898
|
setLocalMode("off");
|
|
4942
5899
|
const msg = e instanceof DOMException ? e.name === "NotAllowedError" ? t("micDenied") : (
|
|
4943
5900
|
// UX:NotReadableError = 麦克风被占用(其他程序/标签页)——与「不可用」
|
|
@@ -4949,11 +5906,13 @@ function MicButton({
|
|
|
4949
5906
|
if (sid2) void bus.exit(sid2);
|
|
4950
5907
|
}
|
|
4951
5908
|
};
|
|
4952
|
-
const
|
|
5909
|
+
const readingOutside = () => localRef.current === "off" && bus.ui.playing;
|
|
4953
5910
|
const toggle = () => {
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
5911
|
+
if (readingOutside()) {
|
|
5912
|
+
bus.stopReading(!!useSession);
|
|
5913
|
+
return;
|
|
5914
|
+
}
|
|
5915
|
+
if (!takeToggleSlot(toggleHistRef.current, Date.now())) return;
|
|
4957
5916
|
if (localRef.current === "on") void exitModeRef.current("manual");
|
|
4958
5917
|
else if (localRef.current === "off") void enterMode();
|
|
4959
5918
|
};
|
|
@@ -4967,6 +5926,32 @@ function MicButton({
|
|
|
4967
5926
|
(0, import_react3.useEffect)(() => {
|
|
4968
5927
|
sidRef.current = sessionId;
|
|
4969
5928
|
}, [sessionId]);
|
|
5929
|
+
(0, import_react3.useEffect)(() => {
|
|
5930
|
+
const onChanged = () => {
|
|
5931
|
+
void fetchConfig();
|
|
5932
|
+
};
|
|
5933
|
+
window.addEventListener("dshvm-settings-changed", onChanged);
|
|
5934
|
+
return () => window.removeEventListener("dshvm-settings-changed", onChanged);
|
|
5935
|
+
}, []);
|
|
5936
|
+
(0, import_react3.useEffect)(() => {
|
|
5937
|
+
const onComposerKey = (e) => {
|
|
5938
|
+
const el = e.target;
|
|
5939
|
+
const editable = el instanceof HTMLElement && (el.tagName === "TEXTAREA" || el.tagName === "INPUT" || el.isContentEditable);
|
|
5940
|
+
if (!editable || e.isComposing) return;
|
|
5941
|
+
if (el.closest("[data-dshvm-settings]")) return;
|
|
5942
|
+
const combo = parseShortcut(bootNow().composerShortcut);
|
|
5943
|
+
if (!combo) return;
|
|
5944
|
+
const key = e.key.toLowerCase();
|
|
5945
|
+
const codeKey = (e.code || "").replace(/^Key/, "").replace(/^Digit/, "").toLowerCase();
|
|
5946
|
+
if (key !== combo.key && codeKey !== combo.key) return;
|
|
5947
|
+
if (e.ctrlKey !== combo.ctrl || e.shiftKey !== combo.shift || e.altKey !== combo.alt || e.metaKey !== combo.meta) return;
|
|
5948
|
+
e.preventDefault();
|
|
5949
|
+
e.stopPropagation();
|
|
5950
|
+
if (!e.repeat) toggleRef.current();
|
|
5951
|
+
};
|
|
5952
|
+
window.addEventListener("keydown", onComposerKey, true);
|
|
5953
|
+
return () => window.removeEventListener("keydown", onComposerKey, true);
|
|
5954
|
+
}, []);
|
|
4970
5955
|
const autoResumeTriedForRef = (0, import_react3.useRef)(null);
|
|
4971
5956
|
const autoResumeHintTimerRef = (0, import_react3.useRef)(null);
|
|
4972
5957
|
(0, import_react3.useEffect)(() => {
|
|
@@ -4996,13 +5981,31 @@ function MicButton({
|
|
|
4996
5981
|
})();
|
|
4997
5982
|
}, [sessionId]);
|
|
4998
5983
|
const runningSel = useSession ? useSession((s) => s === void 0 ? void 0 : s.running) : void 0;
|
|
5984
|
+
const prevRunningRef = (0, import_react3.useRef)(false);
|
|
4999
5985
|
(0, import_react3.useEffect)(() => {
|
|
5000
5986
|
runningRef.current = runningSel === true;
|
|
5987
|
+
if (runningSel === true && !prevRunningRef.current && sessionId) bus.runStarted(sessionId);
|
|
5988
|
+
prevRunningRef.current = runningSel === true;
|
|
5989
|
+
checkOnce();
|
|
5001
5990
|
}, [runningSel]);
|
|
5991
|
+
(0, import_react3.useEffect)(() => bus.subscribe(() => checkOnce()), [bus]);
|
|
5992
|
+
(0, import_react3.useEffect)(() => {
|
|
5993
|
+
if (!sessionId) return;
|
|
5994
|
+
bus.setFocusedSession(sessionId, focusOwner);
|
|
5995
|
+
const onVis = () => {
|
|
5996
|
+
if (document.visibilityState === "visible") bus.setFocusedSession(sessionId, focusOwner);
|
|
5997
|
+
};
|
|
5998
|
+
document.addEventListener("visibilitychange", onVis);
|
|
5999
|
+
return () => {
|
|
6000
|
+
document.removeEventListener("visibilitychange", onVis);
|
|
6001
|
+
bus.setFocusedSession(null, focusOwner);
|
|
6002
|
+
};
|
|
6003
|
+
}, [bus, sessionId]);
|
|
5002
6004
|
(0, import_react3.useEffect)(() => {
|
|
5003
6005
|
mountedRef.current = true;
|
|
5004
6006
|
return () => {
|
|
5005
6007
|
mountedRef.current = false;
|
|
6008
|
+
clearOnce();
|
|
5006
6009
|
clearIdle();
|
|
5007
6010
|
cancelPendingSubmit();
|
|
5008
6011
|
cancelAutoSend();
|
|
@@ -5060,7 +6063,7 @@ function MicButton({
|
|
|
5060
6063
|
if (combo && !e.repeat && (e.key.toLowerCase() === combo.key || codeKey === combo.key) && e.ctrlKey === combo.ctrl && e.shiftKey === combo.shift && e.altKey === combo.alt && e.metaKey === combo.meta) {
|
|
5061
6064
|
const el = e.target;
|
|
5062
6065
|
const editable = el instanceof HTMLElement && (el.tagName === "TEXTAREA" || el.tagName === "INPUT" || el.isContentEditable);
|
|
5063
|
-
if (!editable &&
|
|
6066
|
+
if (!e.isComposing && !(editable && isEditingShortcut(combo, IS_MAC))) {
|
|
5064
6067
|
e.preventDefault();
|
|
5065
6068
|
cancelCtrl();
|
|
5066
6069
|
toggleRef.current();
|
|
@@ -5068,7 +6071,7 @@ function MicButton({
|
|
|
5068
6071
|
return;
|
|
5069
6072
|
}
|
|
5070
6073
|
const eng = engineRef.current;
|
|
5071
|
-
if (e.key === "Control" && !e.shiftKey && !e.altKey && !e.metaKey && !e.repeat && eng) {
|
|
6074
|
+
if (e.key === "Control" && !e.shiftKey && !e.altKey && !e.metaKey && !e.repeat && eng && !onceRef.current) {
|
|
5072
6075
|
ctrlHoldStart = Date.now();
|
|
5073
6076
|
otherKeyDuringCtrl = false;
|
|
5074
6077
|
if (bootNow().mode === "hold") {
|
|
@@ -5140,7 +6143,7 @@ function MicButton({
|
|
|
5140
6143
|
};
|
|
5141
6144
|
const onVisibility = () => {
|
|
5142
6145
|
if (document.hidden) {
|
|
5143
|
-
if (localRef.current === "on" && engineRef.current) {
|
|
6146
|
+
if (localRef.current === "on" && engineRef.current && !onceRef.current) {
|
|
5144
6147
|
if (bootNow().mode === "hold") {
|
|
5145
6148
|
engineRef.current?.endHeld(true);
|
|
5146
6149
|
holdCtrlRef.current = false;
|
|
@@ -5188,7 +6191,9 @@ function MicButton({
|
|
|
5188
6191
|
const phaseRef = (0, import_react3.useRef)("");
|
|
5189
6192
|
phaseRef.current = livePhase;
|
|
5190
6193
|
const [holding, setHolding] = (0, import_react3.useState)(false);
|
|
5191
|
-
const
|
|
6194
|
+
const reading = local === "off" && bus.ui.playing;
|
|
6195
|
+
const showTurn = onceWaiting || bootNow().showStatusBar === false && bus.ui.state !== "speech" && (bus.ui.playing || bus.ui.turn === "agent-speaking");
|
|
6196
|
+
const label = on && showTurn ? bus.ui.playing ? t("reading") : t("thinking") : reading ? t("stopReading") : on ? busy ? (
|
|
5192
6197
|
// UX:loading-model 是加载/下载模型而非识别——「识别中…」与状态不符。
|
|
5193
6198
|
bus.ui.state === "loading-model" ? t("buttonLoading") : t("recognizing")
|
|
5194
6199
|
) : holdMode ? holding ? t("releaseToSend") : t("holdToTalk") : bus.ui.state === "wake" ? t("sayWake").replace("{wake}", bus.ui.wakeWord || t("wakeWord")) : (
|
|
@@ -5196,8 +6201,30 @@ function MicButton({
|
|
|
5196
6201
|
t("buttonListening")
|
|
5197
6202
|
) : local === "pending" ? t("entering") : t("voiceBtn");
|
|
5198
6203
|
const holdPtrRef = (0, import_react3.useRef)(null);
|
|
6204
|
+
const auxClickRef = (0, import_react3.useRef)(false);
|
|
5199
6205
|
const toggleHoldRef = (0, import_react3.useRef)(false);
|
|
5200
6206
|
const suppressClickUntilRef = (0, import_react3.useRef)(0);
|
|
6207
|
+
const pendingHoldRef = (0, import_react3.useRef)(false);
|
|
6208
|
+
const pendingHoldReleaseRef = (0, import_react3.useRef)(false);
|
|
6209
|
+
const holdReleaseExitRef = (0, import_react3.useRef)(false);
|
|
6210
|
+
const pressFromOffRef = (0, import_react3.useRef)(false);
|
|
6211
|
+
const holdExitFallbackRef = (0, import_react3.useRef)(null);
|
|
6212
|
+
function clearHoldExit() {
|
|
6213
|
+
holdReleaseExitRef.current = false;
|
|
6214
|
+
if (holdExitFallbackRef.current) clearTimeout(holdExitFallbackRef.current);
|
|
6215
|
+
holdExitFallbackRef.current = null;
|
|
6216
|
+
}
|
|
6217
|
+
function armHoldExit() {
|
|
6218
|
+
clearHoldExit();
|
|
6219
|
+
holdReleaseExitRef.current = true;
|
|
6220
|
+
holdExitFallbackRef.current = setTimeout(() => {
|
|
6221
|
+
holdExitFallbackRef.current = null;
|
|
6222
|
+
if (holdReleaseExitRef.current && !holdPtrRef.current && !onceRef.current) {
|
|
6223
|
+
holdReleaseExitRef.current = false;
|
|
6224
|
+
void exitModeRef.current("manual");
|
|
6225
|
+
}
|
|
6226
|
+
}, 25e3);
|
|
6227
|
+
}
|
|
5201
6228
|
const breakTimerRef = (0, import_react3.useRef)(null);
|
|
5202
6229
|
const breakDotsTimerRef = (0, import_react3.useRef)(null);
|
|
5203
6230
|
const clearBreakTimer = () => {
|
|
@@ -5252,10 +6279,24 @@ function MicButton({
|
|
|
5252
6279
|
return () => el.removeEventListener("touchstart", onTouchStart);
|
|
5253
6280
|
}, []);
|
|
5254
6281
|
const onPointerDown = (e) => {
|
|
6282
|
+
auxClickRef.current = auxClickPending(e.button, { mac: IS_MAC, ctrlKey: e.ctrlKey });
|
|
6283
|
+
if (!isPrimaryPress(e.button, { mac: IS_MAC, ctrlKey: e.ctrlKey })) return;
|
|
5255
6284
|
lockSelection();
|
|
5256
|
-
holdPtrRef.current = { t: Date.now(), y: e.clientY, id: e.pointerId };
|
|
6285
|
+
holdPtrRef.current = { t: Date.now(), y: e.clientY, id: e.pointerId, button: e.button };
|
|
5257
6286
|
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
5258
6287
|
if (bootNow().mode === "hold") {
|
|
6288
|
+
pressFromOffRef.current = localRef.current === "off";
|
|
6289
|
+
clearHoldExit();
|
|
6290
|
+
if (localRef.current === "off" && !readingOutside()) {
|
|
6291
|
+
pendingHoldRef.current = true;
|
|
6292
|
+
pendingHoldReleaseRef.current = false;
|
|
6293
|
+
void enterMode().finally(() => {
|
|
6294
|
+
pendingHoldRef.current = false;
|
|
6295
|
+
pendingHoldReleaseRef.current = false;
|
|
6296
|
+
if (localRef.current !== "on") clearHoldExit();
|
|
6297
|
+
});
|
|
6298
|
+
return;
|
|
6299
|
+
}
|
|
5259
6300
|
if (localRef.current === "on") {
|
|
5260
6301
|
setHolding(true);
|
|
5261
6302
|
const eng = engineRef.current;
|
|
@@ -5267,7 +6308,7 @@ function MicButton({
|
|
|
5267
6308
|
}, 250);
|
|
5268
6309
|
}
|
|
5269
6310
|
}
|
|
5270
|
-
} else if (localRef.current === "on" && bus.ui.playing) {
|
|
6311
|
+
} else if (localRef.current === "on" && bus.ui.playing && !onceRef.current) {
|
|
5271
6312
|
toggleHoldRef.current = true;
|
|
5272
6313
|
setHolding(true);
|
|
5273
6314
|
const eng = engineRef.current;
|
|
@@ -5293,11 +6334,21 @@ function MicButton({
|
|
|
5293
6334
|
};
|
|
5294
6335
|
const onPointerUp = (e) => {
|
|
5295
6336
|
const p = holdPtrRef.current;
|
|
6337
|
+
const action = pointerUpAction(p, { id: e.pointerId, button: e.button });
|
|
6338
|
+
if (action === "ignore") return;
|
|
5296
6339
|
holdPtrRef.current = null;
|
|
5297
6340
|
clearBreakTimer();
|
|
6341
|
+
if (action === "unarmed" || !p) return;
|
|
5298
6342
|
setHolding(false);
|
|
5299
|
-
if (!p || p.id !== e.pointerId) return;
|
|
5300
6343
|
const ms = Date.now() - p.t;
|
|
6344
|
+
if (pendingHoldRef.current) {
|
|
6345
|
+
pendingHoldReleaseRef.current = true;
|
|
6346
|
+
if (ms >= 250) {
|
|
6347
|
+
armHoldExit();
|
|
6348
|
+
suppressClickUntilRef.current = Date.now() + 500;
|
|
6349
|
+
}
|
|
6350
|
+
return;
|
|
6351
|
+
}
|
|
5301
6352
|
if (bootNow().mode !== "hold") {
|
|
5302
6353
|
if (toggleHoldRef.current) {
|
|
5303
6354
|
toggleHoldRef.current = false;
|
|
@@ -5311,9 +6362,15 @@ function MicButton({
|
|
|
5311
6362
|
return;
|
|
5312
6363
|
}
|
|
5313
6364
|
if (ms < 250) {
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
6365
|
+
if (readingOutside()) {
|
|
6366
|
+
bus.stopReading(!!useSession);
|
|
6367
|
+
return;
|
|
6368
|
+
}
|
|
6369
|
+
if (localRef.current === "on" && pressFromOffRef.current) {
|
|
6370
|
+
engineRef.current?.endHeld(true);
|
|
6371
|
+
return;
|
|
6372
|
+
}
|
|
6373
|
+
if (!takeToggleSlot(toggleHistRef.current, Date.now())) return;
|
|
5317
6374
|
if (localRef.current === "on") {
|
|
5318
6375
|
engineRef.current?.endHeld(true);
|
|
5319
6376
|
void exitModeRef.current("manual");
|
|
@@ -5322,70 +6379,131 @@ function MicButton({
|
|
|
5322
6379
|
}
|
|
5323
6380
|
return;
|
|
5324
6381
|
}
|
|
5325
|
-
if (localRef.current === "on")
|
|
6382
|
+
if (localRef.current === "on") {
|
|
6383
|
+
engineRef.current?.endHeld(false);
|
|
6384
|
+
armHoldExit();
|
|
6385
|
+
suppressClickUntilRef.current = Date.now() + 500;
|
|
6386
|
+
}
|
|
5326
6387
|
};
|
|
5327
6388
|
const onPointerCancel = () => {
|
|
6389
|
+
if (!holdPtrRef.current && !toggleHoldRef.current) return;
|
|
5328
6390
|
holdPtrRef.current = null;
|
|
5329
6391
|
toggleHoldRef.current = false;
|
|
5330
6392
|
clearBreakTimer();
|
|
5331
6393
|
setHolding(false);
|
|
5332
6394
|
engineRef.current?.endHeld(true);
|
|
5333
6395
|
};
|
|
5334
|
-
const
|
|
6396
|
+
const statusBarShown = bootNow().showStatusBar !== false;
|
|
6397
|
+
const micHint = bus.activeSessionId !== sessionId ? bus.ui.error ?? bus.ui.notice ?? "" : statusBarShown ? "" : bus.ui.error ?? (bus.ui.sseDown ? t("sseReconnect") : null) ?? bus.ui.notice ?? (bus.ui.idleWarn ? t("idleWarn30s") : null) ?? bus.ui.ttsNotice ?? "";
|
|
6398
|
+
const visual = holding ? "holding" : bus.ui.playing ? "reading" : on && onceEnding ? "ending" : on && onceWaiting ? "waiting" : on ? holdMode ? "hold" : "on" : local === "pending" ? "pending" : "off";
|
|
6399
|
+
const eqKind = visual === "reading" ? "out" : visual === "on" || visual === "holding" ? "in" : null;
|
|
6400
|
+
(0, import_react3.useEffect)(() => {
|
|
6401
|
+
const el = btnRef.current;
|
|
6402
|
+
if (!el || !eqKind) return;
|
|
6403
|
+
const bars = Array.from(el.querySelectorAll(".dshvm-eq i"));
|
|
6404
|
+
const base = eqKind === "out" ? [6, 10, 14, 10, 6] : [6, 12, 8];
|
|
6405
|
+
const paint = (lv) => bars.forEach((b, i) => b.style.height = `${Math.max(3, base[i] * (0.35 + 0.65 * lv)).toFixed(1)}px`);
|
|
6406
|
+
const mq = typeof matchMedia === "function" ? matchMedia("(prefers-reduced-motion: reduce)") : null;
|
|
6407
|
+
let smooth = 0;
|
|
6408
|
+
let raf = 0;
|
|
6409
|
+
const tick = () => {
|
|
6410
|
+
const raw = eqKind === "out" ? bus.playbackLevel() : bus.ui.levels[bus.ui.levels.length - 1] ?? 0;
|
|
6411
|
+
smooth = Math.max(Math.min(1, Math.max(0, raw)), smooth * 0.82);
|
|
6412
|
+
paint(smooth);
|
|
6413
|
+
raf = requestAnimationFrame(tick);
|
|
6414
|
+
};
|
|
6415
|
+
const apply2 = () => {
|
|
6416
|
+
if (eqPaintMode(mq?.matches === true) === "static-full") {
|
|
6417
|
+
if (raf) {
|
|
6418
|
+
cancelAnimationFrame(raf);
|
|
6419
|
+
raf = 0;
|
|
6420
|
+
}
|
|
6421
|
+
paint(1);
|
|
6422
|
+
return;
|
|
6423
|
+
}
|
|
6424
|
+
if (!raf) {
|
|
6425
|
+
smooth = 0;
|
|
6426
|
+
tick();
|
|
6427
|
+
}
|
|
6428
|
+
};
|
|
6429
|
+
apply2();
|
|
6430
|
+
let detach = null;
|
|
6431
|
+
if (mq && typeof mq.addEventListener === "function") {
|
|
6432
|
+
mq.addEventListener("change", apply2);
|
|
6433
|
+
detach = () => mq.removeEventListener("change", apply2);
|
|
6434
|
+
} else if (mq && typeof mq.addListener === "function") {
|
|
6435
|
+
mq.addListener(apply2);
|
|
6436
|
+
detach = () => mq.removeListener(apply2);
|
|
6437
|
+
}
|
|
6438
|
+
return () => {
|
|
6439
|
+
if (raf) cancelAnimationFrame(raf);
|
|
6440
|
+
detach?.();
|
|
6441
|
+
};
|
|
6442
|
+
}, [eqKind, bus]);
|
|
6443
|
+
const showTimer = on && !statusBarShown && !onceWaiting;
|
|
6444
|
+
const [elapsed, setElapsed] = (0, import_react3.useState)(0);
|
|
6445
|
+
(0, import_react3.useEffect)(() => {
|
|
6446
|
+
setElapsed(0);
|
|
6447
|
+
if (!showTimer) return;
|
|
6448
|
+
const id = setInterval(() => setElapsed((n) => n + 1), 1e3);
|
|
6449
|
+
return () => clearInterval(id);
|
|
6450
|
+
}, [showTimer]);
|
|
6451
|
+
const [menuOpen, setMenuOpen] = (0, import_react3.useState)(false);
|
|
6452
|
+
const closeMenu = React.useCallback((refocus) => {
|
|
6453
|
+
setMenuOpen(false);
|
|
6454
|
+
if (refocus) btnRef.current?.focus();
|
|
6455
|
+
}, []);
|
|
6456
|
+
const title = bus.ui.error ? String(bus.ui.error) : reading ? t("stopReading") : on ? holdMode ? t("titleHold") : t("titleToggle") : t("titleEnter");
|
|
5335
6457
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
5336
6458
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
5337
6459
|
"button",
|
|
5338
6460
|
{
|
|
6461
|
+
type: "button",
|
|
6462
|
+
className: "dshvm-mic",
|
|
6463
|
+
"data-state": visual,
|
|
5339
6464
|
onClick: (e) => {
|
|
6465
|
+
if (isAuxClickToIgnore(auxClickRef.current, e.detail)) {
|
|
6466
|
+
auxClickRef.current = false;
|
|
6467
|
+
return;
|
|
6468
|
+
}
|
|
5340
6469
|
if (Date.now() < suppressClickUntilRef.current) return;
|
|
5341
|
-
if (
|
|
6470
|
+
if (localRef.current === "on" && (bus.ui.playing || onceRef.current)) {
|
|
6471
|
+
bus.stopReading(!!useSession);
|
|
6472
|
+
void exitModeRef.current("manual");
|
|
6473
|
+
return;
|
|
6474
|
+
}
|
|
6475
|
+
if (holdMode && !readingOutside()) {
|
|
5342
6476
|
if (e.detail !== 0) return;
|
|
5343
6477
|
}
|
|
5344
6478
|
toggle();
|
|
5345
6479
|
},
|
|
6480
|
+
onMouseDown: (e) => {
|
|
6481
|
+
e.preventDefault();
|
|
6482
|
+
},
|
|
5346
6483
|
onPointerDown,
|
|
5347
6484
|
onPointerMove,
|
|
5348
6485
|
onPointerUp,
|
|
5349
6486
|
onPointerCancel,
|
|
5350
|
-
onContextMenu: (e) =>
|
|
6487
|
+
onContextMenu: (e) => {
|
|
6488
|
+
e.preventDefault();
|
|
6489
|
+
const pt = e.nativeEvent.pointerType;
|
|
6490
|
+
if (scope && pt !== "touch" && pt !== "pen") setMenuOpen(true);
|
|
6491
|
+
},
|
|
5351
6492
|
ref: btnRef,
|
|
5352
6493
|
"data-dshvm": "mic",
|
|
5353
|
-
"aria-label": on ? t("ariaActive") : t("ariaEnter"),
|
|
6494
|
+
"aria-label": reading ? t("stopReading") : on ? `${t("ariaActive")} \xB7 ${label}` : local === "pending" ? label : t("ariaEnter"),
|
|
5354
6495
|
"aria-pressed": on,
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
background: holding ? "rgba(248, 81, 73, 0.2)" : on ? holdMode ? "rgba(88, 166, 255, 0.16)" : "rgba(63, 185, 80, 0.16)" : local === "pending" ? "rgba(88, 166, 255, 0.14)" : "rgba(139, 148, 158, 0.08)",
|
|
5359
|
-
cursor: "pointer",
|
|
5360
|
-
padding: "5px 10px",
|
|
5361
|
-
borderRadius: 8,
|
|
5362
|
-
display: "flex",
|
|
5363
|
-
alignItems: "center",
|
|
5364
|
-
gap: 6,
|
|
5365
|
-
fontSize: 12,
|
|
5366
|
-
fontFamily: "system-ui, sans-serif",
|
|
5367
|
-
color: holding ? "#f85149" : on ? holdMode ? "#58a6ff" : "#2ea043" : local === "pending" ? "#58a6ff" : "#8b949e",
|
|
5368
|
-
// 批 H 任务 3:toggle 模式「语音中」绿字加深(#3fb950 → #2ea043)+ fontWeight:600 双保险,
|
|
5369
|
-
// 浅色主题下与浅绿底 (rgba 63,185,80,.16) 对比度 ≥ 4.5:1(WCAG AA 文本级)。
|
|
5370
|
-
fontWeight: on && !holdMode ? 600 : void 0,
|
|
5371
|
-
transition: "background 0.15s ease, color 0.2s ease, border-color 0.15s ease",
|
|
5372
|
-
touchAction: "none",
|
|
5373
|
-
// 触摸设备上让 pointer 事件独占(滑出取消可用)
|
|
5374
|
-
userSelect: "none",
|
|
5375
|
-
WebkitUserSelect: "none",
|
|
5376
|
-
// iOS Safari 前缀,防长按选中文字
|
|
5377
|
-
WebkitTouchCallout: "none"
|
|
5378
|
-
// iOS 长按弹出「拷贝/选择」菜单
|
|
5379
|
-
},
|
|
6496
|
+
"aria-haspopup": scope ? "menu" : void 0,
|
|
6497
|
+
"aria-expanded": scope ? menuOpen : void 0,
|
|
6498
|
+
title,
|
|
5380
6499
|
children: [
|
|
5381
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
),
|
|
6500
|
+
visual !== "waiting" && bus.ui.isSpeech === true && on && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dshvm-mic-dot", "data-kind": "vad", title: t("vadDetected") }),
|
|
6501
|
+
bus.ui.error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dshvm-mic-dot", "data-kind": "error" }),
|
|
6502
|
+
visual === "waiting" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { viewBox: "0 0 24 24", width: 16, height: 16, "aria-hidden": "true", className: "dshvm-spin", children: [
|
|
6503
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: 12, cy: 12, r: 8, fill: "none", stroke: "currentColor", strokeWidth: 2, opacity: 0.25 }),
|
|
6504
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 4a8 8 0 0 1 8 8", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round" })
|
|
6505
|
+
] }) : visual === "ending" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { viewBox: "0 0 24 24", width: 16, height: 16, "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M5.5 12.5l4.2 4.2 8.8-8.8", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round" }) }) : eqKind ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: eqKind === "out" ? "dshvm-eq dshvm-eq-out" : "dshvm-eq", "aria-hidden": "true", children: (eqKind === "out" ? [6, 10, 14, 10, 6] : [6, 12, 8]).map((h, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("i", { style: { height: h } }, i)) }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { viewBox: "0 0 24 24", width: 16, height: 16, "aria-hidden": "true", children: [
|
|
6506
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { fill: "currentColor", d: "M12 14a3 3 0 0 0 3-3V5a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3Z" }),
|
|
5389
6507
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
5390
6508
|
"path",
|
|
5391
6509
|
{
|
|
@@ -5394,10 +6512,15 @@ function MicButton({
|
|
|
5394
6512
|
}
|
|
5395
6513
|
)
|
|
5396
6514
|
] }),
|
|
5397
|
-
|
|
6515
|
+
showTimer && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "dshvm-mic-timer", "aria-hidden": "true", children: [
|
|
6516
|
+
String(Math.floor(elapsed / 60)).padStart(2, "0"),
|
|
6517
|
+
":",
|
|
6518
|
+
String(elapsed % 60).padStart(2, "0")
|
|
6519
|
+
] })
|
|
5398
6520
|
]
|
|
5399
6521
|
}
|
|
5400
6522
|
),
|
|
6523
|
+
menuOpen && scope && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MicMenu, { scope, anchor: btnRef.current, onClose: closeMenu }),
|
|
5401
6524
|
micHint && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
5402
6525
|
"span",
|
|
5403
6526
|
{
|
|
@@ -5407,7 +6530,7 @@ function MicButton({
|
|
|
5407
6530
|
title: micHint,
|
|
5408
6531
|
style: {
|
|
5409
6532
|
fontSize: 11,
|
|
5410
|
-
color: "#f85149",
|
|
6533
|
+
color: "var(--dsw-alias-state-error-primary, #f85149)",
|
|
5411
6534
|
maxWidth: 240,
|
|
5412
6535
|
overflow: "hidden",
|
|
5413
6536
|
textOverflow: "ellipsis",
|
|
@@ -5462,7 +6585,7 @@ function VoiceStatusBar({ bus, sessionId }) {
|
|
|
5462
6585
|
return () => clearInterval(id);
|
|
5463
6586
|
}, [b.ui.state]);
|
|
5464
6587
|
const isActive = b.active === sessionId;
|
|
5465
|
-
if (!isActive) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, {});
|
|
6588
|
+
if (!isActive || b.ui.boot?.showStatusBar === false) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, {});
|
|
5466
6589
|
const stateText = b.ui.state === "loading-model" ? t("loadingModel") : b.ui.state === "transcribing" ? transcribingSec >= 2 ? t("recognizingSec").replace("{sec}", String(transcribingSec)) : t("recognizing") : b.ui.state === "wake" ? t("sayWake").replace("{wake}", b.ui.wakeWord || t("wakeWord")) : b.ui.state === "speech" ? b.ui.mode === "hold" ? t("holdDots") : t("listening") : b.ui.playing ? t("reading") : b.ui.turn === "agent-speaking" ? t("thinking") : b.ui.mode === "hold" ? t("barHold") : t("barListening");
|
|
5467
6590
|
const bars = Array.from({ length: WAVE_BARS }, (_, i) => b.ui.levels[i] ?? 0);
|
|
5468
6591
|
const botBars = Array.from({ length: WAVE_BARS }, (_, i) => b.ui.botLevels[i] ?? 0);
|
|
@@ -5685,7 +6808,7 @@ function VoiceOverlay({ bus }) {
|
|
|
5685
6808
|
(0, import_react3.useEffect)(() => {
|
|
5686
6809
|
return bus.subscribe(setB);
|
|
5687
6810
|
}, [bus]);
|
|
5688
|
-
if (!b.ui.playing) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, {});
|
|
6811
|
+
if (!b.ui.playing || b.ui.boot?.showCaptions === false) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, {});
|
|
5689
6812
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
5690
6813
|
"div",
|
|
5691
6814
|
{
|