@burdenoff/fe-libs 2026.1117.4 → 2026.1117.5
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/dist/shared/assistant/ui/useVoiceSession.js +312 -301
- package/dist/shared/assistant/voice/handsFree.d.ts +16 -0
- package/dist/shared/assistant/voice/handsFree.js +2 -2
- package/dist/shared/assistant/voice/handsfree/audioTrackTransport.js +1 -0
- package/dist/shared/assistant/voice/handsfree/backendStreamTransport.d.ts +11 -0
- package/dist/shared/assistant/voice/handsfree/backendStreamTransport.js +118 -63
- package/dist/shared/assistant/voice/handsfree/bargeIn.d.ts +20 -1
- package/dist/shared/assistant/voice/handsfree/bargeIn.js +3 -3
- package/dist/shared/assistant/voice/handsfree/handsFreeController.d.ts +10 -1
- package/dist/shared/assistant/voice/handsfree/handsFreeController.js +103 -83
- package/dist/shared/assistant/voice/handsfree/sttTransport.d.ts +20 -0
- package/dist/shared/assistant/voice/handsfree/useHandsFreeInterrupt.d.ts +8 -0
- package/dist/shared/assistant/voice/handsfree/useHandsFreeInterrupt.js +31 -26
- package/dist/shared/assistant/voice/handsfree/webSpeechTransport.js +1 -0
- package/dist/shared-assistant.js +399 -399
- package/package.json +1 -1
|
@@ -10,331 +10,335 @@ import { useLiveAvatarEchoReference as ie, useLiveAvatarOn as ae } from "./assis
|
|
|
10
10
|
import { captionChunks as oe } from "../voice/speechPlayback.js";
|
|
11
11
|
import { speechFeed as a } from "../speech/speechFeed.js";
|
|
12
12
|
import { planSubmitTimer as se, resolveVoiceGraceMs as ce } from "../voice/handsFree.js";
|
|
13
|
-
import { isTurnSuperseded as
|
|
14
|
-
import { INITIAL_SESSION as
|
|
15
|
-
import { useCallback as
|
|
13
|
+
import { isTurnSuperseded as le } from "../voice/supersededTurns.js";
|
|
14
|
+
import { INITIAL_SESSION as ue, INTERRUPT_MAX_MS as de, NOTHING_HEARD as fe, advanceHeardClock as pe, isCapturing as me, isSubmittable as he, planListeningHold as ge, planReplyConsumption as _e, planVoiceAnnouncement as ve, shouldRecognise as ye, spokenSoFar as o, voiceSessionReducer as be } from "../voice/voiceSession.js";
|
|
15
|
+
import { useCallback as s, useEffect as c, useLayoutEffect as xe, useMemo as Se, useReducer as Ce, useRef as l, useState as u } from "react";
|
|
16
16
|
// src/shared/assistant/ui/useVoiceSession.ts
|
|
17
|
-
var
|
|
18
|
-
function
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}, [
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
let e =
|
|
26
|
-
if (e && e !==
|
|
27
|
-
|
|
28
|
-
for (let [t, n] of
|
|
29
|
-
|
|
17
|
+
var we = 4e3, Te = 2500, Ee = 5e3, De = 12e3;
|
|
18
|
+
function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersede: Ae, handsFreeInterrupt: je, handsFreeStreamNoticeAccepted: Me, onAcceptHandsFreeStreamNotice: Ne, onBargeIn: Pe }) {
|
|
19
|
+
let p = ce(ke), m = l(null), Fe = s((e, t) => be(e, t, m.current), []), [h, g] = Ce(Fe, ue), _ = re(), { setSessionSpeaking: v, setSessionMicOpen: y, speakingMessageId: b, stop: x } = _, Ie = l(_.toggle), Le = _.toggle;
|
|
20
|
+
xe(() => {
|
|
21
|
+
Ie.current = Le;
|
|
22
|
+
}, [Le]);
|
|
23
|
+
let S = l(null), C = l({}), w = l(fe), T = l(void 0), E = l(void 0), Re = l(0), D = l(void 0), O = l(/* @__PURE__ */ new Map()), ze = l(void 0);
|
|
24
|
+
c(() => {
|
|
25
|
+
let e = h.correctionTimingDecision;
|
|
26
|
+
if (e && e !== ze.current) {
|
|
27
|
+
ze.current = e;
|
|
28
|
+
for (let [t, n] of O.current) e.accepted && t >= e.candidateId && (T.current = n.lastSpeechFrame ?? T.current, E.current = n.recognizerSpeechEnded ?? E.current), (e.accepted || t <= e.candidateId) && O.current.delete(t);
|
|
29
|
+
D.current !== void 0 && D.current <= e.candidateId && (D.current = void 0);
|
|
30
30
|
}
|
|
31
|
-
(
|
|
31
|
+
(h.phase !== "thinking" || h.muted) && (O.current.clear(), D.current = void 0), (h.phase === "idle" || h.phase === "ended") && (T.current = void 0, E.current = void 0);
|
|
32
32
|
}, [
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
h.phase,
|
|
34
|
+
h.muted,
|
|
35
|
+
h.correctionTimingDecision
|
|
36
36
|
]);
|
|
37
|
-
let
|
|
38
|
-
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
}, []),
|
|
37
|
+
let k = l(null), Be = l(!1), [Ve, A] = u(null), j = l(null), [He, M] = u(null), [N, P] = u(!1), [Ue, F] = u(!1), [I, L] = u(!1), R = l(h);
|
|
38
|
+
R.current = h;
|
|
39
|
+
let z = l([]), B = l(null), V = l(!1), H = s(() => {
|
|
40
|
+
z.current = [], B.current = null, V.current = !1;
|
|
41
|
+
}, []), U = s(() => {
|
|
42
42
|
for (;;) {
|
|
43
|
-
let e =
|
|
43
|
+
let e = z.current.shift();
|
|
44
44
|
if (!e) return !1;
|
|
45
45
|
if (!e.stillWanted || e.stillWanted()) {
|
|
46
|
-
|
|
46
|
+
B.current = e, m.current = m.current ? `${m.current} ${e.text}` : e.text;
|
|
47
47
|
try {
|
|
48
|
-
|
|
48
|
+
Ie.current(e.id, e.text, e.lang);
|
|
49
49
|
} catch {
|
|
50
|
-
|
|
50
|
+
B.current = null;
|
|
51
51
|
continue;
|
|
52
52
|
}
|
|
53
53
|
return !0;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
}, []),
|
|
57
|
-
let t =
|
|
56
|
+
}, []), W = l(!1), We = s((e) => {
|
|
57
|
+
let t = ge({
|
|
58
58
|
requested: e,
|
|
59
|
-
held:
|
|
60
|
-
muted:
|
|
59
|
+
held: W.current,
|
|
60
|
+
muted: R.current.muted
|
|
61
61
|
});
|
|
62
|
-
|
|
62
|
+
W.current = t.held, t.mute !== null && g({
|
|
63
63
|
type: "mute",
|
|
64
64
|
muted: t.mute
|
|
65
65
|
});
|
|
66
|
-
}, []),
|
|
67
|
-
let t =
|
|
68
|
-
t !== "drop" && (
|
|
69
|
-
}, []),
|
|
70
|
-
|
|
71
|
-
}, [
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
let e =
|
|
75
|
-
|
|
66
|
+
}, []), G = s((e) => {
|
|
67
|
+
let t = ve(R.current);
|
|
68
|
+
t !== "drop" && (B.current?.id === e.id || z.current.some((t) => t.id === e.id) || (z.current.push(e), t === "start" && !V.current && (V.current = !0, g({ type: "announce" }))));
|
|
69
|
+
}, []), Ge = s((e) => {
|
|
70
|
+
R.current.phase === "thinking" ? (z.current.push(e), V.current = !0, g({ type: "answered-locally" })) : G(e);
|
|
71
|
+
}, [G]), Ke = l(d);
|
|
72
|
+
Ke.current = d, c(() => {
|
|
73
|
+
if (h.phase === "speaking") {
|
|
74
|
+
let e = j.current;
|
|
75
|
+
m.current = e && k.current === e.id && d?.id !== e.id ? e.text : d?.text ?? null;
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
|
-
if (
|
|
78
|
+
if (m.current === null) return;
|
|
79
79
|
let e = setTimeout(() => {
|
|
80
|
-
|
|
81
|
-
},
|
|
80
|
+
m.current = null;
|
|
81
|
+
}, Te);
|
|
82
82
|
return () => clearTimeout(e);
|
|
83
|
-
}, [
|
|
84
|
-
let
|
|
85
|
-
|
|
86
|
-
let
|
|
87
|
-
let n =
|
|
83
|
+
}, [h.phase, d]);
|
|
84
|
+
let qe = l(f);
|
|
85
|
+
qe.current = f;
|
|
86
|
+
let Je = s((e, t) => {
|
|
87
|
+
let n = R.current;
|
|
88
88
|
if (!n.muted) {
|
|
89
89
|
if (n.phase === "thinking") {
|
|
90
|
-
e === "lastSpeechFrame" && (
|
|
91
|
-
let n =
|
|
92
|
-
r[e] = t,
|
|
93
|
-
} else n.phase === "listening" && (e === "lastSpeechFrame" ?
|
|
90
|
+
e === "lastSpeechFrame" && (D.current = void 0);
|
|
91
|
+
let n = D.current ?? Re.current, r = O.current.get(n) ?? {};
|
|
92
|
+
r[e] = t, O.current.set(n, r);
|
|
93
|
+
} else n.phase === "listening" && (e === "lastSpeechFrame" ? T.current = t : E.current = t);
|
|
94
94
|
}
|
|
95
|
-
}, []),
|
|
96
|
-
let t =
|
|
95
|
+
}, []), K = s((e) => {
|
|
96
|
+
let t = R.current;
|
|
97
97
|
if (t.phase !== "thinking" || t.muted) return;
|
|
98
|
-
let n =
|
|
99
|
-
return e && (
|
|
100
|
-
}, []),
|
|
101
|
-
|
|
98
|
+
let n = Re.current;
|
|
99
|
+
return e && (D.current = n, Re.current += 1), n;
|
|
100
|
+
}, []), q = s((e, t) => {
|
|
101
|
+
g({
|
|
102
102
|
type: "speech",
|
|
103
103
|
transcript: e,
|
|
104
104
|
final: t,
|
|
105
105
|
at: Date.now(),
|
|
106
|
-
language:
|
|
107
|
-
timingCandidateId:
|
|
106
|
+
language: qe.current,
|
|
107
|
+
timingCandidateId: K(t)
|
|
108
108
|
});
|
|
109
|
-
}, [
|
|
110
|
-
|
|
109
|
+
}, [K]), Ye = s((e, t, n) => {
|
|
110
|
+
g({
|
|
111
111
|
type: "speech",
|
|
112
112
|
transcript: e,
|
|
113
113
|
final: t,
|
|
114
114
|
at: Date.now(),
|
|
115
|
-
language: n ??
|
|
115
|
+
language: n ?? qe.current,
|
|
116
116
|
gated: !0,
|
|
117
|
-
timingCandidateId:
|
|
117
|
+
timingCandidateId: K(t)
|
|
118
118
|
});
|
|
119
|
-
}, [
|
|
120
|
-
|
|
121
|
-
}, [
|
|
122
|
-
onFinalize:
|
|
123
|
-
language:
|
|
124
|
-
deviceId:
|
|
119
|
+
}, [K]), Xe = l(0), Ze = s(() => {
|
|
120
|
+
H(), x(), Xe.current = Date.now(), P(!0), g({ type: "interrupt" });
|
|
121
|
+
}, [x, H]), Qe = s((e) => q(e, !0), [q]), $e = e((e) => e.micDeviceId), J = t({
|
|
122
|
+
onFinalize: Qe,
|
|
123
|
+
language: f,
|
|
124
|
+
deviceId: $e,
|
|
125
125
|
onSpeechEnd: (e) => {
|
|
126
|
-
|
|
126
|
+
Je("recognizerSpeechEnded", e);
|
|
127
127
|
}
|
|
128
|
-
}),
|
|
129
|
-
|
|
130
|
-
let
|
|
131
|
-
|
|
132
|
-
}, [
|
|
133
|
-
enabled: ee(
|
|
134
|
-
phase:
|
|
135
|
-
muted:
|
|
136
|
-
language:
|
|
137
|
-
streamNoticeAccepted:
|
|
138
|
-
onAcceptStreamNotice:
|
|
139
|
-
onBargeIn:
|
|
140
|
-
onTranscript:
|
|
128
|
+
}), et = J.stop, tt = l(Pe);
|
|
129
|
+
tt.current = Pe;
|
|
130
|
+
let nt = s(() => {
|
|
131
|
+
H(), te(), x(), Xe.current = Date.now(), P(!0), g({ type: "interrupt" }), tt.current?.();
|
|
132
|
+
}, [x, H]), rt = ae(), it = ie(), Y = n({
|
|
133
|
+
enabled: ee(je, r(), rt, it),
|
|
134
|
+
phase: h.phase,
|
|
135
|
+
muted: h.muted,
|
|
136
|
+
language: f,
|
|
137
|
+
streamNoticeAccepted: Me ?? null,
|
|
138
|
+
onAcceptStreamNotice: Ne,
|
|
139
|
+
onBargeIn: nt,
|
|
140
|
+
onTranscript: Ye,
|
|
141
141
|
onSpeechFrame: (e) => {
|
|
142
|
-
|
|
142
|
+
Je("lastSpeechFrame", e);
|
|
143
143
|
}
|
|
144
|
-
}),
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}, [
|
|
148
|
-
|
|
144
|
+
}), at = Y.mode === "notice", X = J.isListening || Y.suppressWebSpeech && Y.mode === "active";
|
|
145
|
+
c(() => {
|
|
146
|
+
J.interim && q(J.interim, !1);
|
|
147
|
+
}, [J.interim, q]), c(() => {
|
|
148
|
+
S.current && clearTimeout(S.current), F(!1), w.current = pe(w.current, h, i());
|
|
149
149
|
let e = se({
|
|
150
|
-
phase:
|
|
151
|
-
muted:
|
|
152
|
-
spoken:
|
|
153
|
-
holding:
|
|
154
|
-
graceMs:
|
|
150
|
+
phase: h.phase,
|
|
151
|
+
muted: h.muted,
|
|
152
|
+
spoken: o(h),
|
|
153
|
+
holding: I,
|
|
154
|
+
graceMs: p,
|
|
155
|
+
wordsPending: Y.wordsPending,
|
|
156
|
+
speechEndedAgoMs: Y.wordsAfterUtterance && T.current !== void 0 ? i() - T.current : null
|
|
155
157
|
});
|
|
156
158
|
if (!e.arm) return;
|
|
157
|
-
let t = setTimeout(() =>
|
|
158
|
-
return
|
|
159
|
-
|
|
160
|
-
speechEnded:
|
|
161
|
-
lastSpeechFrame:
|
|
162
|
-
recognizerSpeechEnded:
|
|
163
|
-
selectedGraceMs:
|
|
164
|
-
graceStarted:
|
|
159
|
+
let t = setTimeout(() => F(!0), Math.min(800, e.delayMs)), n = i(), r = n - (p - e.delayMs);
|
|
160
|
+
return S.current = setTimeout(() => {
|
|
161
|
+
C.current = {
|
|
162
|
+
speechEnded: Math.min(w.current.at ?? n, r),
|
|
163
|
+
lastSpeechFrame: T.current,
|
|
164
|
+
recognizerSpeechEnded: E.current,
|
|
165
|
+
selectedGraceMs: p,
|
|
166
|
+
graceStarted: r,
|
|
165
167
|
graceEnded: i()
|
|
166
|
-
},
|
|
168
|
+
}, g({
|
|
167
169
|
type: "silence",
|
|
168
170
|
at: Date.now()
|
|
169
171
|
});
|
|
170
172
|
}, e.delayMs), () => {
|
|
171
|
-
clearTimeout(t),
|
|
173
|
+
clearTimeout(t), S.current && clearTimeout(S.current);
|
|
172
174
|
};
|
|
173
175
|
}, [
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
176
|
+
h,
|
|
177
|
+
I,
|
|
178
|
+
p,
|
|
179
|
+
Y.wordsPending,
|
|
180
|
+
Y.wordsAfterUtterance
|
|
181
|
+
]), c(() => {
|
|
182
|
+
(h.phase !== "listening" || h.muted) && L(!1);
|
|
183
|
+
}, [h.phase, h.muted]), c(() => {
|
|
184
|
+
if (!N) return;
|
|
185
|
+
let e = Date.now() - Xe.current, t = X ? Math.max(0, 500 - e) : Math.max(0, de - e), n = setTimeout(() => P(!1), t);
|
|
182
186
|
return () => clearTimeout(n);
|
|
183
|
-
}, [
|
|
184
|
-
let
|
|
185
|
-
|
|
186
|
-
if (
|
|
187
|
-
|
|
188
|
-
let e =
|
|
189
|
-
e &&
|
|
190
|
-
}, [
|
|
191
|
-
let e =
|
|
192
|
-
e.claim && (
|
|
187
|
+
}, [N, X]);
|
|
188
|
+
let ot = l("");
|
|
189
|
+
h.phase === "listening" && (ot.current = o(h)), c(() => {
|
|
190
|
+
if (h.phase !== "thinking") return;
|
|
191
|
+
y(!1), H(), M((e) => typeof e == "object" && e ? null : e);
|
|
192
|
+
let e = ot.current.trim();
|
|
193
|
+
e && Oe(e, Z.current ?? `vs-orphan-${Date.now().toString(36)}`, C.current, { correction: R.current.correcting }), C.current = {}, w.current = fe, T.current = void 0, E.current = void 0;
|
|
194
|
+
}, [h.phase]), c(() => {
|
|
195
|
+
let e = _e(d?.id, h.phase, k.current, le(d?.id));
|
|
196
|
+
e.claim && (k.current = d?.id ?? null, e.advance && d && (d.refused ? (H(), M({
|
|
193
197
|
kind: "turn-refused",
|
|
194
|
-
text:
|
|
195
|
-
}),
|
|
198
|
+
text: d.text
|
|
199
|
+
}), g({ type: "turn-refused" })) : g({
|
|
196
200
|
type: "reply",
|
|
197
|
-
text:
|
|
201
|
+
text: d.text
|
|
198
202
|
})));
|
|
199
203
|
}, [
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
]),
|
|
204
|
-
if (
|
|
205
|
-
if (
|
|
206
|
-
|
|
204
|
+
d,
|
|
205
|
+
h.phase,
|
|
206
|
+
H
|
|
207
|
+
]), c(() => {
|
|
208
|
+
if (b === null || h.phase !== "thinking" || k.current === b) return;
|
|
209
|
+
if (le(b)) {
|
|
210
|
+
x();
|
|
207
211
|
return;
|
|
208
212
|
}
|
|
209
|
-
let e = a.peek(
|
|
210
|
-
e && e.final && e.channel === "voice" && e.voiceSessionId !== void 0 && e.voiceSessionId ===
|
|
211
|
-
id:
|
|
213
|
+
let e = a.peek(b);
|
|
214
|
+
e && e.final && e.channel === "voice" && e.voiceSessionId !== void 0 && e.voiceSessionId === Z.current && (k.current = b, j.current = {
|
|
215
|
+
id: b,
|
|
212
216
|
text: e.text
|
|
213
|
-
},
|
|
217
|
+
}, g({
|
|
214
218
|
type: "reply-audio-started",
|
|
215
|
-
replyId:
|
|
219
|
+
replyId: b
|
|
216
220
|
}));
|
|
217
221
|
}, [
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
]),
|
|
222
|
+
b,
|
|
223
|
+
h.phase,
|
|
224
|
+
x
|
|
225
|
+
]), c(() => a.subscribe((e) => {
|
|
222
226
|
if (e.type !== "audio") return;
|
|
223
|
-
let t =
|
|
227
|
+
let t = R.current.phase;
|
|
224
228
|
if (t !== "thinking" && t !== "speaking") return;
|
|
225
229
|
if (e.state === "retrying") {
|
|
226
|
-
if (
|
|
227
|
-
|
|
230
|
+
if (k.current !== e.messageId || j.current?.id !== e.messageId) return;
|
|
231
|
+
k.current = null, j.current = null, A(e.messageId), g({ type: "reply-audio-paused" });
|
|
228
232
|
return;
|
|
229
233
|
}
|
|
230
234
|
if (e.state === "ended") {
|
|
231
|
-
if (
|
|
235
|
+
if (k.current !== e.messageId || j.current?.id !== e.messageId) return;
|
|
232
236
|
let n = a.peek(e.messageId);
|
|
233
|
-
n?.channel === "voice" && n.voiceSessionId ===
|
|
237
|
+
n?.channel === "voice" && n.voiceSessionId === Z.current && (j.current = {
|
|
234
238
|
id: e.messageId,
|
|
235
239
|
text: n.text
|
|
236
|
-
}),
|
|
237
|
-
let r =
|
|
240
|
+
}), A(null);
|
|
241
|
+
let r = j.current;
|
|
238
242
|
t === "thinking" && queueMicrotask(() => {
|
|
239
|
-
|
|
243
|
+
j.current === r && R.current.phase === "thinking" && g({ type: "reply-audio-ended" });
|
|
240
244
|
});
|
|
241
245
|
return;
|
|
242
246
|
}
|
|
243
|
-
if (
|
|
247
|
+
if (le(e.messageId)) return;
|
|
244
248
|
let n = a.peek(e.messageId);
|
|
245
|
-
if (n && n.channel === "voice" && n.voiceSessionId ===
|
|
246
|
-
if (e.state === "queued")
|
|
249
|
+
if (n && n.channel === "voice" && n.voiceSessionId === Z.current) {
|
|
250
|
+
if (e.state === "queued") A(e.messageId), k.current = e.messageId, j.current = {
|
|
247
251
|
id: e.messageId,
|
|
248
252
|
text: n.text
|
|
249
|
-
},
|
|
250
|
-
else if (
|
|
251
|
-
else e.state === "started" ? (
|
|
253
|
+
}, et();
|
|
254
|
+
else if (k.current !== e.messageId) return;
|
|
255
|
+
else e.state === "started" ? (k.current = e.messageId, j.current = {
|
|
252
256
|
id: e.messageId,
|
|
253
257
|
text: n.text
|
|
254
|
-
},
|
|
258
|
+
}, g({
|
|
255
259
|
type: "reply-audio-started",
|
|
256
260
|
replyId: e.messageId,
|
|
257
261
|
partial: !n.final
|
|
258
|
-
})) : e.state === "paused" &&
|
|
262
|
+
})) : e.state === "paused" && k.current === e.messageId && g({ type: "reply-audio-paused" });
|
|
259
263
|
}
|
|
260
|
-
}), [
|
|
261
|
-
|
|
262
|
-
}, [
|
|
263
|
-
let e =
|
|
264
|
-
|
|
265
|
-
}, [
|
|
266
|
-
|
|
267
|
-
}, [
|
|
268
|
-
if (
|
|
264
|
+
}), [et]), c(() => {
|
|
265
|
+
h.phase !== "thinking" && h.phase !== "speaking" && A(null);
|
|
266
|
+
}, [h.phase]), c(() => {
|
|
267
|
+
let e = b !== null;
|
|
268
|
+
Be.current && !e && (B.current = null, R.current.phase === "speaking" && U() || g({ type: "speech-ended" })), Be.current = e;
|
|
269
|
+
}, [b, U]), c(() => {
|
|
270
|
+
h.phase !== "listening" && M((e) => e === "nothing-heard" ? null : e);
|
|
271
|
+
}, [h.phase]), c(() => {
|
|
272
|
+
if (h.phase !== "speaking" || b !== null) return;
|
|
269
273
|
let e = setTimeout(() => {
|
|
270
|
-
|
|
271
|
-
},
|
|
274
|
+
Be.current || (H(), g({ type: "speech-ended" }));
|
|
275
|
+
}, we);
|
|
272
276
|
return () => clearTimeout(e);
|
|
273
277
|
}, [
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
278
|
+
h.phase,
|
|
279
|
+
b,
|
|
280
|
+
H
|
|
277
281
|
]);
|
|
278
|
-
let
|
|
279
|
-
|
|
280
|
-
if (
|
|
281
|
-
let { phase: e } =
|
|
282
|
-
e !== "idle" && e !== "ended" && e !== "thinking" &&
|
|
283
|
-
}, [
|
|
284
|
-
|
|
285
|
-
}, [
|
|
286
|
-
let
|
|
287
|
-
|
|
288
|
-
let
|
|
289
|
-
|
|
290
|
-
let e =
|
|
291
|
-
e !==
|
|
282
|
+
let st = _.outputNotCleared;
|
|
283
|
+
c(() => {
|
|
284
|
+
if (st === null || k.current !== st.messageId) return;
|
|
285
|
+
let { phase: e } = R.current;
|
|
286
|
+
e !== "idle" && e !== "ended" && e !== "thinking" && M("reply-not-heard");
|
|
287
|
+
}, [st]), c(() => {
|
|
288
|
+
h.phase !== "listening" && h.phase !== "thinking" && M((e) => e === "reply-not-heard" ? null : e);
|
|
289
|
+
}, [h.phase]);
|
|
290
|
+
let ct = l(Ae);
|
|
291
|
+
ct.current = Ae;
|
|
292
|
+
let lt = l(0);
|
|
293
|
+
c(() => {
|
|
294
|
+
let e = h.superseded;
|
|
295
|
+
e !== lt.current && (lt.current = e, e !== 0 && (H(), x(), ct.current?.()));
|
|
292
296
|
}, [
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
]),
|
|
297
|
-
let e =
|
|
298
|
-
|
|
297
|
+
h.superseded,
|
|
298
|
+
H,
|
|
299
|
+
x
|
|
300
|
+
]), c(() => {
|
|
301
|
+
let e = me(h);
|
|
302
|
+
y(e), ye(h) && Ve === null && !Y.suppressWebSpeech ? J.isActive || J.start("auto") : J.isActive && J.stop();
|
|
299
303
|
}, [
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
]),
|
|
306
|
-
|
|
307
|
-
}, [
|
|
308
|
-
|
|
304
|
+
h,
|
|
305
|
+
J,
|
|
306
|
+
y,
|
|
307
|
+
Y.suppressWebSpeech,
|
|
308
|
+
Ve
|
|
309
|
+
]), c(() => {
|
|
310
|
+
h.phase === "speaking" && V.current && (V.current = !1, U() || g({ type: "speech-ended" }));
|
|
311
|
+
}, [h.phase, U]), c(() => {
|
|
312
|
+
J.error === "not-allowed" || J.error === "audio-capture" ? g({
|
|
309
313
|
type: "fail",
|
|
310
314
|
error: "mic-denied"
|
|
311
|
-
}) :
|
|
315
|
+
}) : J.error === "language-not-supported" ? g({
|
|
312
316
|
type: "fail",
|
|
313
317
|
error: "no-speech-support"
|
|
314
|
-
}) :
|
|
315
|
-
}, [
|
|
316
|
-
|
|
317
|
-
}, [
|
|
318
|
-
if (
|
|
319
|
-
let e = setTimeout(() =>
|
|
318
|
+
}) : J.error === "network" ? M("network") : J.error === "unknown" && M("recognition-failed");
|
|
319
|
+
}, [J.error]), c(() => {
|
|
320
|
+
J.error === null && X && M((e) => e === "network" || e === "recognition-failed" ? null : e);
|
|
321
|
+
}, [J.error, X]), c(() => {
|
|
322
|
+
if (X && M((e) => e === "not-capturing" ? null : e), !me(h) || X || at) return;
|
|
323
|
+
let e = setTimeout(() => M("not-capturing"), Ee);
|
|
320
324
|
return () => clearTimeout(e);
|
|
321
325
|
}, [
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
]),
|
|
326
|
-
if (
|
|
327
|
-
let e = setTimeout(() =>
|
|
326
|
+
h,
|
|
327
|
+
X,
|
|
328
|
+
at
|
|
329
|
+
]), c(() => {
|
|
330
|
+
if (h.phase !== "listening" || h.muted || !X || o(h) !== "") return;
|
|
331
|
+
let e = setTimeout(() => M("nothing-heard"), De);
|
|
328
332
|
return () => clearTimeout(e);
|
|
329
|
-
}, [
|
|
330
|
-
|
|
331
|
-
}, [
|
|
332
|
-
let
|
|
333
|
-
if (
|
|
333
|
+
}, [h, X]), c(() => {
|
|
334
|
+
o(h) !== "" && M(null);
|
|
335
|
+
}, [h]);
|
|
336
|
+
let Z = l(null), ut = s(() => {
|
|
337
|
+
if (P(!1), F(!1), L(!1), H(), W.current = !1, !J.isSupported) g({
|
|
334
338
|
type: "fail",
|
|
335
339
|
error: "no-speech-support"
|
|
336
340
|
});
|
|
337
|
-
else if (
|
|
341
|
+
else if (_.isBlocked) g({
|
|
338
342
|
type: "fail",
|
|
339
343
|
error: "no-voice-support"
|
|
340
344
|
});
|
|
@@ -346,101 +350,108 @@ function De({ onSubmit: De, latestReply: f, language: p, graceMs: Oe, onSupersed
|
|
|
346
350
|
t.volume = 0, e.speak(t);
|
|
347
351
|
}
|
|
348
352
|
} catch {}
|
|
349
|
-
ne(),
|
|
353
|
+
ne(), v(!0), M(null), k.current = Ke.current?.id ?? null, j.current = null, Z.current = `vs-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`, g({ type: "start" });
|
|
350
354
|
}
|
|
351
355
|
}, [
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
]),
|
|
357
|
-
|
|
356
|
+
J.isSupported,
|
|
357
|
+
_.isBlocked,
|
|
358
|
+
v,
|
|
359
|
+
H
|
|
360
|
+
]), dt = s(() => {
|
|
361
|
+
P(!1), F(!1), L(!1), H(), W.current = !1, Z.current = null, g({ type: "end" }), x(), v(!1);
|
|
358
362
|
}, [
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
]),
|
|
363
|
-
let e =
|
|
364
|
-
e.phase !== "listening" || e.muted ||
|
|
365
|
-
}, []),
|
|
366
|
-
R
|
|
367
|
-
|
|
368
|
-
if (e.phase !== "listening" || e.muted || !me(s(e))) return;
|
|
363
|
+
x,
|
|
364
|
+
v,
|
|
365
|
+
H
|
|
366
|
+
]), ft = s((e) => Z.current === e, []), pt = s(() => {
|
|
367
|
+
let e = R.current;
|
|
368
|
+
e.phase !== "listening" || e.muted || L(!0);
|
|
369
|
+
}, []), Q = s(() => {
|
|
370
|
+
let e = R.current;
|
|
371
|
+
if (e.phase !== "listening" || e.muted || !he(o(e))) return;
|
|
369
372
|
let t = i();
|
|
370
|
-
|
|
371
|
-
speechEnded:
|
|
372
|
-
lastSpeechFrame:
|
|
373
|
-
recognizerSpeechEnded:
|
|
374
|
-
selectedGraceMs:
|
|
373
|
+
C.current = {
|
|
374
|
+
speechEnded: w.current.at ?? t,
|
|
375
|
+
lastSpeechFrame: T.current,
|
|
376
|
+
recognizerSpeechEnded: E.current,
|
|
377
|
+
selectedGraceMs: p,
|
|
375
378
|
graceStarted: t,
|
|
376
379
|
graceEnded: t
|
|
377
|
-
},
|
|
380
|
+
}, g({
|
|
378
381
|
type: "silence",
|
|
379
382
|
at: Date.now()
|
|
380
383
|
});
|
|
381
|
-
}, [
|
|
382
|
-
|
|
384
|
+
}, [p]), $ = l(!1);
|
|
385
|
+
c(() => {
|
|
386
|
+
(h.phase !== "listening" || h.muted) && ($.current = !1);
|
|
387
|
+
}, [h.phase, h.muted]), c(() => {
|
|
388
|
+
!Y.wordsPending && $.current && ($.current = !1, Q());
|
|
389
|
+
}, [Y.wordsPending, Q]);
|
|
390
|
+
let mt = s(() => {
|
|
391
|
+
L(!1), Y.wordsPending ? $.current = !0 : Q();
|
|
392
|
+
}, [Y.wordsPending, Q]), ht = s(() => {
|
|
393
|
+
g({
|
|
383
394
|
type: "mute",
|
|
384
|
-
muted: !
|
|
395
|
+
muted: !R.current.muted
|
|
385
396
|
});
|
|
386
397
|
}, []);
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}, [
|
|
390
|
-
let
|
|
391
|
-
return
|
|
392
|
-
session:
|
|
393
|
-
notice:
|
|
394
|
-
spokenChunks:
|
|
395
|
-
capturing:
|
|
396
|
-
active:
|
|
397
|
-
interrupting:
|
|
398
|
-
awaitingEndpoint:
|
|
399
|
-
holding:
|
|
400
|
-
correcting:
|
|
398
|
+
c(() => () => {
|
|
399
|
+
v(!1), y(!1);
|
|
400
|
+
}, [v, y]);
|
|
401
|
+
let gt = oe(_.spokenChunks, h.phase, b);
|
|
402
|
+
return Se(() => ({
|
|
403
|
+
session: h,
|
|
404
|
+
notice: He ?? (Y.fallbackReason !== null && Y.fallbackReason !== "notice-declined" ? "hands-free-fallback" : Y.nothingHeard ? "hands-free-nothing-heard" : null),
|
|
405
|
+
spokenChunks: gt,
|
|
406
|
+
capturing: X,
|
|
407
|
+
active: h.phase !== "idle" && (h.phase !== "ended" || h.error !== null),
|
|
408
|
+
interrupting: N,
|
|
409
|
+
awaitingEndpoint: Ue,
|
|
410
|
+
holding: I,
|
|
411
|
+
correcting: h.correcting,
|
|
401
412
|
handsFree: {
|
|
402
|
-
mode:
|
|
403
|
-
nothingHeard:
|
|
404
|
-
transportKind:
|
|
405
|
-
fallbackReason:
|
|
406
|
-
privacyNotice:
|
|
413
|
+
mode: Y.mode,
|
|
414
|
+
nothingHeard: Y.nothingHeard,
|
|
415
|
+
transportKind: Y.transportKind,
|
|
416
|
+
fallbackReason: Y.fallbackReason,
|
|
417
|
+
privacyNotice: Y.privacyNotice
|
|
407
418
|
},
|
|
408
|
-
available:
|
|
409
|
-
start:
|
|
410
|
-
end:
|
|
411
|
-
isCurrentSession:
|
|
412
|
-
toggleMute:
|
|
413
|
-
interrupt:
|
|
414
|
-
letMeFinish:
|
|
415
|
-
imDone:
|
|
416
|
-
announce:
|
|
417
|
-
holdListening:
|
|
418
|
-
answerLocally:
|
|
419
|
+
available: J.isSupported && !_.isBlocked,
|
|
420
|
+
start: ut,
|
|
421
|
+
end: dt,
|
|
422
|
+
isCurrentSession: ft,
|
|
423
|
+
toggleMute: ht,
|
|
424
|
+
interrupt: Ze,
|
|
425
|
+
letMeFinish: pt,
|
|
426
|
+
imDone: mt,
|
|
427
|
+
announce: G,
|
|
428
|
+
holdListening: We,
|
|
429
|
+
answerLocally: Ge
|
|
419
430
|
}), [
|
|
420
|
-
|
|
421
|
-
Ve,
|
|
422
|
-
P,
|
|
431
|
+
h,
|
|
423
432
|
He,
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
X
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
Y.
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
433
|
+
N,
|
|
434
|
+
Ue,
|
|
435
|
+
I,
|
|
436
|
+
X,
|
|
437
|
+
Y.mode,
|
|
438
|
+
Y.nothingHeard,
|
|
439
|
+
Y.transportKind,
|
|
440
|
+
Y.fallbackReason,
|
|
441
|
+
Y.privacyNotice,
|
|
442
|
+
J.isSupported,
|
|
443
|
+
_.isBlocked,
|
|
444
|
+
gt,
|
|
436
445
|
ut,
|
|
437
|
-
pt,
|
|
438
|
-
Xe,
|
|
439
446
|
dt,
|
|
440
447
|
ft,
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
448
|
+
ht,
|
|
449
|
+
Ze,
|
|
450
|
+
pt,
|
|
451
|
+
mt,
|
|
452
|
+
G,
|
|
453
|
+
We,
|
|
454
|
+
Ge
|
|
444
455
|
]);
|
|
445
456
|
}
|
|
446
|
-
export {
|
|
457
|
+
export { Oe as useVoiceSession };
|