dsh-voice-mode 0.7.27 → 0.7.29
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 +19 -14
- package/README.md +21 -16
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/lib/client.js +948 -102
- package/lib/index.js +659 -214
- package/lib/msedge-tts.cjs +11 -5
- package/package.json +4 -3
package/lib/client.js
CHANGED
|
@@ -496,6 +496,10 @@ function createAsrEngine(config, sessionId) {
|
|
|
496
496
|
let partialInFlight = false;
|
|
497
497
|
let resetGate = Promise.resolve();
|
|
498
498
|
let segmentEpoch = 0;
|
|
499
|
+
let discardGen = 0;
|
|
500
|
+
let finalizeSeq = 0;
|
|
501
|
+
let nextEmitSeq = 1;
|
|
502
|
+
const pendingFinals = /* @__PURE__ */ new Map();
|
|
499
503
|
let wakeSilenceMs = 0;
|
|
500
504
|
let wakeConsumed = false;
|
|
501
505
|
let forcePending = false;
|
|
@@ -510,6 +514,8 @@ function createAsrEngine(config, sessionId) {
|
|
|
510
514
|
let preRollStartWall = 0;
|
|
511
515
|
let preRollSeedWall = null;
|
|
512
516
|
let wasPlaying = false;
|
|
517
|
+
let rawPlayingSinceWall = 0;
|
|
518
|
+
let gateQueryScope = false;
|
|
513
519
|
let partialFailStreak = 0;
|
|
514
520
|
let detectFailStreak = 0;
|
|
515
521
|
let salvagedSegment = false;
|
|
@@ -538,6 +544,18 @@ function createAsrEngine(config, sessionId) {
|
|
|
538
544
|
}
|
|
539
545
|
}
|
|
540
546
|
};
|
|
547
|
+
const flushOrderedFinals = () => {
|
|
548
|
+
while (pendingFinals.has(nextEmitSeq)) {
|
|
549
|
+
const item = pendingFinals.get(nextEmitSeq);
|
|
550
|
+
pendingFinals.delete(nextEmitSeq);
|
|
551
|
+
nextEmitSeq++;
|
|
552
|
+
if (item) emit(transcriptListeners, item.text, item.meta);
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
const settleFinal = (seq, item) => {
|
|
556
|
+
pendingFinals.set(seq, item);
|
|
557
|
+
flushOrderedFinals();
|
|
558
|
+
};
|
|
541
559
|
const resetFailStreaks = () => {
|
|
542
560
|
partialFailStreak = 0;
|
|
543
561
|
detectFailStreak = 0;
|
|
@@ -560,6 +578,14 @@ function createAsrEngine(config, sessionId) {
|
|
|
560
578
|
return out;
|
|
561
579
|
};
|
|
562
580
|
const sliceSince = (from) => sliceChunks(segment, from);
|
|
581
|
+
const deliverIsSpeech = (speech) => {
|
|
582
|
+
gateQueryScope = true;
|
|
583
|
+
try {
|
|
584
|
+
config.onIsSpeech?.(speech);
|
|
585
|
+
} finally {
|
|
586
|
+
gateQueryScope = false;
|
|
587
|
+
}
|
|
588
|
+
};
|
|
563
589
|
const requestPartial = async () => {
|
|
564
590
|
if (partialInFlight || segment.length === 0) return;
|
|
565
591
|
await resetGate;
|
|
@@ -598,6 +624,10 @@ function createAsrEngine(config, sessionId) {
|
|
|
598
624
|
}, 5e3);
|
|
599
625
|
});
|
|
600
626
|
res = retry;
|
|
627
|
+
if (res.status === 202) {
|
|
628
|
+
if (epoch === segmentEpoch && active && state !== "wake") setState("loading-model");
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
601
631
|
}
|
|
602
632
|
if (res.status === 403 && config.onSessionExpired) {
|
|
603
633
|
const recovered = await config.onSessionExpired();
|
|
@@ -624,6 +654,7 @@ function createAsrEngine(config, sessionId) {
|
|
|
624
654
|
if (epoch !== segmentEpoch) return;
|
|
625
655
|
if (state === "wake" && wakeEnabled) {
|
|
626
656
|
uploadedSamples = Math.max(uploadedSamples, from + samples.length);
|
|
657
|
+
partialFailStreak = 0;
|
|
627
658
|
emit(partialListeners, out.text ?? "");
|
|
628
659
|
if (matchWakeWord(out.text ?? "", wakeWord)) {
|
|
629
660
|
wakeConsumed = true;
|
|
@@ -633,7 +664,7 @@ function createAsrEngine(config, sessionId) {
|
|
|
633
664
|
}
|
|
634
665
|
return;
|
|
635
666
|
}
|
|
636
|
-
if (out.isSpeech !== void 0)
|
|
667
|
+
if (out.isSpeech !== void 0) deliverIsSpeech(out.isSpeech);
|
|
637
668
|
if (state === "loading-model") setState("speech");
|
|
638
669
|
uploadedSamples = Math.max(uploadedSamples, from + samples.length);
|
|
639
670
|
partialFailStreak = 0;
|
|
@@ -683,8 +714,11 @@ function createAsrEngine(config, sessionId) {
|
|
|
683
714
|
if (!res.ok) return;
|
|
684
715
|
const out = await res.json();
|
|
685
716
|
if (epoch !== segmentEpoch || gen !== detectGeneration) return;
|
|
686
|
-
|
|
687
|
-
if (out.isSpeech === true && preRollSeedWall === null
|
|
717
|
+
const rawNow = config.isPlayingRaw ? config.isPlayingRaw() : config.isPlaying?.() ?? false;
|
|
718
|
+
if (out.isSpeech === true && preRollSeedWall === null && rawNow && reqBodyStartWall >= rawPlayingSinceWall) {
|
|
719
|
+
preRollSeedWall = reqBodyStartWall - 250;
|
|
720
|
+
}
|
|
721
|
+
if (out.isSpeech !== void 0) deliverIsSpeech(out.isSpeech);
|
|
688
722
|
detectFailStreak = 0;
|
|
689
723
|
detectSent += samples.length;
|
|
690
724
|
while (detectChunks.length > 0 && detectSent >= detectChunks[0].length) {
|
|
@@ -731,6 +765,7 @@ function createAsrEngine(config, sessionId) {
|
|
|
731
765
|
partialFailStreak = 0;
|
|
732
766
|
detectFailStreak = 0;
|
|
733
767
|
segmentEpoch++;
|
|
768
|
+
discardGen++;
|
|
734
769
|
segment = [];
|
|
735
770
|
segmentMs = 0;
|
|
736
771
|
speechMs = 0;
|
|
@@ -756,6 +791,14 @@ function createAsrEngine(config, sessionId) {
|
|
|
756
791
|
const recoverySegment = segment;
|
|
757
792
|
const epochSnapshot = segmentEpoch;
|
|
758
793
|
segmentEpoch++;
|
|
794
|
+
const discardSnapshot = discardGen;
|
|
795
|
+
const mySeq = ++finalizeSeq;
|
|
796
|
+
let settled = false;
|
|
797
|
+
const settle = (item) => {
|
|
798
|
+
if (settled) return;
|
|
799
|
+
settled = true;
|
|
800
|
+
settleFinal(mySeq, item);
|
|
801
|
+
};
|
|
759
802
|
const meta = { force: forcePending };
|
|
760
803
|
const consumedWake = wakeConsumed;
|
|
761
804
|
wakeConsumed = false;
|
|
@@ -778,7 +821,10 @@ function createAsrEngine(config, sessionId) {
|
|
|
778
821
|
const restoreState = () => setState(active ? speechActive || holdActive ? "speech" : wakeEnabled ? "wake" : "listening" : "idle");
|
|
779
822
|
for (let attempt = 0; attempt < MAX_FINAL_ATTEMPTS; attempt++) {
|
|
780
823
|
if (attempt > 0) {
|
|
781
|
-
if (
|
|
824
|
+
if (discardGen !== discardSnapshot) {
|
|
825
|
+
settle(null);
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
782
828
|
await new Promise((r) => setTimeout(r, 500 * attempt));
|
|
783
829
|
}
|
|
784
830
|
const useFull = attempt > 0;
|
|
@@ -822,8 +868,16 @@ function createAsrEngine(config, sessionId) {
|
|
|
822
868
|
continue;
|
|
823
869
|
}
|
|
824
870
|
if (res.status === 403 && config.onSessionExpired) {
|
|
825
|
-
|
|
826
|
-
|
|
871
|
+
let expireTimer = null;
|
|
872
|
+
const recovered = await Promise.race([
|
|
873
|
+
config.onSessionExpired(),
|
|
874
|
+
new Promise((resolve) => {
|
|
875
|
+
expireTimer = setTimeout(() => resolve(false), 5e3);
|
|
876
|
+
})
|
|
877
|
+
]).finally(() => {
|
|
878
|
+
if (expireTimer) clearTimeout(expireTimer);
|
|
879
|
+
}).catch(() => false);
|
|
880
|
+
if (recovered && discardGen === discardSnapshot) {
|
|
827
881
|
try {
|
|
828
882
|
res = await fetch(asrUrl(true, 0, epochSnapshot), {
|
|
829
883
|
signal: AbortSignal.timeout(25e3),
|
|
@@ -847,7 +901,10 @@ function createAsrEngine(config, sessionId) {
|
|
|
847
901
|
if (attempt === MAX_FINAL_ATTEMPTS - 1) console.warn("[dsh-voice-mode] finalize response is not JSON (retries exhausted)");
|
|
848
902
|
continue;
|
|
849
903
|
}
|
|
850
|
-
if (
|
|
904
|
+
if (discardGen !== discardSnapshot) {
|
|
905
|
+
settle(null);
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
851
908
|
resetFailStreaks();
|
|
852
909
|
restoreState();
|
|
853
910
|
const rawText = out.text ?? "";
|
|
@@ -856,17 +913,25 @@ function createAsrEngine(config, sessionId) {
|
|
|
856
913
|
if ((wasSalvaged || wasYielded) && matchBackchannel(finalText)) {
|
|
857
914
|
emit(noticeListeners, "backchannelDropped");
|
|
858
915
|
if (active && wakeEnabled) setState("listening");
|
|
916
|
+
settle(null);
|
|
859
917
|
return;
|
|
860
918
|
}
|
|
861
|
-
|
|
862
|
-
} else
|
|
863
|
-
|
|
919
|
+
settle({ text: finalText, meta });
|
|
920
|
+
} else {
|
|
921
|
+
settle(null);
|
|
922
|
+
if (consumedWake && active && !speechActive && !holdActive) {
|
|
923
|
+
setState("listening");
|
|
924
|
+
}
|
|
864
925
|
}
|
|
865
926
|
return;
|
|
866
927
|
}
|
|
867
928
|
restoreState();
|
|
929
|
+
settle(null);
|
|
868
930
|
emitError("recognitionFail");
|
|
869
|
-
})()
|
|
931
|
+
})().catch((err) => {
|
|
932
|
+
console.warn(`[dsh-voice-mode] finalize unexpected error (seq=${mySeq}, settled as no-emit)`, err);
|
|
933
|
+
settle(null);
|
|
934
|
+
});
|
|
870
935
|
};
|
|
871
936
|
let latestResidualRms = 0;
|
|
872
937
|
let echoFloorRms = 0;
|
|
@@ -883,8 +948,20 @@ function createAsrEngine(config, sessionId) {
|
|
|
883
948
|
data = echo.process(data, ref);
|
|
884
949
|
}
|
|
885
950
|
let sum = 0;
|
|
886
|
-
|
|
887
|
-
|
|
951
|
+
let nonFinite = 0;
|
|
952
|
+
for (let i = 0; i < data.length; i++) {
|
|
953
|
+
const v = data[i];
|
|
954
|
+
if (Number.isFinite(v)) sum += v * v;
|
|
955
|
+
else nonFinite++;
|
|
956
|
+
}
|
|
957
|
+
let rms = Math.sqrt(sum / data.length);
|
|
958
|
+
if (nonFinite > 0) {
|
|
959
|
+
const clean = new Float32Array(data);
|
|
960
|
+
for (let i = 0; i < clean.length; i++) if (!Number.isFinite(clean[i])) clean[i] = 0;
|
|
961
|
+
data = clean;
|
|
962
|
+
if (!Number.isFinite(rms)) rms = 0;
|
|
963
|
+
}
|
|
964
|
+
const frameValid = nonFinite === 0;
|
|
888
965
|
const durationMs = data.length / SAMPLE_RATE2 * 1e3;
|
|
889
966
|
for (const fn of levelListeners) {
|
|
890
967
|
try {
|
|
@@ -893,17 +970,22 @@ function createAsrEngine(config, sessionId) {
|
|
|
893
970
|
}
|
|
894
971
|
}
|
|
895
972
|
const playingNow = config.isPlaying?.() ?? false;
|
|
973
|
+
const rawNow = config.isPlayingRaw ? config.isPlayingRaw() : playingNow;
|
|
896
974
|
const gateRatio = Math.pow(10, (config.echoGateDb ?? 6) / 20);
|
|
897
975
|
const peakDecay = Math.pow(0.9, durationMs / 64);
|
|
898
976
|
const floorAlpha = 1 - Math.pow(0.98, durationMs / 64);
|
|
899
|
-
if (
|
|
977
|
+
if (!Number.isFinite(echoFloorRms)) echoFloorRms = 0;
|
|
978
|
+
if (!Number.isFinite(echoPeak)) echoPeak = 0;
|
|
979
|
+
if (playingNow && frameValid) {
|
|
900
980
|
latestResidualRms = rms;
|
|
901
981
|
echoPeak = Math.max(echoPeak * peakDecay, rms);
|
|
902
982
|
}
|
|
903
983
|
const doubleTalk = playingNow && echoFloorRms > 0 && rms > echoFloorRms * gateRatio;
|
|
904
984
|
if (playingNow) {
|
|
905
|
-
if (
|
|
906
|
-
|
|
985
|
+
if (frameValid) {
|
|
986
|
+
if (echoFloorRms === 0) echoFloorRms = rms;
|
|
987
|
+
else if (!doubleTalk) echoFloorRms = echoFloorRms * (1 - floorAlpha) + rms * floorAlpha;
|
|
988
|
+
}
|
|
907
989
|
} else {
|
|
908
990
|
echoPeak = 0;
|
|
909
991
|
}
|
|
@@ -921,7 +1003,7 @@ function createAsrEngine(config, sessionId) {
|
|
|
921
1003
|
}
|
|
922
1004
|
if (playingNow && !holdActive && config.mode !== "hold") {
|
|
923
1005
|
detectChunks.push(data);
|
|
924
|
-
if (salvageEnabled) {
|
|
1006
|
+
if (salvageEnabled && rawNow) {
|
|
925
1007
|
if (preRoll.length === 0) preRollStartWall = Date.now();
|
|
926
1008
|
preRoll.push(data);
|
|
927
1009
|
preRollMs += durationMs;
|
|
@@ -933,14 +1015,13 @@ function createAsrEngine(config, sessionId) {
|
|
|
933
1015
|
}
|
|
934
1016
|
}
|
|
935
1017
|
}
|
|
936
|
-
if (
|
|
937
|
-
wasPlaying =
|
|
1018
|
+
if (rawNow !== wasPlaying) {
|
|
1019
|
+
wasPlaying = rawNow;
|
|
1020
|
+
if (rawNow) rawPlayingSinceWall = Date.now() - durationMs;
|
|
938
1021
|
preRollSeedWall = null;
|
|
939
1022
|
preRoll = [];
|
|
940
1023
|
preRollMs = 0;
|
|
941
1024
|
preRollStartWall = 0;
|
|
942
|
-
} else if (!playingNow && wasPlaying) {
|
|
943
|
-
wasPlaying = false;
|
|
944
1025
|
}
|
|
945
1026
|
if (holdActive) {
|
|
946
1027
|
if (!speechActive) {
|
|
@@ -995,6 +1076,8 @@ function createAsrEngine(config, sessionId) {
|
|
|
995
1076
|
segment.push(data);
|
|
996
1077
|
if (segmentMs > MAX_SEGMENT_MS) finalizeSegment();
|
|
997
1078
|
}
|
|
1079
|
+
} else if (speechActive && config.isPlaying?.()) {
|
|
1080
|
+
finalizeSegment(true);
|
|
998
1081
|
} else if (speechActive) {
|
|
999
1082
|
if (utteranceEndAt === null) {
|
|
1000
1083
|
utteranceEndAt = Date.now();
|
|
@@ -1008,6 +1091,7 @@ function createAsrEngine(config, sessionId) {
|
|
|
1008
1091
|
finalizeSegment();
|
|
1009
1092
|
} else {
|
|
1010
1093
|
segmentEpoch++;
|
|
1094
|
+
discardGen++;
|
|
1011
1095
|
segment = [];
|
|
1012
1096
|
speechActive = false;
|
|
1013
1097
|
salvagedSegment = false;
|
|
@@ -1048,6 +1132,7 @@ function createAsrEngine(config, sessionId) {
|
|
|
1048
1132
|
} catch {
|
|
1049
1133
|
}
|
|
1050
1134
|
if (stream === myStream) stream = null;
|
|
1135
|
+
if (!myCtx) return;
|
|
1051
1136
|
try {
|
|
1052
1137
|
await myCtx.close();
|
|
1053
1138
|
} catch {
|
|
@@ -1055,6 +1140,15 @@ function createAsrEngine(config, sessionId) {
|
|
|
1055
1140
|
if (audioCtx === myCtx) audioCtx = null;
|
|
1056
1141
|
};
|
|
1057
1142
|
const startRecorder = async () => {
|
|
1143
|
+
const owned = {};
|
|
1144
|
+
try {
|
|
1145
|
+
await startRecorderInner(owned);
|
|
1146
|
+
} catch (error) {
|
|
1147
|
+
if (owned.stream) await abandonStart(owned.stream, owned.ctx ?? null);
|
|
1148
|
+
throw error;
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
const startRecorderInner = async (owned) => {
|
|
1058
1152
|
const mySeq = startSeq;
|
|
1059
1153
|
const myStream = await navigator.mediaDevices.getUserMedia({
|
|
1060
1154
|
audio: {
|
|
@@ -1068,6 +1162,7 @@ function createAsrEngine(config, sessionId) {
|
|
|
1068
1162
|
autoGainControl: false
|
|
1069
1163
|
}
|
|
1070
1164
|
});
|
|
1165
|
+
owned.stream = myStream;
|
|
1071
1166
|
if (stopRequested || mySeq !== startSeq) {
|
|
1072
1167
|
myStream.getTracks().forEach((t3) => t3.stop());
|
|
1073
1168
|
return;
|
|
@@ -1083,6 +1178,7 @@ function createAsrEngine(config, sessionId) {
|
|
|
1083
1178
|
config.onAecState?.(aecOn);
|
|
1084
1179
|
const AC = window.AudioContext ?? window.webkitAudioContext;
|
|
1085
1180
|
const myCtx = new AC({ sampleRate: SAMPLE_RATE2 });
|
|
1181
|
+
owned.ctx = myCtx;
|
|
1086
1182
|
audioCtx = myCtx;
|
|
1087
1183
|
try {
|
|
1088
1184
|
await audioCtx.resume?.();
|
|
@@ -1138,6 +1234,7 @@ function createAsrEngine(config, sessionId) {
|
|
|
1138
1234
|
const myCtx = audioCtx;
|
|
1139
1235
|
inFlush = true;
|
|
1140
1236
|
segmentEpoch++;
|
|
1237
|
+
discardGen++;
|
|
1141
1238
|
forcePending = false;
|
|
1142
1239
|
holdActive = false;
|
|
1143
1240
|
segment = [];
|
|
@@ -1192,10 +1289,21 @@ function createAsrEngine(config, sessionId) {
|
|
|
1192
1289
|
get holding() {
|
|
1193
1290
|
return holdActive;
|
|
1194
1291
|
},
|
|
1195
|
-
/** A2.5 回声门控:当前残差是否明显高于回声地板(marginDb 默认 6dB)——判用户人声而非回声。
|
|
1292
|
+
/** A2.5 回声门控:当前残差是否明显高于回声地板(marginDb 默认 6dB)——判用户人声而非回声。
|
|
1293
|
+
* Issue #15 R15-5:本方法是客户端回声门控的**唯一询问点**——客户端在「本次检测达到
|
|
1294
|
+
* 打断确认帧数」的瞬间问本方法,答 false 即「放弃本次检测(判为回声,不打断)」。
|
|
1295
|
+
* 引擎据此作废抢救种子:被拒检测的窗口不得成为下次真打断的锚点(种子陈旧会被
|
|
1296
|
+
* Math.max 钳到环起点 → 整环 2s AI 音频并入用户消息)。作用域限定见 gateQueryScope。 */
|
|
1196
1297
|
aboveEchoFloor(marginDb = 6) {
|
|
1197
|
-
|
|
1198
|
-
|
|
1298
|
+
const pass = echoFloorRms > 0 && echoPeak > echoFloorRms * Math.pow(10, marginDb / 20);
|
|
1299
|
+
if (!pass && gateQueryScope) preRollSeedWall = null;
|
|
1300
|
+
return pass;
|
|
1301
|
+
},
|
|
1302
|
+
/** 作废抢救种子(客户端放弃本次检测时调用——语义见 AsrEngine.invalidateSalvageSeed)。
|
|
1303
|
+
* Issue #15 R15-5:补「从未问过门控」的放弃路径(确认帧数未达门槛 / 迟滞衰减归零):
|
|
1304
|
+
* 这类检测不会触发上面的门控询问点,引擎只能由客户端显式告知。 */
|
|
1305
|
+
invalidateSalvageSeed() {
|
|
1306
|
+
preRollSeedWall = null;
|
|
1199
1307
|
},
|
|
1200
1308
|
echoLevels() {
|
|
1201
1309
|
return { floorRms: echoFloorRms, residualRms: latestResidualRms, peakRms: echoPeak };
|
|
@@ -1206,6 +1314,7 @@ function createAsrEngine(config, sessionId) {
|
|
|
1206
1314
|
startSeq++;
|
|
1207
1315
|
const myStartSeq = startSeq;
|
|
1208
1316
|
segmentEpoch++;
|
|
1317
|
+
discardGen++;
|
|
1209
1318
|
partialFailStreak = 0;
|
|
1210
1319
|
detectFailStreak = 0;
|
|
1211
1320
|
lastPollAt = 0;
|
|
@@ -1255,6 +1364,7 @@ function createAsrEngine(config, sessionId) {
|
|
|
1255
1364
|
if (!active || holdActive) return;
|
|
1256
1365
|
holdActive = true;
|
|
1257
1366
|
segmentEpoch++;
|
|
1367
|
+
discardGen++;
|
|
1258
1368
|
wakeConsumed = false;
|
|
1259
1369
|
salvagedSegment = false;
|
|
1260
1370
|
yieldedSegment = false;
|
|
@@ -1275,6 +1385,7 @@ function createAsrEngine(config, sessionId) {
|
|
|
1275
1385
|
},
|
|
1276
1386
|
discardSegment() {
|
|
1277
1387
|
segmentEpoch++;
|
|
1388
|
+
discardGen++;
|
|
1278
1389
|
partialFailStreak = 0;
|
|
1279
1390
|
detectFailStreak = 0;
|
|
1280
1391
|
segment = [];
|
|
@@ -1332,7 +1443,9 @@ function createAsrEngine(config, sessionId) {
|
|
|
1332
1443
|
holdActive = false;
|
|
1333
1444
|
if (cancel) {
|
|
1334
1445
|
segmentEpoch++;
|
|
1446
|
+
discardGen++;
|
|
1335
1447
|
segment = [];
|
|
1448
|
+
uploadedSamples = 0;
|
|
1336
1449
|
salvagedSegment = false;
|
|
1337
1450
|
yieldedSegment = false;
|
|
1338
1451
|
resetFailStreaks();
|
|
@@ -1444,7 +1557,9 @@ var NlmsAec = class {
|
|
|
1444
1557
|
const bufLen = xBuf.length;
|
|
1445
1558
|
let cursor = this.cursor;
|
|
1446
1559
|
for (let i = 0; i < n; i++) {
|
|
1447
|
-
|
|
1560
|
+
let r = i < ref.length ? ref[i] : 0;
|
|
1561
|
+
if (!Number.isFinite(r) && !Number.isNaN(r)) r = 0;
|
|
1562
|
+
xBuf[cursor] = r;
|
|
1448
1563
|
cursor = (cursor + 1) % bufLen;
|
|
1449
1564
|
this.filled = Math.min(this.filled + 1, bufLen);
|
|
1450
1565
|
const d = mic[i];
|
|
@@ -1459,10 +1574,11 @@ var NlmsAec = class {
|
|
|
1459
1574
|
idx = (idx - 1 + bufLen) % bufLen;
|
|
1460
1575
|
}
|
|
1461
1576
|
const e = d - y;
|
|
1462
|
-
|
|
1577
|
+
const eSafe = Number.isFinite(e) ? e : 0;
|
|
1578
|
+
out[i] = eSafe;
|
|
1463
1579
|
if (norm > MIN_REF_NORM && !this.frozen) {
|
|
1464
1580
|
const denom = norm + this.eps;
|
|
1465
|
-
const gain = this.mu *
|
|
1581
|
+
const gain = this.mu * eSafe / denom;
|
|
1466
1582
|
idx = (cursor - this.delay + bufLen) % bufLen;
|
|
1467
1583
|
for (let t3 = 0; t3 < this.filterLength; t3++) {
|
|
1468
1584
|
this.w[t3] += gain * xBuf[idx];
|
|
@@ -1470,10 +1586,16 @@ var NlmsAec = class {
|
|
|
1470
1586
|
}
|
|
1471
1587
|
}
|
|
1472
1588
|
} else {
|
|
1473
|
-
out[i] = d;
|
|
1589
|
+
out[i] = Number.isFinite(d) ? d : 0;
|
|
1474
1590
|
}
|
|
1475
1591
|
}
|
|
1476
1592
|
this.cursor = cursor;
|
|
1593
|
+
for (let t3 = 0; t3 < this.filterLength; t3++) {
|
|
1594
|
+
if (!Number.isFinite(this.w[t3])) {
|
|
1595
|
+
this.w.fill(0);
|
|
1596
|
+
break;
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1477
1599
|
return out;
|
|
1478
1600
|
}
|
|
1479
1601
|
};
|
|
@@ -1546,6 +1668,7 @@ var ERROR_I18N_KEY = {
|
|
|
1546
1668
|
unknown_session: "errUnknownSession",
|
|
1547
1669
|
forbidden: "errForbidden",
|
|
1548
1670
|
bad_request: "errBadRequest",
|
|
1671
|
+
method_not_allowed: "errMethodNotAllowed",
|
|
1549
1672
|
engine_not_active: "errEngineNotActive",
|
|
1550
1673
|
model_download_failed: "errModelDownload",
|
|
1551
1674
|
too_many_streams: "errTooManyStreams",
|
|
@@ -1611,7 +1734,7 @@ var zh = {
|
|
|
1611
1734
|
startFail: "\u8BED\u97F3\u6A21\u5F0F\u542F\u52A8\u5931\u8D25\uFF1A{err}",
|
|
1612
1735
|
holdDots: "\u6309\u4F4F\u8BF4\u8BDD\u2026",
|
|
1613
1736
|
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",
|
|
1737
|
+
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
1738
|
// settings-form
|
|
1616
1739
|
previewNameFirst: "\u8BF7\u5148\u586B\u5199\u97F3\u8272\u540D\uFF08ShortName\uFF09",
|
|
1617
1740
|
previewDisabled: "\u8BED\u97F3\u6A21\u5F0F\u5DF2\u7981\u7528\uFF08\u63D2\u4EF6 enabled=false\uFF09\uFF0C\u65E0\u6CD5\u8BD5\u542C",
|
|
@@ -1653,6 +1776,17 @@ var zh = {
|
|
|
1653
1776
|
// R1 收尾(fix-client 直连 tk() 调用):连续 3 次回声拒断的解释出口 + 快捷键非法停用提示。
|
|
1654
1777
|
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
1778
|
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",
|
|
1779
|
+
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",
|
|
1780
|
+
composerShortcutLabel: "\u8FDB\u5165 / \u9000\u51FA\u8BED\u97F3\u6A21\u5F0F\uFF08\u8F93\u5165\u6846\u5185\uFF09",
|
|
1781
|
+
shortcutRecord: "\u5F55\u5236",
|
|
1782
|
+
shortcutRecording: "\u6309\u4E0B\u7EC4\u5408\u952E\u2026",
|
|
1783
|
+
shortcutCancel: "\u53D6\u6D88",
|
|
1784
|
+
shortcutNeedModifier: "\u9700\u8981\u81F3\u5C11\u4E00\u4E2A\u4FEE\u9970\u952E",
|
|
1785
|
+
shortcutUnsupportedKey: "\u53EA\u652F\u6301\u5B57\u6BCD\u3001\u6570\u5B57\u3001Enter\u3001Space\u3001Tab",
|
|
1786
|
+
shortcutPlaceholder: "\u70B9\u5F55\u5236\u540E\u6309\u7EC4\u5408\u952E",
|
|
1787
|
+
shortcutReset: "\u6062\u590D\u9ED8\u8BA4",
|
|
1788
|
+
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",
|
|
1789
|
+
secShortcut: "\u5FEB\u6377\u952E",
|
|
1656
1790
|
elapsedHint: "\u5F53\u524D\u8BED\u97F3\u4F1A\u8BDD\u5DF2\u7528\u65F6\u957F",
|
|
1657
1791
|
botLevelsHint: "AI \u6717\u8BFB\u97F3\u91CF\uFF08\u84DD\u8272\u6761 = \u6717\u8BFB\uFF0C\u7EFF\u8272\u6761 = \u9EA6\u514B\u98CE\uFF09",
|
|
1658
1792
|
interruptConfirm: "\u6253\u65AD\u786E\u8BA4",
|
|
@@ -1706,7 +1840,7 @@ var zh = {
|
|
|
1706
1840
|
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",
|
|
1707
1841
|
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",
|
|
1708
1842
|
wakePlaceholder: "\u5982\uFF1A\u4F60\u597D\u5C0FD",
|
|
1709
|
-
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",
|
|
1843
|
+
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",
|
|
1710
1844
|
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",
|
|
1711
1845
|
effectivePending: "\u6709 {count} \u9879\u4FEE\u6539\u5C06\u5728\u4E0B\u6B21\u8FDB\u5165\u8BED\u97F3\u6A21\u5F0F\u65F6\u751F\u6548\uFF1A{items}",
|
|
1712
1846
|
valueOn: "\u5F00",
|
|
@@ -1790,7 +1924,7 @@ var zh = {
|
|
|
1790
1924
|
bargeInModeLabel: "\u6253\u65AD\u65B9\u5F0F",
|
|
1791
1925
|
echoGateDbLabel: "\u56DE\u58F0\u95E8\u63A7",
|
|
1792
1926
|
modeLabel: "\u4EA4\u4E92\u6A21\u5F0F",
|
|
1793
|
-
shortcutLabel: "\
|
|
1927
|
+
shortcutLabel: "\u8FDB\u5165 / \u9000\u51FA\u8BED\u97F3\u6A21\u5F0F\uFF08\u5E94\u7528\u5185\uFF09",
|
|
1794
1928
|
wakeWordLabel: "\u5524\u9192\u8BCD",
|
|
1795
1929
|
toolBeepLabel: "\u5DE5\u5177\u63D0\u793A\u97F3",
|
|
1796
1930
|
autoSendLabel: "\u81EA\u52A8\u53D1\u9001",
|
|
@@ -1826,6 +1960,7 @@ var zh = {
|
|
|
1826
1960
|
errUnknownSession: "\u8BED\u97F3\u4F1A\u8BDD\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u5F00\u542F\u8BED\u97F3\u6A21\u5F0F",
|
|
1827
1961
|
errForbidden: "\u8BF7\u6C42\u88AB\u62D2\u7EDD\uFF08\u4EC5\u9650\u672C\u673A\u8BBF\u95EE\uFF0C\u6216\u6765\u6E90\u4E0D\u7B26\uFF09",
|
|
1828
1962
|
errBadRequest: "\u8BF7\u6C42\u65E0\u6548",
|
|
1963
|
+
errMethodNotAllowed: "\u8BF7\u6C42\u65B9\u6CD5\u4E0D\u88AB\u652F\u6301",
|
|
1829
1964
|
errEngineNotActive: "\u8BE5\u6717\u8BFB\u5F15\u64CE\u5F53\u524D\u672A\u542F\u7528",
|
|
1830
1965
|
errModelDownload: "\u6A21\u578B\u4E0B\u8F7D\u5931\u8D25\uFF1A\u8BF7\u68C0\u67E5\u7F51\u7EDC",
|
|
1831
1966
|
errTooManyStreams: "\u8BED\u97F3\u8FDE\u63A5\u8FC7\u591A\uFF0C\u8BF7\u5173\u95ED\u5176\u5B83\u8BED\u97F3\u9875\u9762\u540E\u91CD\u8BD5",
|
|
@@ -1885,7 +2020,7 @@ var en = {
|
|
|
1885
2020
|
startFail: "Voice mode failed to start: {err}",
|
|
1886
2021
|
holdDots: "Hold to talk\u2026",
|
|
1887
2022
|
exit: "Exit",
|
|
1888
|
-
configUnavailableNote: " (settings document not ready; the panel will appear when it is).",
|
|
2023
|
+
configUnavailableNote: " (settings document not ready; retrying \u2014 the panel will appear when it is).",
|
|
1889
2024
|
previewNameFirst: "Enter a voice ShortName first",
|
|
1890
2025
|
previewDisabled: "Voice mode disabled (plugin enabled=false); preview unavailable",
|
|
1891
2026
|
// 批 G 任务 6:本地 TTS 引擎未下载模型时禁用试听按钮 + 提示。
|
|
@@ -1925,6 +2060,17 @@ var en = {
|
|
|
1925
2060
|
// R1 收尾(fix-client 直连 tk() 调用):连续 3 次回声拒断的解释出口 + 快捷键非法停用提示。
|
|
1926
2061
|
echoRejectHint: "Strong echo detected \u2014 barge-in is limited by echo protection. Use headphones or switch to manual barge-in",
|
|
1927
2062
|
shortcutInvalid: "Invalid shortcut, disabled. Fix it in settings (e.g. Ctrl+Shift+V); leave empty to use the mic button only",
|
|
2063
|
+
descComposerShortcut: "Shortcut to toggle voice mode while the composer has focus (default Alt/Option+Enter)",
|
|
2064
|
+
composerShortcutLabel: "Enter / exit voice mode (in composer)",
|
|
2065
|
+
shortcutRecord: "Record",
|
|
2066
|
+
shortcutRecording: "Press a key combo\u2026",
|
|
2067
|
+
shortcutCancel: "Cancel",
|
|
2068
|
+
shortcutNeedModifier: "At least one modifier is required",
|
|
2069
|
+
shortcutUnsupportedKey: "Only letters, digits, Enter, Space and Tab are supported",
|
|
2070
|
+
shortcutPlaceholder: "Click Record, then press a combo",
|
|
2071
|
+
shortcutReset: "Reset to default",
|
|
2072
|
+
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.",
|
|
2073
|
+
secShortcut: "Shortcut",
|
|
1928
2074
|
elapsedHint: "Current voice session duration",
|
|
1929
2075
|
botLevelsHint: "AI playback level (blue bar = TTS playback, green bar = microphone)",
|
|
1930
2076
|
interruptConfirm: "interrupt confirm",
|
|
@@ -1977,7 +2123,7 @@ var en = {
|
|
|
1977
2123
|
descShowStatusBar: "Show the voice status bar above the composer (waveform, transcript, timer, notices, exit); when off, state shows only on the mic button",
|
|
1978
2124
|
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',
|
|
1979
2125
|
wakePlaceholder: "e.g. Hey D",
|
|
1980
|
-
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",
|
|
2126
|
+
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",
|
|
1981
2127
|
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.",
|
|
1982
2128
|
effectivePending: "{count} change(s) will apply next time you enter voice mode: {items}",
|
|
1983
2129
|
valueOn: "On",
|
|
@@ -2055,7 +2201,7 @@ var en = {
|
|
|
2055
2201
|
bargeInModeLabel: "Interrupt mode",
|
|
2056
2202
|
echoGateDbLabel: "Echo gate",
|
|
2057
2203
|
modeLabel: "Interaction mode",
|
|
2058
|
-
shortcutLabel: "
|
|
2204
|
+
shortcutLabel: "Enter / exit voice mode (app-wide)",
|
|
2059
2205
|
wakeWordLabel: "Wake word",
|
|
2060
2206
|
toolBeepLabel: "Tool-call beep",
|
|
2061
2207
|
autoSendLabel: "Auto-send",
|
|
@@ -2091,6 +2237,7 @@ var en = {
|
|
|
2091
2237
|
errUnknownSession: "Voice session expired \u2014 re-enter voice mode",
|
|
2092
2238
|
errForbidden: "Request denied (local access only, or origin mismatch)",
|
|
2093
2239
|
errBadRequest: "Invalid request",
|
|
2240
|
+
errMethodNotAllowed: "Request method not allowed",
|
|
2094
2241
|
errEngineNotActive: "That read-aloud engine is not active",
|
|
2095
2242
|
errModelDownload: "Model download failed \u2014 check your network",
|
|
2096
2243
|
errTooManyStreams: "Too many voice connections \u2014 close other voice tabs and retry",
|
|
@@ -2228,6 +2375,170 @@ function takeToggleSlot(history, now) {
|
|
|
2228
2375
|
function onceFinished(o, running, ttsDrained, playing) {
|
|
2229
2376
|
return o.sawRun && !running && ttsDrained && !playing;
|
|
2230
2377
|
}
|
|
2378
|
+
function isPrimaryPress(button, opts) {
|
|
2379
|
+
if (button !== 0) return false;
|
|
2380
|
+
if (opts.mac && opts.ctrlKey) return false;
|
|
2381
|
+
return true;
|
|
2382
|
+
}
|
|
2383
|
+
function eqPaintMode(reducedMotion) {
|
|
2384
|
+
return reducedMotion ? "static-full" : "animated";
|
|
2385
|
+
}
|
|
2386
|
+
function menuFocusIndex(i, len, dir) {
|
|
2387
|
+
if (len <= 0) return -1;
|
|
2388
|
+
if (i < 0) return dir === 1 ? 0 : len - 1;
|
|
2389
|
+
return (i + dir + len) % len;
|
|
2390
|
+
}
|
|
2391
|
+
function handleReplaced(o) {
|
|
2392
|
+
if (o.staleBus) {
|
|
2393
|
+
o.retire();
|
|
2394
|
+
return;
|
|
2395
|
+
}
|
|
2396
|
+
o.reconnect(o.renewTabId());
|
|
2397
|
+
}
|
|
2398
|
+
function decayConfirmCount(count, abandon) {
|
|
2399
|
+
const next = Math.max(0, count - 1);
|
|
2400
|
+
if (next === 0) abandon();
|
|
2401
|
+
return next;
|
|
2402
|
+
}
|
|
2403
|
+
function shouldReleaseStopLine(o) {
|
|
2404
|
+
if (!o.hasStopLine) return false;
|
|
2405
|
+
if (o.untilNextRun) return false;
|
|
2406
|
+
if (o.turn !== void 0 && o.lastTurn !== void 0) return o.turn !== o.lastTurn;
|
|
2407
|
+
if (o.sameRoundContinuation) return false;
|
|
2408
|
+
return true;
|
|
2409
|
+
}
|
|
2410
|
+
function applyTurnEvent(o) {
|
|
2411
|
+
const release = shouldReleaseStopLine({
|
|
2412
|
+
hasStopLine: o.hasStopLine,
|
|
2413
|
+
untilNextRun: o.untilNextRun,
|
|
2414
|
+
turn: o.turn,
|
|
2415
|
+
lastTurn: o.identity.lastTurn,
|
|
2416
|
+
sameRoundContinuation: o.sameRoundContinuation
|
|
2417
|
+
});
|
|
2418
|
+
return {
|
|
2419
|
+
identity: o.turn !== void 0 ? { lastTurn: o.turn } : o.identity,
|
|
2420
|
+
release
|
|
2421
|
+
};
|
|
2422
|
+
}
|
|
2423
|
+
function cancelPayload(o) {
|
|
2424
|
+
return JSON.stringify({ sessionId: o.sessionId, keepAsr: o.keepAsr, reason: o.reason });
|
|
2425
|
+
}
|
|
2426
|
+
function auxClickPending(button, opts) {
|
|
2427
|
+
return button === 0 && opts.mac && opts.ctrlKey;
|
|
2428
|
+
}
|
|
2429
|
+
function isAuxClickToIgnore(pending, clickDetail) {
|
|
2430
|
+
return pending && clickDetail !== 0;
|
|
2431
|
+
}
|
|
2432
|
+
function isGestureEnd(armed, up) {
|
|
2433
|
+
if (!armed) return false;
|
|
2434
|
+
return armed.id === up.id && armed.button === up.button;
|
|
2435
|
+
}
|
|
2436
|
+
function pointerUpAction(armed, up) {
|
|
2437
|
+
if (!armed) return "unarmed";
|
|
2438
|
+
if (!isGestureEnd(armed, up)) return "ignore";
|
|
2439
|
+
return "finish";
|
|
2440
|
+
}
|
|
2441
|
+
function focusFailureAction(status, attempt) {
|
|
2442
|
+
if (status !== 403) return "silent";
|
|
2443
|
+
return attempt === 1 ? "retry-later" : "report-once";
|
|
2444
|
+
}
|
|
2445
|
+
async function reportFocus(o) {
|
|
2446
|
+
const wait = o.wait ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
2447
|
+
const warn = o.warn ?? (() => {
|
|
2448
|
+
});
|
|
2449
|
+
const retryMs = o.retryMs ?? 800;
|
|
2450
|
+
let attempts = 0;
|
|
2451
|
+
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
2452
|
+
attempts++;
|
|
2453
|
+
let status;
|
|
2454
|
+
try {
|
|
2455
|
+
status = (await o.fetchImpl()).status;
|
|
2456
|
+
} catch {
|
|
2457
|
+
return { ok: false, reported: false, attempts, skipped: false };
|
|
2458
|
+
}
|
|
2459
|
+
const action = focusFailureAction(status, attempt);
|
|
2460
|
+
if (action === "silent") return { ok: status >= 200 && status < 300, reported: false, attempts, skipped: false };
|
|
2461
|
+
if (action === "retry-later") {
|
|
2462
|
+
if (o.sessionId === null) return { ok: false, reported: false, attempts, skipped: false };
|
|
2463
|
+
await wait(retryMs);
|
|
2464
|
+
if (o.stillRelevant && !o.stillRelevant()) {
|
|
2465
|
+
return { ok: false, reported: false, attempts, skipped: true };
|
|
2466
|
+
}
|
|
2467
|
+
continue;
|
|
2468
|
+
}
|
|
2469
|
+
warn({ sessionId: o.sessionId, status });
|
|
2470
|
+
return { ok: false, reported: true, attempts, skipped: false };
|
|
2471
|
+
}
|
|
2472
|
+
return { ok: false, reported: false, attempts, skipped: false };
|
|
2473
|
+
}
|
|
2474
|
+
var FOCUS_OWNER_DEFAULT = "default";
|
|
2475
|
+
function focusSession(owners) {
|
|
2476
|
+
let last = null;
|
|
2477
|
+
for (const sessionId of owners.values()) last = sessionId;
|
|
2478
|
+
return last;
|
|
2479
|
+
}
|
|
2480
|
+
function focusClaim(owners, owner, sessionId) {
|
|
2481
|
+
owners.delete(owner);
|
|
2482
|
+
owners.set(owner, sessionId);
|
|
2483
|
+
}
|
|
2484
|
+
function focusRelease(owners, owner) {
|
|
2485
|
+
const before = focusSession(owners);
|
|
2486
|
+
owners.delete(owner);
|
|
2487
|
+
const focused = focusSession(owners);
|
|
2488
|
+
return { changed: before !== focused, focused };
|
|
2489
|
+
}
|
|
2490
|
+
function registerScopeDispose(host, raw) {
|
|
2491
|
+
host.effect(() => raw.dispose);
|
|
2492
|
+
}
|
|
2493
|
+
function createScopeBridge(raw) {
|
|
2494
|
+
const listeners = [];
|
|
2495
|
+
let off = null;
|
|
2496
|
+
function resubscribe() {
|
|
2497
|
+
off?.();
|
|
2498
|
+
off = raw.subscribe(forward);
|
|
2499
|
+
}
|
|
2500
|
+
function forward() {
|
|
2501
|
+
for (const entry of [...listeners]) entry.fn();
|
|
2502
|
+
}
|
|
2503
|
+
const scope = {
|
|
2504
|
+
getSnapshot: () => raw.getSnapshot(),
|
|
2505
|
+
subscribe(fn) {
|
|
2506
|
+
const entry = { fn };
|
|
2507
|
+
listeners.push(entry);
|
|
2508
|
+
if (listeners.length === 1) off = raw.subscribe(forward);
|
|
2509
|
+
return () => {
|
|
2510
|
+
const i = listeners.indexOf(entry);
|
|
2511
|
+
if (i >= 0) listeners.splice(i, 1);
|
|
2512
|
+
if (listeners.length === 0 && off !== null) {
|
|
2513
|
+
off();
|
|
2514
|
+
off = null;
|
|
2515
|
+
}
|
|
2516
|
+
};
|
|
2517
|
+
},
|
|
2518
|
+
set: (field, value) => raw.set(field, value)
|
|
2519
|
+
};
|
|
2520
|
+
return {
|
|
2521
|
+
scope,
|
|
2522
|
+
invalidate() {
|
|
2523
|
+
if (typeof raw.invalidate === "function") {
|
|
2524
|
+
raw.invalidate();
|
|
2525
|
+
return;
|
|
2526
|
+
}
|
|
2527
|
+
if (listeners.length === 0) return;
|
|
2528
|
+
resubscribe();
|
|
2529
|
+
}
|
|
2530
|
+
};
|
|
2531
|
+
}
|
|
2532
|
+
var RENEW_WHILE_HIDDEN = true;
|
|
2533
|
+
var IDLE_USER_ACTIVITY_CAP_MS = 2 * 60 * 60 * 1e3;
|
|
2534
|
+
function idleBusy(input) {
|
|
2535
|
+
if (input.hidden && !RENEW_WHILE_HIDDEN) return false;
|
|
2536
|
+
return input.playing || input.turn === "agent-speaking" || input.running;
|
|
2537
|
+
}
|
|
2538
|
+
function idleAction(input) {
|
|
2539
|
+
if (input.busy && input.sinceUserActivityMs <= IDLE_USER_ACTIVITY_CAP_MS) return "renew";
|
|
2540
|
+
return input.warn ? "warn" : "exit";
|
|
2541
|
+
}
|
|
2231
2542
|
|
|
2232
2543
|
// src/runtime-boot.ts
|
|
2233
2544
|
var runtimeBoot = null;
|
|
@@ -2635,6 +2946,114 @@ function TextField({
|
|
|
2635
2946
|
}
|
|
2636
2947
|
);
|
|
2637
2948
|
}
|
|
2949
|
+
function ShortcutField({
|
|
2950
|
+
score,
|
|
2951
|
+
field,
|
|
2952
|
+
value
|
|
2953
|
+
}) {
|
|
2954
|
+
const [draft, setDraft] = (0, import_react2.useState)(String(value ?? ""));
|
|
2955
|
+
const [recording, setRecording] = (0, import_react2.useState)(false);
|
|
2956
|
+
const [err, setErr] = (0, import_react2.useState)("");
|
|
2957
|
+
(0, import_react2.useEffect)(() => {
|
|
2958
|
+
setDraft((d) => d === String(value ?? "") ? d : String(value ?? ""));
|
|
2959
|
+
}, [value]);
|
|
2960
|
+
const notify = () => {
|
|
2961
|
+
try {
|
|
2962
|
+
window.dispatchEvent(new Event("dshvm-settings-changed"));
|
|
2963
|
+
} catch {
|
|
2964
|
+
}
|
|
2965
|
+
};
|
|
2966
|
+
const commit = () => {
|
|
2967
|
+
void score.set(field, draft.trim());
|
|
2968
|
+
notify();
|
|
2969
|
+
};
|
|
2970
|
+
(0, import_react2.useEffect)(() => {
|
|
2971
|
+
if (!recording) return;
|
|
2972
|
+
const onKey = (e) => {
|
|
2973
|
+
e.preventDefault();
|
|
2974
|
+
e.stopPropagation();
|
|
2975
|
+
if (e.key === "Escape") {
|
|
2976
|
+
setRecording(false);
|
|
2977
|
+
setErr("");
|
|
2978
|
+
return;
|
|
2979
|
+
}
|
|
2980
|
+
if (e.key === "Backspace" || e.key === "Delete") {
|
|
2981
|
+
setDraft("");
|
|
2982
|
+
void score.set(field, "");
|
|
2983
|
+
notify();
|
|
2984
|
+
setRecording(false);
|
|
2985
|
+
return;
|
|
2986
|
+
}
|
|
2987
|
+
if (e.key === "Control" || e.key === "Alt" || e.key === "Shift" || e.key === "Meta") return;
|
|
2988
|
+
const mods = [];
|
|
2989
|
+
if (e.metaKey) mods.push("Cmd");
|
|
2990
|
+
else if (e.ctrlKey) mods.push("Ctrl");
|
|
2991
|
+
if (e.altKey) mods.push("Alt");
|
|
2992
|
+
if (e.shiftKey) mods.push("Shift");
|
|
2993
|
+
if (mods.length === 0) {
|
|
2994
|
+
setErr(t("shortcutNeedModifier"));
|
|
2995
|
+
return;
|
|
2996
|
+
}
|
|
2997
|
+
const named = e.key === "Enter" ? "Enter" : e.key === " " ? "Space" : e.key === "Tab" ? "Tab" : "";
|
|
2998
|
+
const codeKey = (e.code || "").replace(/^Key/, "").replace(/^Digit/, "");
|
|
2999
|
+
const k = named || (/^[A-Za-z0-9]$/.test(codeKey) ? codeKey.toUpperCase() : /^[A-Za-z0-9]$/.test(e.key) ? e.key.toUpperCase() : "");
|
|
3000
|
+
if (!k) {
|
|
3001
|
+
setErr(t("shortcutUnsupportedKey"));
|
|
3002
|
+
return;
|
|
3003
|
+
}
|
|
3004
|
+
const combo = [...mods, k].join("+");
|
|
3005
|
+
setDraft(combo);
|
|
3006
|
+
void score.set(field, combo);
|
|
3007
|
+
notify();
|
|
3008
|
+
setRecording(false);
|
|
3009
|
+
setErr("");
|
|
3010
|
+
};
|
|
3011
|
+
window.addEventListener("keydown", onKey, true);
|
|
3012
|
+
return () => window.removeEventListener("keydown", onKey, true);
|
|
3013
|
+
}, [recording, score, field]);
|
|
3014
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { display: "inline-flex", flexDirection: "column", alignItems: "flex-end", gap: 3 }, children: [
|
|
3015
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { display: "inline-flex", alignItems: "center", gap: 6 }, children: [
|
|
3016
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3017
|
+
"input",
|
|
3018
|
+
{
|
|
3019
|
+
style: { ...inputStyle, width: 150 },
|
|
3020
|
+
value: draft,
|
|
3021
|
+
placeholder: t("shortcutPlaceholder"),
|
|
3022
|
+
onChange: (e) => {
|
|
3023
|
+
setDraft(e.target.value);
|
|
3024
|
+
if (err) setErr("");
|
|
3025
|
+
},
|
|
3026
|
+
onBlur: commit,
|
|
3027
|
+
onKeyDown: (e) => {
|
|
3028
|
+
if (e.key === "Enter") commit();
|
|
3029
|
+
}
|
|
3030
|
+
}
|
|
3031
|
+
),
|
|
3032
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3033
|
+
"button",
|
|
3034
|
+
{
|
|
3035
|
+
type: "button",
|
|
3036
|
+
onClick: () => {
|
|
3037
|
+
setRecording((r) => !r);
|
|
3038
|
+
setErr("");
|
|
3039
|
+
},
|
|
3040
|
+
style: {
|
|
3041
|
+
height: 28,
|
|
3042
|
+
padding: "0 10px",
|
|
3043
|
+
borderRadius: 6,
|
|
3044
|
+
border: "1px solid var(--dsw-alias-border-l3)",
|
|
3045
|
+
background: "transparent",
|
|
3046
|
+
color: "var(--dsw-alias-label-secondary)",
|
|
3047
|
+
fontSize: 12,
|
|
3048
|
+
cursor: "pointer"
|
|
3049
|
+
},
|
|
3050
|
+
children: recording ? t("shortcutCancel") : t("shortcutRecord")
|
|
3051
|
+
}
|
|
3052
|
+
)
|
|
3053
|
+
] }),
|
|
3054
|
+
/* @__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 })
|
|
3055
|
+
] });
|
|
3056
|
+
}
|
|
2638
3057
|
function SelectField({
|
|
2639
3058
|
score,
|
|
2640
3059
|
field,
|
|
@@ -3313,7 +3732,6 @@ function VoiceSettingsCard({ scope, defaultOpen = false }) {
|
|
|
3313
3732
|
]
|
|
3314
3733
|
}
|
|
3315
3734
|
) }),
|
|
3316
|
-
/* @__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" }) }),
|
|
3317
3735
|
/* @__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") }) }),
|
|
3318
3736
|
/* @__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) }) }),
|
|
3319
3737
|
/* @__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) }) }),
|
|
@@ -3365,6 +3783,39 @@ function VoiceSettingsCard({ scope, defaultOpen = false }) {
|
|
|
3365
3783
|
/* @__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) }) }),
|
|
3366
3784
|
/* @__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 }) })
|
|
3367
3785
|
] }),
|
|
3786
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Section, { title: t("secShortcut"), children: [
|
|
3787
|
+
/* @__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 ?? "" }) }),
|
|
3788
|
+
/* @__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" }) }),
|
|
3789
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "flex-start", gap: 10, padding: "2px 0 6px" }, children: [
|
|
3790
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { flex: 1, fontSize: 11, lineHeight: "17px", color: "var(--dsw-alias-label-tertiary)" }, children: t("shortcutNote") }),
|
|
3791
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3792
|
+
"button",
|
|
3793
|
+
{
|
|
3794
|
+
type: "button",
|
|
3795
|
+
onClick: () => {
|
|
3796
|
+
void scope.set("shortcut", "Ctrl+Shift+V");
|
|
3797
|
+
void scope.set("composerShortcut", "Alt+Enter");
|
|
3798
|
+
try {
|
|
3799
|
+
window.dispatchEvent(new Event("dshvm-settings-changed"));
|
|
3800
|
+
} catch {
|
|
3801
|
+
}
|
|
3802
|
+
},
|
|
3803
|
+
style: {
|
|
3804
|
+
flexShrink: 0,
|
|
3805
|
+
height: 26,
|
|
3806
|
+
padding: "0 10px",
|
|
3807
|
+
borderRadius: 6,
|
|
3808
|
+
border: "1px solid var(--dsw-alias-border-l3)",
|
|
3809
|
+
background: "transparent",
|
|
3810
|
+
color: "var(--dsw-alias-label-secondary)",
|
|
3811
|
+
fontSize: 12,
|
|
3812
|
+
cursor: "pointer"
|
|
3813
|
+
},
|
|
3814
|
+
children: t("shortcutReset")
|
|
3815
|
+
}
|
|
3816
|
+
)
|
|
3817
|
+
] })
|
|
3818
|
+
] }),
|
|
3368
3819
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Section, { title: t("secRecognition"), children: [
|
|
3369
3820
|
/* @__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) }) }),
|
|
3370
3821
|
/* @__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) }) }),
|
|
@@ -3382,54 +3833,124 @@ function VoiceSettingsCard({ scope, defaultOpen = false }) {
|
|
|
3382
3833
|
|
|
3383
3834
|
// src/settings-http-scope.ts
|
|
3384
3835
|
var SETTINGS_URL = "/voice-mode/settings";
|
|
3385
|
-
|
|
3836
|
+
var RETRY_BASE_MS = 500;
|
|
3837
|
+
var RETRY_MAX_MS = 1e4;
|
|
3838
|
+
var REQUEST_TIMEOUT_MS = 8e3;
|
|
3839
|
+
function createHttpScope(origin = location.origin, fetchImpl = fetch, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
3386
3840
|
let snap = { status: "loading", value: {} };
|
|
3387
3841
|
const subs = /* @__PURE__ */ new Set();
|
|
3388
|
-
let
|
|
3842
|
+
let inFlight = false;
|
|
3843
|
+
let writing = 0;
|
|
3844
|
+
let writeGen = 0;
|
|
3845
|
+
let pendingReload = false;
|
|
3846
|
+
let disposed = false;
|
|
3847
|
+
let retryTimer = null;
|
|
3848
|
+
let retryDelay = 0;
|
|
3389
3849
|
const emit = (next) => {
|
|
3390
3850
|
snap = next;
|
|
3391
|
-
for (const fn of [...subs])
|
|
3851
|
+
for (const fn of [...subs]) {
|
|
3852
|
+
try {
|
|
3853
|
+
fn();
|
|
3854
|
+
} catch (e) {
|
|
3855
|
+
console.warn("[dsh-voice-mode] settings scope subscriber failed: " + String(e));
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
};
|
|
3859
|
+
const clearRetry = () => {
|
|
3860
|
+
if (retryTimer !== null) {
|
|
3861
|
+
clearTimeout(retryTimer);
|
|
3862
|
+
retryTimer = null;
|
|
3863
|
+
}
|
|
3392
3864
|
};
|
|
3393
3865
|
const load = async () => {
|
|
3866
|
+
if (disposed) return;
|
|
3867
|
+
if (inFlight) {
|
|
3868
|
+
pendingReload = true;
|
|
3869
|
+
return;
|
|
3870
|
+
}
|
|
3871
|
+
inFlight = true;
|
|
3872
|
+
clearRetry();
|
|
3873
|
+
const myGen = writeGen;
|
|
3394
3874
|
try {
|
|
3395
|
-
const res = await fetchImpl(origin + SETTINGS_URL);
|
|
3875
|
+
const res = await fetchImpl(origin + SETTINGS_URL, { signal: AbortSignal.timeout(timeoutMs) });
|
|
3396
3876
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
3397
3877
|
const data = await res.json();
|
|
3398
|
-
|
|
3878
|
+
retryDelay = 0;
|
|
3879
|
+
if (writing === 0 && myGen === writeGen) emit({ status: "ready", value: data.value ?? {} });
|
|
3399
3880
|
} catch {
|
|
3400
3881
|
emit({ status: "unavailable", value: snap.value });
|
|
3882
|
+
scheduleRetry();
|
|
3883
|
+
} finally {
|
|
3884
|
+
inFlight = false;
|
|
3885
|
+
if (pendingReload) {
|
|
3886
|
+
pendingReload = false;
|
|
3887
|
+
if (!disposed && subs.size > 0) void load();
|
|
3888
|
+
}
|
|
3401
3889
|
}
|
|
3402
3890
|
};
|
|
3403
|
-
|
|
3891
|
+
const scheduleRetry = () => {
|
|
3892
|
+
if (disposed || subs.size === 0 || retryTimer !== null) return;
|
|
3893
|
+
retryDelay = retryDelay === 0 ? RETRY_BASE_MS : Math.min(retryDelay * 2, RETRY_MAX_MS);
|
|
3894
|
+
retryTimer = setTimeout(() => {
|
|
3895
|
+
retryTimer = null;
|
|
3896
|
+
void load();
|
|
3897
|
+
}, retryDelay);
|
|
3898
|
+
};
|
|
3899
|
+
const onFocus = () => {
|
|
3900
|
+
if (subs.size > 0) void load();
|
|
3901
|
+
};
|
|
3902
|
+
if (typeof window !== "undefined" && typeof window.addEventListener === "function") {
|
|
3903
|
+
window.addEventListener("focus", onFocus);
|
|
3904
|
+
}
|
|
3905
|
+
const scope = {
|
|
3404
3906
|
getSnapshot: () => snap,
|
|
3405
3907
|
subscribe(fn) {
|
|
3908
|
+
const first = subs.size === 0;
|
|
3406
3909
|
subs.add(fn);
|
|
3407
|
-
if (
|
|
3408
|
-
|
|
3910
|
+
if (first) {
|
|
3911
|
+
retryDelay = 0;
|
|
3409
3912
|
void load();
|
|
3410
3913
|
}
|
|
3411
3914
|
return () => {
|
|
3412
3915
|
subs.delete(fn);
|
|
3916
|
+
if (subs.size === 0) clearRetry();
|
|
3413
3917
|
};
|
|
3414
3918
|
},
|
|
3415
3919
|
async set(field, value) {
|
|
3920
|
+
if (disposed) return;
|
|
3416
3921
|
const before = snap;
|
|
3922
|
+
writing++;
|
|
3417
3923
|
emit({ status: "ready", value: { ...snap.value, [field]: value } });
|
|
3924
|
+
let ok = false;
|
|
3418
3925
|
try {
|
|
3419
3926
|
const res = await fetchImpl(origin + SETTINGS_URL, {
|
|
3420
3927
|
method: "POST",
|
|
3421
3928
|
headers: { "content-type": "application/json" },
|
|
3422
|
-
body: JSON.stringify({ [field]: value })
|
|
3929
|
+
body: JSON.stringify({ [field]: value }),
|
|
3930
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
3423
3931
|
});
|
|
3424
3932
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
3425
3933
|
const data = await res.json();
|
|
3426
3934
|
emit({ status: "ready", value: data.value ?? before.value });
|
|
3935
|
+
ok = true;
|
|
3427
3936
|
} catch {
|
|
3428
3937
|
emit(before);
|
|
3429
|
-
|
|
3938
|
+
} finally {
|
|
3939
|
+
writing--;
|
|
3940
|
+
writeGen++;
|
|
3430
3941
|
}
|
|
3942
|
+
if (!ok) await load();
|
|
3943
|
+
},
|
|
3944
|
+
dispose: () => {
|
|
3945
|
+
disposed = true;
|
|
3946
|
+
pendingReload = false;
|
|
3947
|
+
if (typeof window !== "undefined" && typeof window.removeEventListener === "function") {
|
|
3948
|
+
window.removeEventListener("focus", onFocus);
|
|
3949
|
+
}
|
|
3950
|
+
clearRetry();
|
|
3431
3951
|
}
|
|
3432
3952
|
};
|
|
3953
|
+
return scope;
|
|
3433
3954
|
}
|
|
3434
3955
|
|
|
3435
3956
|
// src/client.tsx
|
|
@@ -3463,7 +3984,7 @@ function telemetryDeltas(tel) {
|
|
|
3463
3984
|
}
|
|
3464
3985
|
return out;
|
|
3465
3986
|
}
|
|
3466
|
-
var BUILD_TAG = "
|
|
3987
|
+
var BUILD_TAG = "5c6d521";
|
|
3467
3988
|
var TELEMETRY_FLAG = "dsh-voice-mode.telemetry";
|
|
3468
3989
|
var telemetryEnabled = typeof localStorage !== "undefined" && localStorage.getItem(TELEMETRY_FLAG) === "1";
|
|
3469
3990
|
console.log("[dsh-voice] build=" + BUILD_TAG);
|
|
@@ -3497,6 +4018,7 @@ var SAMPLE_RATE_16K = 16e3;
|
|
|
3497
4018
|
var ECHO_DELAY_MS = 0;
|
|
3498
4019
|
var AUTO_SEND_EXTRA_MS = 1200;
|
|
3499
4020
|
var ECHO_TAIL_MS = 400;
|
|
4021
|
+
var TOGGLE_TIMEOUT_MS = 8e3;
|
|
3500
4022
|
var HOLD_CLEAR_FRAMES = 2;
|
|
3501
4023
|
var WAVE_BARS = 14;
|
|
3502
4024
|
var BASE_PATH2 = "/voice-mode";
|
|
@@ -3524,6 +4046,8 @@ function getTabId(fresh = false) {
|
|
|
3524
4046
|
}
|
|
3525
4047
|
var TAB_ID = getTabId();
|
|
3526
4048
|
var BUS_GEN_KEY = "__dshvmBusGen";
|
|
4049
|
+
var focusOwnerSeq = 0;
|
|
4050
|
+
var settingsScopeInvalidate = null;
|
|
3527
4051
|
function parseShortcut(s) {
|
|
3528
4052
|
const parts = (s || "").split("+");
|
|
3529
4053
|
const mods = { ctrl: false, shift: false, alt: false, meta: false };
|
|
@@ -3537,6 +4061,9 @@ function parseShortcut(s) {
|
|
|
3537
4061
|
else if (t3.length === 1 && /^[a-z0-9]$/.test(t3)) {
|
|
3538
4062
|
if (key) return null;
|
|
3539
4063
|
key = t3;
|
|
4064
|
+
} else if (t3 === "enter" || t3 === "space" || t3 === "tab") {
|
|
4065
|
+
if (key) return null;
|
|
4066
|
+
key = t3;
|
|
3540
4067
|
} else return null;
|
|
3541
4068
|
}
|
|
3542
4069
|
if (!key) return null;
|
|
@@ -3651,7 +4178,17 @@ function apply(ctx) {
|
|
|
3651
4178
|
)
|
|
3652
4179
|
);
|
|
3653
4180
|
const settingsScope = ctx.get?.("settingsScope");
|
|
3654
|
-
|
|
4181
|
+
let scope;
|
|
4182
|
+
if (settingsScope) {
|
|
4183
|
+
scope = settingsScope.bind({ namespace: "voice-mode" });
|
|
4184
|
+
settingsScopeInvalidate = null;
|
|
4185
|
+
} else {
|
|
4186
|
+
const raw = createHttpScope();
|
|
4187
|
+
const bridge = createScopeBridge(raw);
|
|
4188
|
+
scope = bridge.scope;
|
|
4189
|
+
settingsScopeInvalidate = bridge.invalidate;
|
|
4190
|
+
registerScopeDispose(ctx, raw);
|
|
4191
|
+
}
|
|
3655
4192
|
ctx.slots.inject(
|
|
3656
4193
|
"settings.plugin.item",
|
|
3657
4194
|
() => ctx.slots.register(
|
|
@@ -3686,6 +4223,8 @@ function createAudioEngine(setUi, onPlayed, onPlaybackRef, onAllPlayed) {
|
|
|
3686
4223
|
const pending = [];
|
|
3687
4224
|
const fallbackAudio = new Audio();
|
|
3688
4225
|
let fallback = false;
|
|
4226
|
+
let decodeFailStreak = 0;
|
|
4227
|
+
let fallbackBusy = false;
|
|
3689
4228
|
let ctx = null;
|
|
3690
4229
|
let duckGain = null;
|
|
3691
4230
|
let analyser = null;
|
|
@@ -3721,19 +4260,23 @@ function createAudioEngine(setUi, onPlayed, onPlaybackRef, onAllPlayed) {
|
|
|
3721
4260
|
const playFallback = () => {
|
|
3722
4261
|
const frame = pending.shift() ?? null;
|
|
3723
4262
|
if (!frame) {
|
|
4263
|
+
fallbackBusy = false;
|
|
3724
4264
|
setUi({ playing: false, playingCaption: null });
|
|
3725
4265
|
return;
|
|
3726
4266
|
}
|
|
4267
|
+
fallbackBusy = true;
|
|
3727
4268
|
const url = URL.createObjectURL(new Blob([frame.audio], { type: frame.mime === "audio/wav" ? "audio/wav" : "audio/mpeg" }));
|
|
3728
4269
|
fallbackAudio.src = url;
|
|
3729
|
-
|
|
3730
|
-
URL.revokeObjectURL(url);
|
|
3731
|
-
playFallback();
|
|
3732
|
-
};
|
|
3733
|
-
fallbackAudio.onerror = () => {
|
|
4270
|
+
const next = () => {
|
|
3734
4271
|
URL.revokeObjectURL(url);
|
|
3735
|
-
|
|
4272
|
+
fallbackBusy = false;
|
|
4273
|
+
if (!fallback && ctx) {
|
|
4274
|
+
if (pending.length > 0) drainPending();
|
|
4275
|
+
else setUi({ playing: false, playingCaption: null });
|
|
4276
|
+
} else playFallback();
|
|
3736
4277
|
};
|
|
4278
|
+
fallbackAudio.onended = next;
|
|
4279
|
+
fallbackAudio.onerror = next;
|
|
3737
4280
|
fallbackAudio.onplaying = () => {
|
|
3738
4281
|
try {
|
|
3739
4282
|
onPlayed?.();
|
|
@@ -3754,13 +4297,14 @@ function createAudioEngine(setUi, onPlayed, onPlaybackRef, onAllPlayed) {
|
|
|
3754
4297
|
void fallbackAudio.play().catch(() => playFallback());
|
|
3755
4298
|
};
|
|
3756
4299
|
const drainPending = () => {
|
|
3757
|
-
if (decoding || !ctx || !duckGain || pending.length === 0) return;
|
|
4300
|
+
if (decoding || fallbackBusy || !ctx || !duckGain || pending.length === 0) return;
|
|
3758
4301
|
decoding = true;
|
|
3759
4302
|
void (async () => {
|
|
3760
4303
|
try {
|
|
3761
4304
|
while (pending.length > 0) {
|
|
3762
4305
|
const frame = pending[0];
|
|
3763
4306
|
const buf = await ctx.decodeAudioData(frame.audio.buffer.slice(0));
|
|
4307
|
+
decodeFailStreak = 0;
|
|
3764
4308
|
if (pending.length === 0 || pending[0] !== frame) return;
|
|
3765
4309
|
pending.shift();
|
|
3766
4310
|
const t0 = ctx.currentTime;
|
|
@@ -3804,7 +4348,7 @@ function createAudioEngine(setUi, onPlayed, onPlaybackRef, onAllPlayed) {
|
|
|
3804
4348
|
}
|
|
3805
4349
|
activeSrcs.clear();
|
|
3806
4350
|
captionQueue.length = 0;
|
|
3807
|
-
fallback = true;
|
|
4351
|
+
if (++decodeFailStreak >= 2) fallback = true;
|
|
3808
4352
|
playFallback();
|
|
3809
4353
|
} finally {
|
|
3810
4354
|
decoding = false;
|
|
@@ -3824,6 +4368,7 @@ function createAudioEngine(setUi, onPlayed, onPlaybackRef, onAllPlayed) {
|
|
|
3824
4368
|
},
|
|
3825
4369
|
skip() {
|
|
3826
4370
|
pending.length = 0;
|
|
4371
|
+
fallbackBusy = false;
|
|
3827
4372
|
nextEndAt = 0;
|
|
3828
4373
|
fallbackAudio.pause();
|
|
3829
4374
|
fallbackAudio.onended = null;
|
|
@@ -3839,6 +4384,10 @@ function createAudioEngine(setUi, onPlayed, onPlaybackRef, onAllPlayed) {
|
|
|
3839
4384
|
setUi({ playing: false, playingCaption: null });
|
|
3840
4385
|
},
|
|
3841
4386
|
warm,
|
|
4387
|
+
resetFallback() {
|
|
4388
|
+
fallback = false;
|
|
4389
|
+
decodeFailStreak = 0;
|
|
4390
|
+
},
|
|
3842
4391
|
unduck() {
|
|
3843
4392
|
if (!ctx || !duckGain) return;
|
|
3844
4393
|
const now = ctx.currentTime;
|
|
@@ -3858,17 +4407,38 @@ function createAudioEngine(setUi, onPlayed, onPlaybackRef, onAllPlayed) {
|
|
|
3858
4407
|
function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
3859
4408
|
let activeSessionId = null;
|
|
3860
4409
|
let focusedSessionId = null;
|
|
4410
|
+
const focusOwners = /* @__PURE__ */ new Map();
|
|
3861
4411
|
let focusOwnerTab = null;
|
|
3862
4412
|
let voiceActive = null;
|
|
3863
4413
|
let voiceOwnerTab = null;
|
|
3864
4414
|
const busGen = globalThis[BUS_GEN_KEY] = (globalThis[BUS_GEN_KEY] ?? 0) + 1;
|
|
4415
|
+
const focusWarned = /* @__PURE__ */ new Set();
|
|
3865
4416
|
const postFocus = (sessionId) => {
|
|
3866
|
-
void
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
4417
|
+
void reportFocus({
|
|
4418
|
+
sessionId,
|
|
4419
|
+
fetchImpl: () => fetch(`${location.origin}${basePath}/focus`, {
|
|
4420
|
+
method: "POST",
|
|
4421
|
+
headers: { "content-type": "application/json" },
|
|
4422
|
+
body: JSON.stringify({ sessionId, tabId: TAB_ID }),
|
|
4423
|
+
signal: AbortSignal.timeout(3e3)
|
|
4424
|
+
}).then((r) => ({ status: r.status })),
|
|
4425
|
+
// 补报前复核焦点是否已变:403 → 等 800ms 期间用户切到别的会话 → 补报会把**旧**
|
|
4426
|
+
// 会话重新 POST → host 的焦点归属指回旧会话(当前会话不朗读、旧会话被朗读)。
|
|
4427
|
+
stillRelevant: () => focusedSessionId === sessionId,
|
|
4428
|
+
// 留痕文案放在 client.tsx(mic-gesture.ts 不在 strings-coverage 白名单里)。
|
|
4429
|
+
// 日志文案用英文:本仓红线禁止 console.* 里出现中文字面量(见 strings-coverage)。
|
|
4430
|
+
// 含义:/focus 被 host 拒绝(host 不认识这个会话 = 会话表滞后)→ 焦点静默失败,
|
|
4431
|
+
// readAloud=always 可能整页不朗读而用户看不到原因。
|
|
4432
|
+
// 每会话只留一次痕:反复切标签页/可见性变化会反复触发 postFocus。
|
|
4433
|
+
warn: ({ sessionId: warnedSession, status }) => {
|
|
4434
|
+
if (warnedSession !== null) {
|
|
4435
|
+
if (focusWarned.has(warnedSession)) return;
|
|
4436
|
+
focusWarned.add(warnedSession);
|
|
4437
|
+
}
|
|
4438
|
+
console.warn(
|
|
4439
|
+
"[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"
|
|
4440
|
+
);
|
|
4441
|
+
}
|
|
3872
4442
|
});
|
|
3873
4443
|
};
|
|
3874
4444
|
const DEFAULT_BOOT = {
|
|
@@ -3886,6 +4456,7 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
3886
4456
|
bargeInMode: "detect",
|
|
3887
4457
|
echoGateDb: 6,
|
|
3888
4458
|
shortcut: "Ctrl+Shift+V",
|
|
4459
|
+
composerShortcut: "Alt+Enter",
|
|
3889
4460
|
wakeWord: "",
|
|
3890
4461
|
toolBeep: false,
|
|
3891
4462
|
captionFontSize: 0,
|
|
@@ -4085,6 +4656,7 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4085
4656
|
if (source) return;
|
|
4086
4657
|
source = new EventSource(`${location.origin}${basePath}/stream?tabId=${encodeURIComponent(TAB_ID)}`);
|
|
4087
4658
|
source.addEventListener("open", () => {
|
|
4659
|
+
engine.resetFallback();
|
|
4088
4660
|
rejectSeqUpTo.clear();
|
|
4089
4661
|
lastFinalSeq.clear();
|
|
4090
4662
|
curSentenceId = null;
|
|
@@ -4102,13 +4674,18 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4102
4674
|
source.addEventListener("replaced", () => {
|
|
4103
4675
|
source?.close();
|
|
4104
4676
|
source = null;
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4677
|
+
handleReplaced({
|
|
4678
|
+
staleBus: globalThis[BUS_GEN_KEY] !== busGen,
|
|
4679
|
+
renewTabId: () => {
|
|
4680
|
+
TAB_ID = getTabId(true);
|
|
4681
|
+
return TAB_ID;
|
|
4682
|
+
},
|
|
4683
|
+
reconnect: () => connect(),
|
|
4684
|
+
retire: () => {
|
|
4685
|
+
ui.sseDown = true;
|
|
4686
|
+
notify();
|
|
4687
|
+
}
|
|
4688
|
+
});
|
|
4112
4689
|
});
|
|
4113
4690
|
source.addEventListener("display", (e) => {
|
|
4114
4691
|
try {
|
|
@@ -4116,6 +4693,7 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4116
4693
|
notify();
|
|
4117
4694
|
} catch {
|
|
4118
4695
|
}
|
|
4696
|
+
settingsScopeInvalidate?.();
|
|
4119
4697
|
});
|
|
4120
4698
|
source.addEventListener("focus", (e) => {
|
|
4121
4699
|
try {
|
|
@@ -4164,8 +4742,19 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4164
4742
|
source.addEventListener("turn", (e) => {
|
|
4165
4743
|
try {
|
|
4166
4744
|
const ev = JSON.parse(e.data);
|
|
4167
|
-
if (ev.state === "agent-speaking" && ev.sessionId
|
|
4168
|
-
|
|
4745
|
+
if (ev.state === "agent-speaking" && ev.sessionId) {
|
|
4746
|
+
const sameRoundContinuation = toolPending.has(ev.sessionId);
|
|
4747
|
+
toolPending.delete(ev.sessionId);
|
|
4748
|
+
const turn = typeof ev.turn === "number" ? ev.turn : void 0;
|
|
4749
|
+
const r = applyTurnEvent({
|
|
4750
|
+
turn,
|
|
4751
|
+
identity: { lastTurn: currentTurn.get(ev.sessionId) },
|
|
4752
|
+
hasStopLine: rejectSeqUpTo.get(ev.sessionId) === STOP_READING_LINE,
|
|
4753
|
+
untilNextRun: stopUntilRun.has(ev.sessionId),
|
|
4754
|
+
sameRoundContinuation
|
|
4755
|
+
});
|
|
4756
|
+
if (r.identity.lastTurn !== void 0) currentTurn.set(ev.sessionId, r.identity.lastTurn);
|
|
4757
|
+
if (r.release) rejectSeqUpTo.delete(ev.sessionId);
|
|
4169
4758
|
}
|
|
4170
4759
|
if (ev.sessionId === activeSessionId && ev.state) {
|
|
4171
4760
|
ui.turn = ev.state;
|
|
@@ -4258,6 +4847,7 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4258
4847
|
source.addEventListener("tool", (e) => {
|
|
4259
4848
|
try {
|
|
4260
4849
|
const p = JSON.parse(e.data);
|
|
4850
|
+
if (p.sessionId) toolPending.add(p.sessionId);
|
|
4261
4851
|
if (p.sessionId === activeSessionId && ui.boot.toolBeep === true) playToolBeep();
|
|
4262
4852
|
} catch {
|
|
4263
4853
|
}
|
|
@@ -4266,6 +4856,8 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4266
4856
|
connect();
|
|
4267
4857
|
const rejectSeqUpTo = /* @__PURE__ */ new Map();
|
|
4268
4858
|
const stopUntilRun = /* @__PURE__ */ new Set();
|
|
4859
|
+
const toolPending = /* @__PURE__ */ new Set();
|
|
4860
|
+
const currentTurn = /* @__PURE__ */ new Map();
|
|
4269
4861
|
const lastFinalSeq = /* @__PURE__ */ new Map();
|
|
4270
4862
|
let curSentenceId = null;
|
|
4271
4863
|
let curChunks = [];
|
|
@@ -4382,11 +4974,14 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4382
4974
|
return playingEndAt + ECHO_TAIL_MS + refDelaySamples / SAMPLE_RATE_16K * 1e3;
|
|
4383
4975
|
},
|
|
4384
4976
|
async enter(sessionId) {
|
|
4977
|
+
engine.resetFallback();
|
|
4385
4978
|
try {
|
|
4386
4979
|
const res = await fetch(`${location.origin}${basePath}/toggle`, {
|
|
4387
4980
|
method: "POST",
|
|
4388
4981
|
headers: { "content-type": "application/json" },
|
|
4389
|
-
body: JSON.stringify({ sessionId, on: true, tabId: TAB_ID, lang: activeLocale() })
|
|
4982
|
+
body: JSON.stringify({ sessionId, on: true, tabId: TAB_ID, lang: activeLocale() }),
|
|
4983
|
+
signal: AbortSignal.timeout(TOGGLE_TIMEOUT_MS)
|
|
4984
|
+
// I-7:宿主无响应不再让按钮永久 pending
|
|
4390
4985
|
});
|
|
4391
4986
|
const out = await res.json();
|
|
4392
4987
|
activeSessionId = out.active === sessionId ? sessionId : null;
|
|
@@ -4400,10 +4995,18 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4400
4995
|
error: out.active === sessionId ? void 0 : t("enterFail")
|
|
4401
4996
|
};
|
|
4402
4997
|
} catch {
|
|
4998
|
+
void fetch(`${location.origin}${basePath}/toggle`, {
|
|
4999
|
+
method: "POST",
|
|
5000
|
+
headers: { "content-type": "application/json" },
|
|
5001
|
+
body: JSON.stringify({ sessionId, on: false, tabId: TAB_ID }),
|
|
5002
|
+
signal: AbortSignal.timeout(TOGGLE_TIMEOUT_MS)
|
|
5003
|
+
}).catch(() => {
|
|
5004
|
+
});
|
|
4403
5005
|
return { ok: false, error: t("enterFail") };
|
|
4404
5006
|
}
|
|
4405
5007
|
},
|
|
4406
5008
|
async exit(sessionId, keepAudio) {
|
|
5009
|
+
engine.resetFallback();
|
|
4407
5010
|
resetTelemetry();
|
|
4408
5011
|
ui.turn = "idle";
|
|
4409
5012
|
if (!keepAudio) {
|
|
@@ -4413,7 +5016,9 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4413
5016
|
const res = await fetch(`${location.origin}${basePath}/toggle`, {
|
|
4414
5017
|
method: "POST",
|
|
4415
5018
|
headers: { "content-type": "application/json" },
|
|
4416
|
-
body: JSON.stringify({ sessionId, on: false, tabId: TAB_ID })
|
|
5019
|
+
body: JSON.stringify({ sessionId, on: false, tabId: TAB_ID }),
|
|
5020
|
+
signal: AbortSignal.timeout(TOGGLE_TIMEOUT_MS)
|
|
5021
|
+
// I-7
|
|
4417
5022
|
});
|
|
4418
5023
|
await res.json();
|
|
4419
5024
|
activeSessionId = null;
|
|
@@ -4472,13 +5077,19 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4472
5077
|
if (rejectSeqUpTo.get(sessionId) === STOP_READING_LINE) rejectSeqUpTo.delete(sessionId);
|
|
4473
5078
|
stopUntilRun.delete(sessionId);
|
|
4474
5079
|
},
|
|
4475
|
-
setFocusedSession(sessionId) {
|
|
5080
|
+
setFocusedSession(sessionId, owner = FOCUS_OWNER_DEFAULT) {
|
|
4476
5081
|
if (sessionId === null) {
|
|
4477
|
-
|
|
4478
|
-
|
|
5082
|
+
const { changed, focused } = focusRelease(focusOwners, owner);
|
|
5083
|
+
if (!changed) return;
|
|
5084
|
+
focusedSessionId = focused;
|
|
5085
|
+
if (focused !== null) {
|
|
5086
|
+
if (typeof document === "undefined" || document.visibilityState === "visible") postFocus(focused);
|
|
5087
|
+
return;
|
|
5088
|
+
}
|
|
4479
5089
|
if (focusOwnerTab === TAB_ID) postFocus(null);
|
|
4480
5090
|
return;
|
|
4481
5091
|
}
|
|
5092
|
+
focusClaim(focusOwners, owner, sessionId);
|
|
4482
5093
|
focusedSessionId = sessionId;
|
|
4483
5094
|
if (typeof document === "undefined" || document.visibilityState === "visible") postFocus(sessionId);
|
|
4484
5095
|
},
|
|
@@ -4492,7 +5103,9 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4492
5103
|
void fetch(`${location.origin}${basePath}/cancel`, {
|
|
4493
5104
|
method: "POST",
|
|
4494
5105
|
headers: { "content-type": "application/json" },
|
|
4495
|
-
|
|
5106
|
+
// reason=stop-reading:host 据此**不**动回合闸门(否则「停止朗读」后的排空分支
|
|
5107
|
+
// 会补发 tts-idle → mode:once 提前退出,R15 Important-1 回归)。
|
|
5108
|
+
body: cancelPayload({ sessionId: sid, keepAsr: true, reason: "stop-reading" }),
|
|
4496
5109
|
signal: AbortSignal.timeout(3e3)
|
|
4497
5110
|
}).catch(() => {
|
|
4498
5111
|
});
|
|
@@ -4594,7 +5207,8 @@ function MicMenu({ scope, anchor, onClose }) {
|
|
|
4594
5207
|
e.preventDefault();
|
|
4595
5208
|
const items = Array.from(menuRef.current?.querySelectorAll("button") ?? []);
|
|
4596
5209
|
const i = items.indexOf(document.activeElement);
|
|
4597
|
-
|
|
5210
|
+
const next = menuFocusIndex(i, items.length, e.key === "ArrowDown" ? 1 : -1);
|
|
5211
|
+
if (next >= 0) items[next]?.focus();
|
|
4598
5212
|
};
|
|
4599
5213
|
document.addEventListener("pointerdown", onDown, true);
|
|
4600
5214
|
document.addEventListener("keydown", onKey, true);
|
|
@@ -4651,6 +5265,7 @@ function MicButton({
|
|
|
4651
5265
|
const sidRef = (0, import_react3.useRef)(sessionId);
|
|
4652
5266
|
const engineRef = (0, import_react3.useRef)(null);
|
|
4653
5267
|
const micReadyRef = (0, import_react3.useRef)(false);
|
|
5268
|
+
const enterEpochRef = (0, import_react3.useRef)(0);
|
|
4654
5269
|
const actionsRef = (0, import_react3.useRef)(inputActions);
|
|
4655
5270
|
const submitTimerRef = (0, import_react3.useRef)(null);
|
|
4656
5271
|
const autoSendTimerRef = (0, import_react3.useRef)(null);
|
|
@@ -4658,12 +5273,16 @@ function MicButton({
|
|
|
4658
5273
|
const idleWarnTimerRef = (0, import_react3.useRef)(null);
|
|
4659
5274
|
const idleWarnActiveRef = (0, import_react3.useRef)(false);
|
|
4660
5275
|
const idleClearErrorRef = (0, import_react3.useRef)(null);
|
|
5276
|
+
const idleUserActivityAtRef = (0, import_react3.useRef)(Date.now());
|
|
4661
5277
|
const runningRef = (0, import_react3.useRef)(false);
|
|
4662
5278
|
const mountedRef = (0, import_react3.useRef)(true);
|
|
4663
5279
|
const holdCtrlRef = (0, import_react3.useRef)(false);
|
|
4664
5280
|
const manualHoldRef = (0, import_react3.useRef)(false);
|
|
4665
5281
|
const breakRef = (0, import_react3.useRef)(null);
|
|
4666
5282
|
const pausedForHiddenRef = (0, import_react3.useRef)(false);
|
|
5283
|
+
const focusOwnerRef = (0, import_react3.useRef)(null);
|
|
5284
|
+
if (focusOwnerRef.current === null) focusOwnerRef.current = `mic-${++focusOwnerSeq}`;
|
|
5285
|
+
const focusOwner = focusOwnerRef.current;
|
|
4667
5286
|
const onceRef = (0, import_react3.useRef)(null);
|
|
4668
5287
|
const [onceWaiting, setOnceWaiting] = (0, import_react3.useState)(false);
|
|
4669
5288
|
const [onceEnding, setOnceEnding] = (0, import_react3.useState)(false);
|
|
@@ -4683,6 +5302,7 @@ function MicButton({
|
|
|
4683
5302
|
bargeInMode: "detect",
|
|
4684
5303
|
echoGateDb: 6,
|
|
4685
5304
|
shortcut: "Ctrl+Shift+V",
|
|
5305
|
+
composerShortcut: "Alt+Enter",
|
|
4686
5306
|
wakeWord: "",
|
|
4687
5307
|
toolBeep: false,
|
|
4688
5308
|
captionFontSize: 0,
|
|
@@ -4714,7 +5334,7 @@ function MicButton({
|
|
|
4714
5334
|
};
|
|
4715
5335
|
const fetchConfig = async () => {
|
|
4716
5336
|
try {
|
|
4717
|
-
const res = await fetch(`${location.origin}${BASE_PATH2}/config
|
|
5337
|
+
const res = await fetch(`${location.origin}${BASE_PATH2}/config`, { signal: AbortSignal.timeout(TOGGLE_TIMEOUT_MS) });
|
|
4718
5338
|
if (!res.ok) return bootNow();
|
|
4719
5339
|
const c = await res.json();
|
|
4720
5340
|
const cur = bootNow();
|
|
@@ -4730,6 +5350,7 @@ function MicButton({
|
|
|
4730
5350
|
bargeInMode: c.bargeInMode === "manual" ? "manual" : c.bargeInMode === "detect" ? "detect" : "auto",
|
|
4731
5351
|
echoGateDb: typeof c.echoGateDb === "number" ? Math.min(12, Math.max(3, c.echoGateDb)) : cur.echoGateDb,
|
|
4732
5352
|
shortcut: typeof c.shortcut === "string" ? c.shortcut : cur.shortcut,
|
|
5353
|
+
composerShortcut: typeof c.composerShortcut === "string" ? c.composerShortcut : cur.composerShortcut,
|
|
4733
5354
|
wakeWord: typeof c.wakeWord === "string" ? c.wakeWord : cur.wakeWord,
|
|
4734
5355
|
toolBeep: c.toolBeep === true,
|
|
4735
5356
|
// 批 3:fetchConfig 是白名单拼接(plan §5.2 措辞「通用透传」与此处源码不符——见 commit message)
|
|
@@ -4755,6 +5376,12 @@ function MicButton({
|
|
|
4755
5376
|
return bootNow();
|
|
4756
5377
|
}
|
|
4757
5378
|
};
|
|
5379
|
+
const idleBusyNow = () => idleBusy({
|
|
5380
|
+
playing: bus.ui.playing,
|
|
5381
|
+
turn: bus.ui.turn,
|
|
5382
|
+
running: runningRef.current,
|
|
5383
|
+
hidden: document.hidden
|
|
5384
|
+
});
|
|
4758
5385
|
const clearIdle = () => {
|
|
4759
5386
|
if (idleTimerRef.current) {
|
|
4760
5387
|
clearTimeout(idleTimerRef.current);
|
|
@@ -4773,12 +5400,22 @@ function MicButton({
|
|
|
4773
5400
|
bus.setUi({ idleWarn: false });
|
|
4774
5401
|
}
|
|
4775
5402
|
};
|
|
4776
|
-
const resetIdle = () => {
|
|
5403
|
+
const resetIdle = (userActivity = true) => {
|
|
4777
5404
|
clearIdle();
|
|
5405
|
+
if (userActivity) idleUserActivityAtRef.current = Date.now();
|
|
4778
5406
|
const idleMs = (bootNow().idleTimeoutMinutes > 0 ? bootNow().idleTimeoutMinutes : 10) * 60 * 1e3;
|
|
4779
5407
|
if (idleMs > 3e4) {
|
|
4780
5408
|
idleWarnTimerRef.current = setTimeout(() => {
|
|
4781
5409
|
idleWarnTimerRef.current = null;
|
|
5410
|
+
const action = idleAction({
|
|
5411
|
+
busy: idleBusyNow(),
|
|
5412
|
+
warn: true,
|
|
5413
|
+
sinceUserActivityMs: Date.now() - idleUserActivityAtRef.current
|
|
5414
|
+
});
|
|
5415
|
+
if (action === "renew") {
|
|
5416
|
+
resetIdle(false);
|
|
5417
|
+
return;
|
|
5418
|
+
}
|
|
4782
5419
|
idleWarnActiveRef.current = true;
|
|
4783
5420
|
bus.setUi({ idleWarn: true });
|
|
4784
5421
|
}, idleMs - 3e4);
|
|
@@ -4787,6 +5424,15 @@ function MicButton({
|
|
|
4787
5424
|
idleTimerRef.current = null;
|
|
4788
5425
|
const sid = sidRef.current;
|
|
4789
5426
|
if (localRef.current === "on" && sid) {
|
|
5427
|
+
const action = idleAction({
|
|
5428
|
+
busy: idleBusyNow(),
|
|
5429
|
+
warn: false,
|
|
5430
|
+
sinceUserActivityMs: Date.now() - idleUserActivityAtRef.current
|
|
5431
|
+
});
|
|
5432
|
+
if (action === "renew") {
|
|
5433
|
+
resetIdle(false);
|
|
5434
|
+
return;
|
|
5435
|
+
}
|
|
4790
5436
|
const quitMsg = t("idleTimeoutQuit");
|
|
4791
5437
|
void exitModeRef.current("idle").then(() => {
|
|
4792
5438
|
bus.setUi({ error: bus.ui.error ?? quitMsg });
|
|
@@ -5018,6 +5664,9 @@ function MicButton({
|
|
|
5018
5664
|
};
|
|
5019
5665
|
const exitMode = async (reason) => {
|
|
5020
5666
|
if (localRef.current === "off") return;
|
|
5667
|
+
pendingHoldRef.current = false;
|
|
5668
|
+
pendingHoldReleaseRef.current = false;
|
|
5669
|
+
clearHoldExit();
|
|
5021
5670
|
setLocalMode("off");
|
|
5022
5671
|
clearOnce();
|
|
5023
5672
|
clearIdle();
|
|
@@ -5045,6 +5694,10 @@ function MicButton({
|
|
|
5045
5694
|
const sid = sidRef.current;
|
|
5046
5695
|
if (sid) await bus.exit(sid, reason === "typing");
|
|
5047
5696
|
};
|
|
5697
|
+
const cancelPending = () => {
|
|
5698
|
+
enterEpochRef.current++;
|
|
5699
|
+
void exitModeRef.current("manual");
|
|
5700
|
+
};
|
|
5048
5701
|
const enterMode = async () => {
|
|
5049
5702
|
const sid = sidRef.current;
|
|
5050
5703
|
if (!sid || localRef.current !== "off") return;
|
|
@@ -5052,10 +5705,11 @@ function MicButton({
|
|
|
5052
5705
|
isSpeechFalseRun = 0;
|
|
5053
5706
|
micReadyRef.current = false;
|
|
5054
5707
|
setLocalMode("pending");
|
|
5708
|
+
const myEnter = ++enterEpochRef.current;
|
|
5055
5709
|
try {
|
|
5056
5710
|
const entered = await bus.enter(sid);
|
|
5057
|
-
if (!mountedRef.current) {
|
|
5058
|
-
if (entered.ok) void bus.exit(sid);
|
|
5711
|
+
if (!mountedRef.current || enterEpochRef.current !== myEnter) {
|
|
5712
|
+
if (entered.ok && localRef.current === "off") void bus.exit(sid);
|
|
5059
5713
|
return;
|
|
5060
5714
|
}
|
|
5061
5715
|
if (!entered.ok) {
|
|
@@ -5068,6 +5722,10 @@ function MicButton({
|
|
|
5068
5722
|
return;
|
|
5069
5723
|
}
|
|
5070
5724
|
const cfg = await fetchConfig();
|
|
5725
|
+
if (enterEpochRef.current !== myEnter) {
|
|
5726
|
+
if (localRef.current === "off") void bus.exit(sid);
|
|
5727
|
+
return;
|
|
5728
|
+
}
|
|
5071
5729
|
const basePath = cfg.basePath;
|
|
5072
5730
|
const silenceMs = cfg.silenceMs;
|
|
5073
5731
|
const interruptLevel = cfg.interruptLevel;
|
|
@@ -5097,7 +5755,13 @@ function MicButton({
|
|
|
5097
5755
|
method: "POST",
|
|
5098
5756
|
headers: { "content-type": "application/json" },
|
|
5099
5757
|
// hold 按压中保留 host ASR 段(松手定稿续传前半句,防吃句)。
|
|
5100
|
-
|
|
5758
|
+
// reason=interrupt:host 据此可收口回合闸门(abandonTurn)——用户打断与
|
|
5759
|
+
// 「停止朗读」靠它区分(两者 keepAsr 都可能是 true,载荷本身区分不了)。
|
|
5760
|
+
body: cancelPayload({
|
|
5761
|
+
sessionId: sidRef.current,
|
|
5762
|
+
keepAsr: engineRef.current?.holding === true,
|
|
5763
|
+
reason: "interrupt"
|
|
5764
|
+
}),
|
|
5101
5765
|
signal: AbortSignal.timeout(3e3)
|
|
5102
5766
|
}).catch(() => {
|
|
5103
5767
|
});
|
|
@@ -5124,6 +5788,8 @@ function MicButton({
|
|
|
5124
5788
|
echo: bus.echoForAsr(),
|
|
5125
5789
|
// 回声尾音宽限:playing 或尾音窗口内均视为朗读中,防句播完瞬间的残响漏入 ASR。
|
|
5126
5790
|
isPlaying: () => bus.ui.playing || Date.now() < bus.playingTailUntil(),
|
|
5791
|
+
// I-18:裸播放态(不含尾窗),预录环/抢救种子以它划句边界。
|
|
5792
|
+
isPlayingRaw: () => bus.ui.playing,
|
|
5127
5793
|
// 打断根治阶段二:服务端 Silero VAD 帧级检测下行 → 驱动打断(替代 RMS 能量快
|
|
5128
5794
|
// 路径)。连续 confirmFrames 次 true(墙钟节拍 100ms/拍,三档确认约 0.3/0.2/0.1s)
|
|
5129
5795
|
// 判真实人声前沿;仅 AI 朗读中(bus.ui.playing)触发 hardBreak,
|
|
@@ -5189,7 +5855,10 @@ function MicButton({
|
|
|
5189
5855
|
isSpeechFalseRun++;
|
|
5190
5856
|
if (isSpeechFalseRun >= 2) {
|
|
5191
5857
|
isSpeechFalseRun = 0;
|
|
5192
|
-
isSpeechTrueCount =
|
|
5858
|
+
isSpeechTrueCount = decayConfirmCount(
|
|
5859
|
+
isSpeechTrueCount,
|
|
5860
|
+
() => engineRef.current?.invalidateSalvageSeed()
|
|
5861
|
+
);
|
|
5193
5862
|
if (isSpeechTrueCount === 0) interruptFirstAt = 0;
|
|
5194
5863
|
}
|
|
5195
5864
|
}
|
|
@@ -5305,6 +5974,16 @@ function MicButton({
|
|
|
5305
5974
|
resetIdle();
|
|
5306
5975
|
submitInFlightRef.current = false;
|
|
5307
5976
|
bus.setUi({ partial: "" });
|
|
5977
|
+
if (holdReleaseExitRef.current && meta?.force) {
|
|
5978
|
+
clearHoldExit();
|
|
5979
|
+
if (bootNow().autoSend === false) {
|
|
5980
|
+
setTimeout(() => {
|
|
5981
|
+
if (!holdPtrRef.current) void exitModeRef.current("manual");
|
|
5982
|
+
}, 300);
|
|
5983
|
+
} else {
|
|
5984
|
+
beginOnceWait();
|
|
5985
|
+
}
|
|
5986
|
+
}
|
|
5308
5987
|
const actions = actionsRef.current;
|
|
5309
5988
|
const trimmed = text.trim();
|
|
5310
5989
|
if (!trimmed) return;
|
|
@@ -5320,6 +5999,7 @@ function MicButton({
|
|
|
5320
5999
|
}
|
|
5321
6000
|
if (meta?.force) {
|
|
5322
6001
|
cancelAutoSend();
|
|
6002
|
+
if (bootNow().mode === "hold" && bootNow().autoSend === false) return;
|
|
5323
6003
|
submitDraftNow(nextDraft);
|
|
5324
6004
|
return;
|
|
5325
6005
|
}
|
|
@@ -5335,10 +6015,10 @@ function MicButton({
|
|
|
5335
6015
|
return;
|
|
5336
6016
|
}
|
|
5337
6017
|
await engine.start();
|
|
5338
|
-
if (!mountedRef.current) {
|
|
5339
|
-
engineRef.current = null;
|
|
6018
|
+
if (!mountedRef.current || enterEpochRef.current !== myEnter) {
|
|
6019
|
+
if (engineRef.current === engine) engineRef.current = null;
|
|
5340
6020
|
await engine.stop();
|
|
5341
|
-
void bus.exit(sid);
|
|
6021
|
+
if (!mountedRef.current || localRef.current === "off") void bus.exit(sid);
|
|
5342
6022
|
return;
|
|
5343
6023
|
}
|
|
5344
6024
|
if (bus.activeSessionId !== sid) {
|
|
@@ -5350,7 +6030,26 @@ function MicButton({
|
|
|
5350
6030
|
micReadyRef.current = true;
|
|
5351
6031
|
setLocalMode("on");
|
|
5352
6032
|
resetIdle();
|
|
6033
|
+
if (pendingHoldRef.current) {
|
|
6034
|
+
pendingHoldRef.current = false;
|
|
6035
|
+
if (holdPtrRef.current) {
|
|
6036
|
+
setHolding(true);
|
|
6037
|
+
engineRef.current?.beginHeld();
|
|
6038
|
+
} else if (pendingHoldReleaseRef.current) {
|
|
6039
|
+
pendingHoldReleaseRef.current = false;
|
|
6040
|
+
engineRef.current?.endHeld(true);
|
|
6041
|
+
if (holdReleaseExitRef.current) {
|
|
6042
|
+
clearHoldExit();
|
|
6043
|
+
void exitModeRef.current("manual");
|
|
6044
|
+
}
|
|
6045
|
+
}
|
|
6046
|
+
}
|
|
5353
6047
|
} catch (e) {
|
|
6048
|
+
if (enterEpochRef.current !== myEnter) return;
|
|
6049
|
+
engineRef.current = null;
|
|
6050
|
+
pendingHoldRef.current = false;
|
|
6051
|
+
pendingHoldReleaseRef.current = false;
|
|
6052
|
+
clearHoldExit();
|
|
5354
6053
|
setLocalMode("off");
|
|
5355
6054
|
const msg = e instanceof DOMException ? e.name === "NotAllowedError" ? t("micDenied") : (
|
|
5356
6055
|
// UX:NotReadableError = 麦克风被占用(其他程序/标签页)——与「不可用」
|
|
@@ -5371,6 +6070,7 @@ function MicButton({
|
|
|
5371
6070
|
if (!takeToggleSlot(toggleHistRef.current, Date.now())) return;
|
|
5372
6071
|
if (localRef.current === "on") void exitModeRef.current("manual");
|
|
5373
6072
|
else if (localRef.current === "off") void enterMode();
|
|
6073
|
+
else if (localRef.current === "pending") cancelPending();
|
|
5374
6074
|
};
|
|
5375
6075
|
const toggleRef = (0, import_react3.useRef)(toggle);
|
|
5376
6076
|
toggleRef.current = toggle;
|
|
@@ -5382,6 +6082,32 @@ function MicButton({
|
|
|
5382
6082
|
(0, import_react3.useEffect)(() => {
|
|
5383
6083
|
sidRef.current = sessionId;
|
|
5384
6084
|
}, [sessionId]);
|
|
6085
|
+
(0, import_react3.useEffect)(() => {
|
|
6086
|
+
const onChanged = () => {
|
|
6087
|
+
void fetchConfig();
|
|
6088
|
+
};
|
|
6089
|
+
window.addEventListener("dshvm-settings-changed", onChanged);
|
|
6090
|
+
return () => window.removeEventListener("dshvm-settings-changed", onChanged);
|
|
6091
|
+
}, []);
|
|
6092
|
+
(0, import_react3.useEffect)(() => {
|
|
6093
|
+
const onComposerKey = (e) => {
|
|
6094
|
+
const el = e.target;
|
|
6095
|
+
const editable = el instanceof HTMLElement && (el.tagName === "TEXTAREA" || el.tagName === "INPUT" || el.isContentEditable);
|
|
6096
|
+
if (!editable || e.isComposing) return;
|
|
6097
|
+
if (el.closest("[data-dshvm-settings]")) return;
|
|
6098
|
+
const combo = parseShortcut(bootNow().composerShortcut);
|
|
6099
|
+
if (!combo) return;
|
|
6100
|
+
const key = e.key.toLowerCase();
|
|
6101
|
+
const codeKey = (e.code || "").replace(/^Key/, "").replace(/^Digit/, "").toLowerCase();
|
|
6102
|
+
if (key !== combo.key && codeKey !== combo.key) return;
|
|
6103
|
+
if (e.ctrlKey !== combo.ctrl || e.shiftKey !== combo.shift || e.altKey !== combo.alt || e.metaKey !== combo.meta) return;
|
|
6104
|
+
e.preventDefault();
|
|
6105
|
+
e.stopPropagation();
|
|
6106
|
+
if (!e.repeat) toggleRef.current();
|
|
6107
|
+
};
|
|
6108
|
+
window.addEventListener("keydown", onComposerKey, true);
|
|
6109
|
+
return () => window.removeEventListener("keydown", onComposerKey, true);
|
|
6110
|
+
}, []);
|
|
5385
6111
|
const autoResumeTriedForRef = (0, import_react3.useRef)(null);
|
|
5386
6112
|
const autoResumeHintTimerRef = (0, import_react3.useRef)(null);
|
|
5387
6113
|
(0, import_react3.useEffect)(() => {
|
|
@@ -5421,14 +6147,14 @@ function MicButton({
|
|
|
5421
6147
|
(0, import_react3.useEffect)(() => bus.subscribe(() => checkOnce()), [bus]);
|
|
5422
6148
|
(0, import_react3.useEffect)(() => {
|
|
5423
6149
|
if (!sessionId) return;
|
|
5424
|
-
bus.setFocusedSession(sessionId);
|
|
6150
|
+
bus.setFocusedSession(sessionId, focusOwner);
|
|
5425
6151
|
const onVis = () => {
|
|
5426
|
-
if (document.visibilityState === "visible") bus.setFocusedSession(sessionId);
|
|
6152
|
+
if (document.visibilityState === "visible") bus.setFocusedSession(sessionId, focusOwner);
|
|
5427
6153
|
};
|
|
5428
6154
|
document.addEventListener("visibilitychange", onVis);
|
|
5429
6155
|
return () => {
|
|
5430
6156
|
document.removeEventListener("visibilitychange", onVis);
|
|
5431
|
-
bus.setFocusedSession(null);
|
|
6157
|
+
bus.setFocusedSession(null, focusOwner);
|
|
5432
6158
|
};
|
|
5433
6159
|
}, [bus, sessionId]);
|
|
5434
6160
|
(0, import_react3.useEffect)(() => {
|
|
@@ -5631,8 +6357,30 @@ function MicButton({
|
|
|
5631
6357
|
t("buttonListening")
|
|
5632
6358
|
) : local === "pending" ? t("entering") : t("voiceBtn");
|
|
5633
6359
|
const holdPtrRef = (0, import_react3.useRef)(null);
|
|
6360
|
+
const auxClickRef = (0, import_react3.useRef)(false);
|
|
5634
6361
|
const toggleHoldRef = (0, import_react3.useRef)(false);
|
|
5635
6362
|
const suppressClickUntilRef = (0, import_react3.useRef)(0);
|
|
6363
|
+
const pendingHoldRef = (0, import_react3.useRef)(false);
|
|
6364
|
+
const pendingHoldReleaseRef = (0, import_react3.useRef)(false);
|
|
6365
|
+
const holdReleaseExitRef = (0, import_react3.useRef)(false);
|
|
6366
|
+
const pressFromOffRef = (0, import_react3.useRef)(false);
|
|
6367
|
+
const holdExitFallbackRef = (0, import_react3.useRef)(null);
|
|
6368
|
+
function clearHoldExit() {
|
|
6369
|
+
holdReleaseExitRef.current = false;
|
|
6370
|
+
if (holdExitFallbackRef.current) clearTimeout(holdExitFallbackRef.current);
|
|
6371
|
+
holdExitFallbackRef.current = null;
|
|
6372
|
+
}
|
|
6373
|
+
function armHoldExit() {
|
|
6374
|
+
clearHoldExit();
|
|
6375
|
+
holdReleaseExitRef.current = true;
|
|
6376
|
+
holdExitFallbackRef.current = setTimeout(() => {
|
|
6377
|
+
holdExitFallbackRef.current = null;
|
|
6378
|
+
if (holdReleaseExitRef.current && !holdPtrRef.current && !onceRef.current) {
|
|
6379
|
+
holdReleaseExitRef.current = false;
|
|
6380
|
+
void exitModeRef.current("manual");
|
|
6381
|
+
}
|
|
6382
|
+
}, 25e3);
|
|
6383
|
+
}
|
|
5636
6384
|
const breakTimerRef = (0, import_react3.useRef)(null);
|
|
5637
6385
|
const breakDotsTimerRef = (0, import_react3.useRef)(null);
|
|
5638
6386
|
const clearBreakTimer = () => {
|
|
@@ -5687,10 +6435,24 @@ function MicButton({
|
|
|
5687
6435
|
return () => el.removeEventListener("touchstart", onTouchStart);
|
|
5688
6436
|
}, []);
|
|
5689
6437
|
const onPointerDown = (e) => {
|
|
6438
|
+
auxClickRef.current = auxClickPending(e.button, { mac: IS_MAC, ctrlKey: e.ctrlKey });
|
|
6439
|
+
if (!isPrimaryPress(e.button, { mac: IS_MAC, ctrlKey: e.ctrlKey })) return;
|
|
5690
6440
|
lockSelection();
|
|
5691
|
-
holdPtrRef.current = { t: Date.now(), y: e.clientY, id: e.pointerId };
|
|
6441
|
+
holdPtrRef.current = { t: Date.now(), y: e.clientY, id: e.pointerId, button: e.button };
|
|
5692
6442
|
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
5693
6443
|
if (bootNow().mode === "hold") {
|
|
6444
|
+
pressFromOffRef.current = localRef.current === "off";
|
|
6445
|
+
clearHoldExit();
|
|
6446
|
+
if (localRef.current === "off" && !readingOutside()) {
|
|
6447
|
+
pendingHoldRef.current = true;
|
|
6448
|
+
pendingHoldReleaseRef.current = false;
|
|
6449
|
+
void enterMode().finally(() => {
|
|
6450
|
+
pendingHoldRef.current = false;
|
|
6451
|
+
pendingHoldReleaseRef.current = false;
|
|
6452
|
+
if (localRef.current !== "on") clearHoldExit();
|
|
6453
|
+
});
|
|
6454
|
+
return;
|
|
6455
|
+
}
|
|
5694
6456
|
if (localRef.current === "on") {
|
|
5695
6457
|
setHolding(true);
|
|
5696
6458
|
const eng = engineRef.current;
|
|
@@ -5728,11 +6490,21 @@ function MicButton({
|
|
|
5728
6490
|
};
|
|
5729
6491
|
const onPointerUp = (e) => {
|
|
5730
6492
|
const p = holdPtrRef.current;
|
|
6493
|
+
const action = pointerUpAction(p, { id: e.pointerId, button: e.button });
|
|
6494
|
+
if (action === "ignore") return;
|
|
5731
6495
|
holdPtrRef.current = null;
|
|
5732
6496
|
clearBreakTimer();
|
|
6497
|
+
if (action === "unarmed" || !p) return;
|
|
5733
6498
|
setHolding(false);
|
|
5734
|
-
if (!p || p.id !== e.pointerId) return;
|
|
5735
6499
|
const ms = Date.now() - p.t;
|
|
6500
|
+
if (pendingHoldRef.current) {
|
|
6501
|
+
pendingHoldReleaseRef.current = true;
|
|
6502
|
+
if (ms >= 250) {
|
|
6503
|
+
armHoldExit();
|
|
6504
|
+
suppressClickUntilRef.current = Date.now() + 500;
|
|
6505
|
+
}
|
|
6506
|
+
return;
|
|
6507
|
+
}
|
|
5736
6508
|
if (bootNow().mode !== "hold") {
|
|
5737
6509
|
if (toggleHoldRef.current) {
|
|
5738
6510
|
toggleHoldRef.current = false;
|
|
@@ -5750,18 +6522,29 @@ function MicButton({
|
|
|
5750
6522
|
bus.stopReading(!!useSession);
|
|
5751
6523
|
return;
|
|
5752
6524
|
}
|
|
6525
|
+
if (localRef.current === "on" && pressFromOffRef.current) {
|
|
6526
|
+
engineRef.current?.endHeld(true);
|
|
6527
|
+
return;
|
|
6528
|
+
}
|
|
5753
6529
|
if (!takeToggleSlot(toggleHistRef.current, Date.now())) return;
|
|
5754
6530
|
if (localRef.current === "on") {
|
|
5755
6531
|
engineRef.current?.endHeld(true);
|
|
5756
6532
|
void exitModeRef.current("manual");
|
|
6533
|
+
} else if (localRef.current === "pending") {
|
|
6534
|
+
cancelPending();
|
|
5757
6535
|
} else {
|
|
5758
6536
|
void enterMode();
|
|
5759
6537
|
}
|
|
5760
6538
|
return;
|
|
5761
6539
|
}
|
|
5762
|
-
if (localRef.current === "on")
|
|
6540
|
+
if (localRef.current === "on") {
|
|
6541
|
+
engineRef.current?.endHeld(false);
|
|
6542
|
+
armHoldExit();
|
|
6543
|
+
suppressClickUntilRef.current = Date.now() + 500;
|
|
6544
|
+
}
|
|
5763
6545
|
};
|
|
5764
6546
|
const onPointerCancel = () => {
|
|
6547
|
+
if (!holdPtrRef.current && !toggleHoldRef.current) return;
|
|
5765
6548
|
holdPtrRef.current = null;
|
|
5766
6549
|
toggleHoldRef.current = false;
|
|
5767
6550
|
clearBreakTimer();
|
|
@@ -5778,10 +6561,7 @@ function MicButton({
|
|
|
5778
6561
|
const bars = Array.from(el.querySelectorAll(".dshvm-eq i"));
|
|
5779
6562
|
const base = eqKind === "out" ? [6, 10, 14, 10, 6] : [6, 12, 8];
|
|
5780
6563
|
const paint = (lv) => bars.forEach((b, i) => b.style.height = `${Math.max(3, base[i] * (0.35 + 0.65 * lv)).toFixed(1)}px`);
|
|
5781
|
-
|
|
5782
|
-
paint(1);
|
|
5783
|
-
return;
|
|
5784
|
-
}
|
|
6564
|
+
const mq = typeof matchMedia === "function" ? matchMedia("(prefers-reduced-motion: reduce)") : null;
|
|
5785
6565
|
let smooth = 0;
|
|
5786
6566
|
let raf = 0;
|
|
5787
6567
|
const tick = () => {
|
|
@@ -5790,8 +6570,33 @@ function MicButton({
|
|
|
5790
6570
|
paint(smooth);
|
|
5791
6571
|
raf = requestAnimationFrame(tick);
|
|
5792
6572
|
};
|
|
5793
|
-
|
|
5794
|
-
|
|
6573
|
+
const apply2 = () => {
|
|
6574
|
+
if (eqPaintMode(mq?.matches === true) === "static-full") {
|
|
6575
|
+
if (raf) {
|
|
6576
|
+
cancelAnimationFrame(raf);
|
|
6577
|
+
raf = 0;
|
|
6578
|
+
}
|
|
6579
|
+
paint(1);
|
|
6580
|
+
return;
|
|
6581
|
+
}
|
|
6582
|
+
if (!raf) {
|
|
6583
|
+
smooth = 0;
|
|
6584
|
+
tick();
|
|
6585
|
+
}
|
|
6586
|
+
};
|
|
6587
|
+
apply2();
|
|
6588
|
+
let detach = null;
|
|
6589
|
+
if (mq && typeof mq.addEventListener === "function") {
|
|
6590
|
+
mq.addEventListener("change", apply2);
|
|
6591
|
+
detach = () => mq.removeEventListener("change", apply2);
|
|
6592
|
+
} else if (mq && typeof mq.addListener === "function") {
|
|
6593
|
+
mq.addListener(apply2);
|
|
6594
|
+
detach = () => mq.removeListener(apply2);
|
|
6595
|
+
}
|
|
6596
|
+
return () => {
|
|
6597
|
+
if (raf) cancelAnimationFrame(raf);
|
|
6598
|
+
detach?.();
|
|
6599
|
+
};
|
|
5795
6600
|
}, [eqKind, bus]);
|
|
5796
6601
|
const showTimer = on && !statusBarShown && !onceWaiting;
|
|
5797
6602
|
const [elapsed, setElapsed] = (0, import_react3.useState)(0);
|
|
@@ -5815,12 +6620,24 @@ function MicButton({
|
|
|
5815
6620
|
className: "dshvm-mic",
|
|
5816
6621
|
"data-state": visual,
|
|
5817
6622
|
onClick: (e) => {
|
|
6623
|
+
if (isAuxClickToIgnore(auxClickRef.current, e.detail)) {
|
|
6624
|
+
auxClickRef.current = false;
|
|
6625
|
+
return;
|
|
6626
|
+
}
|
|
5818
6627
|
if (Date.now() < suppressClickUntilRef.current) return;
|
|
6628
|
+
if (localRef.current === "on" && (bus.ui.playing || onceRef.current)) {
|
|
6629
|
+
bus.stopReading(!!useSession);
|
|
6630
|
+
void exitModeRef.current("manual");
|
|
6631
|
+
return;
|
|
6632
|
+
}
|
|
5819
6633
|
if (holdMode && !readingOutside()) {
|
|
5820
6634
|
if (e.detail !== 0) return;
|
|
5821
6635
|
}
|
|
5822
6636
|
toggle();
|
|
5823
6637
|
},
|
|
6638
|
+
onMouseDown: (e) => {
|
|
6639
|
+
e.preventDefault();
|
|
6640
|
+
},
|
|
5824
6641
|
onPointerDown,
|
|
5825
6642
|
onPointerMove,
|
|
5826
6643
|
onPointerUp,
|
|
@@ -5956,8 +6773,6 @@ function VoiceStatusBar({ bus, sessionId }) {
|
|
|
5956
6773
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
5957
6774
|
"div",
|
|
5958
6775
|
{
|
|
5959
|
-
role: "status",
|
|
5960
|
-
"aria-live": "polite",
|
|
5961
6776
|
style: {
|
|
5962
6777
|
display: "flex",
|
|
5963
6778
|
flexDirection: "column",
|
|
@@ -5976,6 +6791,7 @@ function VoiceStatusBar({ bus, sessionId }) {
|
|
|
5976
6791
|
botBars.some((v) => v > 0) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
5977
6792
|
"span",
|
|
5978
6793
|
{
|
|
6794
|
+
"aria-hidden": "true",
|
|
5979
6795
|
title: t("botLevelsHint"),
|
|
5980
6796
|
style: {
|
|
5981
6797
|
display: "inline-flex",
|
|
@@ -5998,7 +6814,7 @@ function VoiceStatusBar({ bus, sessionId }) {
|
|
|
5998
6814
|
))
|
|
5999
6815
|
}
|
|
6000
6816
|
),
|
|
6001
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { display: "inline-flex", alignItems: "flex-end", gap: 2, height: 14, flexShrink: 0 }, children: bars.map((v, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
6817
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "aria-hidden": "true", style: { display: "inline-flex", alignItems: "flex-end", gap: 2, height: 14, flexShrink: 0 }, children: bars.map((v, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
6002
6818
|
"span",
|
|
6003
6819
|
{
|
|
6004
6820
|
className: "dshvm-bar",
|
|
@@ -6010,7 +6826,32 @@ function VoiceStatusBar({ bus, sessionId }) {
|
|
|
6010
6826
|
},
|
|
6011
6827
|
i
|
|
6012
6828
|
)) }),
|
|
6013
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
6829
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
6830
|
+
"span",
|
|
6831
|
+
{
|
|
6832
|
+
"data-dshvm": "status-text",
|
|
6833
|
+
role: "status",
|
|
6834
|
+
"aria-live": "polite",
|
|
6835
|
+
"aria-atomic": "true",
|
|
6836
|
+
style: {
|
|
6837
|
+
position: "absolute",
|
|
6838
|
+
width: 1,
|
|
6839
|
+
height: 1,
|
|
6840
|
+
overflow: "hidden",
|
|
6841
|
+
clip: "rect(0 0 0 0)",
|
|
6842
|
+
whiteSpace: "nowrap"
|
|
6843
|
+
},
|
|
6844
|
+
children: b.ui.error || (b.ui.sseDown ? t("sseReconnect") : "") || b.ui.notice || (b.ui.idleWarn ? t("idleWarn30s") : "") || (b.ui.state === "transcribing" ? t("recognizing") : stateText)
|
|
6845
|
+
}
|
|
6846
|
+
),
|
|
6847
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
6848
|
+
"span",
|
|
6849
|
+
{
|
|
6850
|
+
"aria-hidden": "true",
|
|
6851
|
+
style: { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", flexGrow: 1 },
|
|
6852
|
+
children: b.ui.error ? b.ui.error : b.ui.sseDown ? t("sseReconnect") : b.ui.notice ? b.ui.notice : b.ui.idleWarn ? t("idleWarn30s") : b.ui.state === "loading-model" || b.ui.model ? b.ui.model ? `${t("loadingModel")} ${b.ui.model.file} ${b.ui.model.percent}%` : stateText : b.ui.playing || b.ui.turn === "agent-speaking" ? stateText : b.ui.state === "wake" && b.ui.partial ? `${stateText} \xB7 ${b.ui.partial}` : b.ui.partial ? b.ui.partial : b.ui.ttsNotice ? b.ui.ttsNotice : stateText
|
|
6853
|
+
}
|
|
6854
|
+
),
|
|
6014
6855
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
6015
6856
|
"button",
|
|
6016
6857
|
{
|
|
@@ -6034,6 +6875,7 @@ function VoiceStatusBar({ bus, sessionId }) {
|
|
|
6034
6875
|
b.ui.isSpeech === true && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
6035
6876
|
"span",
|
|
6036
6877
|
{
|
|
6878
|
+
"aria-hidden": "true",
|
|
6037
6879
|
title: t("vadDetected"),
|
|
6038
6880
|
style: {
|
|
6039
6881
|
flexShrink: 0,
|
|
@@ -6051,6 +6893,7 @@ function VoiceStatusBar({ bus, sessionId }) {
|
|
|
6051
6893
|
b.ui.ttsNotice && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
6052
6894
|
"span",
|
|
6053
6895
|
{
|
|
6896
|
+
"aria-hidden": "true",
|
|
6054
6897
|
title: b.ui.ttsNotice,
|
|
6055
6898
|
style: {
|
|
6056
6899
|
flexShrink: 0,
|
|
@@ -6072,6 +6915,7 @@ function VoiceStatusBar({ bus, sessionId }) {
|
|
|
6072
6915
|
elapsedSec > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
6073
6916
|
"span",
|
|
6074
6917
|
{
|
|
6918
|
+
"aria-hidden": "true",
|
|
6075
6919
|
title: t("elapsedHint"),
|
|
6076
6920
|
style: {
|
|
6077
6921
|
flexShrink: 0,
|
|
@@ -6093,6 +6937,7 @@ function VoiceStatusBar({ bus, sessionId }) {
|
|
|
6093
6937
|
b.ui.aecOff === true && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
6094
6938
|
"span",
|
|
6095
6939
|
{
|
|
6940
|
+
"aria-hidden": "true",
|
|
6096
6941
|
title: b.ui.bargeInDetectFallback ? t("bargeInDetectFallback") : t("aecOffHint"),
|
|
6097
6942
|
style: {
|
|
6098
6943
|
flexShrink: 0,
|
|
@@ -6128,6 +6973,7 @@ function VoiceStatusBar({ bus, sessionId }) {
|
|
|
6128
6973
|
telParts.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
6129
6974
|
"div",
|
|
6130
6975
|
{
|
|
6976
|
+
"aria-hidden": "true",
|
|
6131
6977
|
style: {
|
|
6132
6978
|
fontSize: 11,
|
|
6133
6979
|
color: "#8b949e",
|