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