@burdenoff/fe-libs 2026.1118.8 → 2026.1118.9
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 +2 -0
- package/dist/shared/assistant/ui/useVoiceSession.js +188 -142
- package/dist/shared/assistant/voice/handsFree.d.ts +3 -1
- package/dist/shared/assistant/voice/handsfree/audioTrackTransport.d.ts +8 -0
- package/dist/shared/assistant/voice/handsfree/audioTrackTransport.js +36 -31
- package/dist/shared/assistant/voice/handsfree/backendStreamTransport.js +1 -0
- package/dist/shared/assistant/voice/handsfree/echoGate.d.ts +21 -0
- package/dist/shared/assistant/voice/handsfree/echoGate.js +11 -2
- package/dist/shared/assistant/voice/handsfree/handsFreeController.d.ts +7 -0
- package/dist/shared/assistant/voice/handsfree/handsFreeController.js +46 -42
- package/dist/shared/assistant/voice/handsfree/playbackReference.d.ts +63 -5
- package/dist/shared/assistant/voice/handsfree/playbackReference.js +56 -29
- package/dist/shared/assistant/voice/handsfree/preRollRing.d.ts +7 -0
- package/dist/shared/assistant/voice/handsfree/preRollRing.js +3 -0
- package/dist/shared/assistant/voice/handsfree/sttTransport.d.ts +16 -0
- package/dist/shared/assistant/voice/handsfree/useHandsFreeInterrupt.js +55 -54
- package/dist/shared/assistant/voice/handsfree/vad.d.ts +9 -0
- package/dist/shared/assistant/voice/handsfree/vad.js +10 -7
- package/dist/shared/assistant/voice/handsfree/webSpeechTransport.js +1 -0
- package/dist/shared/assistant/voice/thinkingTone.d.ts +213 -0
- package/dist/shared/assistant/voice/thinkingTone.js +182 -0
- package/dist/shared/assistant/voice/thinkingToneConfig.d.ts +4 -0
- package/dist/shared/assistant/voice/thinkingToneConfig.js +9 -0
- package/dist/shared/assistant/voice/voiceSession.d.ts +24 -0
- package/dist/shared/assistant/voice/voiceSession.js +18 -11
- package/dist/shared-assistant.js +404 -402
- package/package.json +1 -1
|
@@ -424,6 +424,8 @@ export * from './promptDelivery';
|
|
|
424
424
|
export * from './speech/appendSpeechQueue';
|
|
425
425
|
export * from './voice/phraseSpeechConfig';
|
|
426
426
|
export * from './voice/firstClipPrefetchConfig';
|
|
427
|
+
export * from './voice/thinkingToneConfig';
|
|
428
|
+
export * from './voice/thinkingTone';
|
|
427
429
|
export * from './voice/phraseGate';
|
|
428
430
|
export * from './voice/livePhraseSpeech';
|
|
429
431
|
export * from './voice/phrasePlayback';
|
|
@@ -11,20 +11,22 @@ 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
13
|
import { isTurnSuperseded as le } from "../voice/supersededTurns.js";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
14
|
+
import { THINKING_TONE_PHRASE_WAIT_MS as ue, createThinkingTonePlayer as de, planThinkingTone as fe, shouldPlayThinkingTone as pe, thinkingToneHeardUntil as me } from "../voice/thinkingTone.js";
|
|
15
|
+
import { thinkingToneEnabled as he } from "../voice/thinkingToneConfig.js";
|
|
16
|
+
import { INITIAL_SESSION as ge, INTERRUPT_MAX_MS as _e, NOTHING_HEARD as ve, advanceHeardClock as ye, isCapturing as be, isSubmittable as xe, planListeningHold as Se, planReplyConsumption as Ce, planVoiceAnnouncement as we, shouldRecognise as Te, spokenSoFar as o, voiceSessionReducer as Ee } from "../voice/voiceSession.js";
|
|
17
|
+
import { useCallback as s, useEffect as c, useLayoutEffect as De, useMemo as Oe, useReducer as ke, useRef as l, useState as u } from "react";
|
|
16
18
|
// src/shared/assistant/ui/useVoiceSession.ts
|
|
17
|
-
var
|
|
18
|
-
function
|
|
19
|
-
let p = ce(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}, [
|
|
23
|
-
let S = l(null), C = l({}), w = l(
|
|
19
|
+
var Ae = 4e3, je = 2500, Me = 5e3, Ne = 12e3;
|
|
20
|
+
function Pe({ onSubmit: Pe, latestReply: d, language: f, graceMs: Fe, onSupersede: Ie, handsFreeInterrupt: Le, handsFreeStreamNoticeAccepted: Re, onAcceptHandsFreeStreamNotice: ze, onBargeIn: Be }) {
|
|
21
|
+
let p = ce(Fe), m = l(null), Ve = s((e, t) => Ee(e, t, m.current), []), [h, g] = ke(Ve, ge), _ = re(), { setSessionSpeaking: v, setSessionMicOpen: y, speakingMessageId: b, stop: x } = _, He = l(_.toggle), Ue = _.toggle;
|
|
22
|
+
De(() => {
|
|
23
|
+
He.current = Ue;
|
|
24
|
+
}, [Ue]);
|
|
25
|
+
let S = l(null), C = l({}), w = l(ve), T = l(void 0), E = l(void 0), We = l(0), D = l(void 0), O = l(/* @__PURE__ */ new Map()), Ge = l(void 0);
|
|
24
26
|
c(() => {
|
|
25
27
|
let e = h.correctionTimingDecision;
|
|
26
|
-
if (e && e !==
|
|
27
|
-
|
|
28
|
+
if (e && e !== Ge.current) {
|
|
29
|
+
Ge.current = e;
|
|
28
30
|
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
31
|
D.current !== void 0 && D.current <= e.candidateId && (D.current = void 0);
|
|
30
32
|
}
|
|
@@ -34,7 +36,7 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
|
|
|
34
36
|
h.muted,
|
|
35
37
|
h.correctionTimingDecision
|
|
36
38
|
]);
|
|
37
|
-
let k = l(null),
|
|
39
|
+
let k = l(null), Ke = l(!1), [qe, A] = u(null), j = l(null), [Je, M] = u(null), [N, P] = u(!1), [Ye, F] = u(!1), [I, L] = u(!1), R = l(h);
|
|
38
40
|
R.current = h;
|
|
39
41
|
let z = l([]), B = l(null), V = l(!1), H = s(() => {
|
|
40
42
|
z.current = [], B.current = null, V.current = !1;
|
|
@@ -45,7 +47,7 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
|
|
|
45
47
|
if (!e.stillWanted || e.stillWanted()) {
|
|
46
48
|
B.current = e, m.current = m.current ? `${m.current} ${e.text}` : e.text;
|
|
47
49
|
try {
|
|
48
|
-
|
|
50
|
+
He.current(e.id, e.text, e.lang);
|
|
49
51
|
} catch {
|
|
50
52
|
B.current = null;
|
|
51
53
|
continue;
|
|
@@ -53,8 +55,8 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
|
|
|
53
55
|
return !0;
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
|
-
}, []), W = l(!1),
|
|
57
|
-
let t =
|
|
58
|
+
}, []), W = l(!1), Xe = s((e) => {
|
|
59
|
+
let t = Se({
|
|
58
60
|
requested: e,
|
|
59
61
|
held: W.current,
|
|
60
62
|
muted: R.current.muted
|
|
@@ -64,12 +66,12 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
|
|
|
64
66
|
muted: t.mute
|
|
65
67
|
});
|
|
66
68
|
}, []), G = s((e) => {
|
|
67
|
-
let t =
|
|
69
|
+
let t = we(R.current);
|
|
68
70
|
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
|
-
}, []),
|
|
71
|
+
}, []), Ze = s((e) => {
|
|
70
72
|
R.current.phase === "thinking" ? (z.current.push(e), V.current = !0, g({ type: "answered-locally" })) : G(e);
|
|
71
|
-
}, [G]),
|
|
72
|
-
|
|
73
|
+
}, [G]), Qe = l(d);
|
|
74
|
+
Qe.current = d, c(() => {
|
|
73
75
|
if (h.phase === "speaking") {
|
|
74
76
|
let e = j.current;
|
|
75
77
|
m.current = e && k.current === e.id && d?.id !== e.id ? e.text : d?.text ?? null;
|
|
@@ -78,82 +80,82 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
|
|
|
78
80
|
if (m.current === null) return;
|
|
79
81
|
let e = setTimeout(() => {
|
|
80
82
|
m.current = null;
|
|
81
|
-
},
|
|
83
|
+
}, je);
|
|
82
84
|
return () => clearTimeout(e);
|
|
83
85
|
}, [h.phase, d]);
|
|
84
|
-
let
|
|
85
|
-
|
|
86
|
-
let
|
|
86
|
+
let $e = l(f);
|
|
87
|
+
$e.current = f;
|
|
88
|
+
let et = s((e, t) => {
|
|
87
89
|
let n = R.current;
|
|
88
90
|
if (!n.muted) {
|
|
89
91
|
if (n.phase === "thinking") {
|
|
90
92
|
e === "lastSpeechFrame" && (D.current = void 0);
|
|
91
|
-
let n = D.current ??
|
|
93
|
+
let n = D.current ?? We.current, r = O.current.get(n) ?? {};
|
|
92
94
|
r[e] = t, O.current.set(n, r);
|
|
93
95
|
} else n.phase === "listening" && (e === "lastSpeechFrame" ? T.current = t : E.current = t);
|
|
94
96
|
}
|
|
95
97
|
}, []), K = s((e) => {
|
|
96
98
|
let t = R.current;
|
|
97
99
|
if (t.phase !== "thinking" || t.muted) return;
|
|
98
|
-
let n =
|
|
99
|
-
return e && (D.current = n,
|
|
100
|
+
let n = We.current;
|
|
101
|
+
return e && (D.current = n, We.current += 1), n;
|
|
100
102
|
}, []), q = s((e, t) => {
|
|
101
103
|
g({
|
|
102
104
|
type: "speech",
|
|
103
105
|
transcript: e,
|
|
104
106
|
final: t,
|
|
105
107
|
at: Date.now(),
|
|
106
|
-
language:
|
|
108
|
+
language: $e.current,
|
|
107
109
|
timingCandidateId: K(t)
|
|
108
110
|
});
|
|
109
|
-
}, [K]),
|
|
111
|
+
}, [K]), tt = s((e, t, n) => {
|
|
110
112
|
g({
|
|
111
113
|
type: "speech",
|
|
112
114
|
transcript: e,
|
|
113
115
|
final: t,
|
|
114
116
|
at: Date.now(),
|
|
115
|
-
language: n ??
|
|
117
|
+
language: n ?? $e.current,
|
|
116
118
|
gated: !0,
|
|
117
119
|
timingCandidateId: K(t)
|
|
118
120
|
});
|
|
119
|
-
}, [K]),
|
|
120
|
-
H(), x(),
|
|
121
|
-
}, [x, H]),
|
|
122
|
-
onFinalize:
|
|
121
|
+
}, [K]), nt = l(0), rt = s(() => {
|
|
122
|
+
H(), x(), nt.current = Date.now(), P(!0), g({ type: "interrupt" });
|
|
123
|
+
}, [x, H]), it = s((e) => q(e, !0), [q]), at = e((e) => e.micDeviceId), J = t({
|
|
124
|
+
onFinalize: it,
|
|
123
125
|
language: f,
|
|
124
|
-
deviceId:
|
|
126
|
+
deviceId: at,
|
|
125
127
|
onSpeechEnd: (e) => {
|
|
126
|
-
|
|
128
|
+
et("recognizerSpeechEnded", e);
|
|
127
129
|
}
|
|
128
|
-
}),
|
|
129
|
-
|
|
130
|
-
let
|
|
131
|
-
H(), te(), x(),
|
|
132
|
-
}, [x, H]),
|
|
133
|
-
enabled: ee(
|
|
130
|
+
}), ot = J.stop, st = l(Be);
|
|
131
|
+
st.current = Be;
|
|
132
|
+
let ct = s(() => {
|
|
133
|
+
H(), te(), x(), nt.current = Date.now(), P(!0), g({ type: "interrupt" }), st.current?.();
|
|
134
|
+
}, [x, H]), Y = ae(), lt = ie(), X = n({
|
|
135
|
+
enabled: ee(Le, r(), Y, lt),
|
|
134
136
|
phase: h.phase,
|
|
135
137
|
muted: h.muted,
|
|
136
138
|
language: f,
|
|
137
|
-
streamNoticeAccepted:
|
|
138
|
-
onAcceptStreamNotice:
|
|
139
|
-
onBargeIn:
|
|
140
|
-
onTranscript:
|
|
139
|
+
streamNoticeAccepted: Re ?? null,
|
|
140
|
+
onAcceptStreamNotice: ze,
|
|
141
|
+
onBargeIn: ct,
|
|
142
|
+
onTranscript: tt,
|
|
141
143
|
onSpeechFrame: (e) => {
|
|
142
|
-
|
|
144
|
+
et("lastSpeechFrame", e);
|
|
143
145
|
}
|
|
144
|
-
}),
|
|
146
|
+
}), ut = X.mode === "notice", Z = J.isListening || X.suppressWebSpeech && X.mode === "active";
|
|
145
147
|
c(() => {
|
|
146
148
|
J.interim && q(J.interim, !1);
|
|
147
149
|
}, [J.interim, q]), c(() => {
|
|
148
|
-
S.current && clearTimeout(S.current), F(!1), w.current =
|
|
150
|
+
S.current && clearTimeout(S.current), F(!1), h.phase !== "thinking" && (w.current = ye(w.current, h, i()));
|
|
149
151
|
let e = se({
|
|
150
152
|
phase: h.phase,
|
|
151
153
|
muted: h.muted,
|
|
152
154
|
spoken: o(h),
|
|
153
155
|
holding: I,
|
|
154
156
|
graceMs: p,
|
|
155
|
-
wordsPending:
|
|
156
|
-
speechEndedAgoMs:
|
|
157
|
+
wordsPending: X.wordsPending,
|
|
158
|
+
speechEndedAgoMs: X.wordsAfterUtterance && T.current !== void 0 ? i() - T.current : null
|
|
157
159
|
});
|
|
158
160
|
if (!e.arm) return;
|
|
159
161
|
let t = setTimeout(() => F(!0), Math.min(800, e.delayMs)), n = i(), r = n - (p - e.delayMs);
|
|
@@ -176,23 +178,66 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
|
|
|
176
178
|
h,
|
|
177
179
|
I,
|
|
178
180
|
p,
|
|
179
|
-
|
|
180
|
-
|
|
181
|
+
X.wordsPending,
|
|
182
|
+
X.wordsAfterUtterance
|
|
181
183
|
]), c(() => {
|
|
182
184
|
(h.phase !== "listening" || h.muted) && L(!1);
|
|
183
185
|
}, [h.phase, h.muted]), c(() => {
|
|
184
186
|
if (!N) return;
|
|
185
|
-
let e = Date.now() -
|
|
187
|
+
let e = Date.now() - nt.current, t = Z ? Math.max(0, 500 - e) : Math.max(0, _e - e), n = setTimeout(() => P(!1), t);
|
|
186
188
|
return () => clearTimeout(n);
|
|
187
|
-
}, [N,
|
|
188
|
-
let
|
|
189
|
-
h.phase === "listening" && (
|
|
189
|
+
}, [N, Z]);
|
|
190
|
+
let dt = l("");
|
|
191
|
+
h.phase === "listening" && (dt.current = o(h)), c(() => {
|
|
190
192
|
if (h.phase !== "thinking") return;
|
|
191
193
|
y(!1), H(), M((e) => typeof e == "object" && e ? null : e);
|
|
192
|
-
let e =
|
|
193
|
-
e &&
|
|
194
|
-
}, [h.phase])
|
|
195
|
-
|
|
194
|
+
let e = dt.current.trim();
|
|
195
|
+
e && Pe(e, $.current ?? `vs-orphan-${Date.now().toString(36)}`, C.current, { correction: R.current.correcting }), C.current = {}, w.current = ve, T.current = void 0, E.current = void 0;
|
|
196
|
+
}, [h.phase]);
|
|
197
|
+
let [Q] = u(de), ft = l(h.phase), pt = l(null), mt = J.interim.trim() !== "";
|
|
198
|
+
c(() => {
|
|
199
|
+
let e = ft.current;
|
|
200
|
+
ft.current = h.phase;
|
|
201
|
+
let t = he(), n = Date.now();
|
|
202
|
+
pe({
|
|
203
|
+
enabled: t,
|
|
204
|
+
from: e,
|
|
205
|
+
to: h.phase,
|
|
206
|
+
muted: h.muted,
|
|
207
|
+
avatarOn: Y
|
|
208
|
+
}) && (pt.current = n + ue);
|
|
209
|
+
let r = pt.current;
|
|
210
|
+
if (r === null) return;
|
|
211
|
+
let ee = fe({
|
|
212
|
+
enabled: t,
|
|
213
|
+
phase: h.phase,
|
|
214
|
+
muted: h.muted,
|
|
215
|
+
avatarOn: Y,
|
|
216
|
+
phraseOpen: mt,
|
|
217
|
+
now: n,
|
|
218
|
+
until: r
|
|
219
|
+
});
|
|
220
|
+
if (ee === "wait" || (pt.current = null, ee === "skip")) return;
|
|
221
|
+
let te = Q.play();
|
|
222
|
+
te !== null && g({
|
|
223
|
+
type: "thinking-tone",
|
|
224
|
+
until: me(Date.now(), te)
|
|
225
|
+
});
|
|
226
|
+
}, [
|
|
227
|
+
h.phase,
|
|
228
|
+
h.muted,
|
|
229
|
+
Y,
|
|
230
|
+
Q,
|
|
231
|
+
mt
|
|
232
|
+
]), c(() => {
|
|
233
|
+
h.phase === "ended" ? Q.dispose() : (h.phase === "listening" || h.muted || Y) && Q.stop();
|
|
234
|
+
}, [
|
|
235
|
+
h.phase,
|
|
236
|
+
h.muted,
|
|
237
|
+
Y,
|
|
238
|
+
Q
|
|
239
|
+
]), c(() => () => Q.dispose(), [Q]), c(() => {
|
|
240
|
+
let e = Ce(d?.id, h.phase, k.current, le(d?.id));
|
|
196
241
|
e.claim && (k.current = d?.id ?? null, e.advance && d && (d.refused ? (H(), M({
|
|
197
242
|
kind: "turn-refused",
|
|
198
243
|
text: d.text
|
|
@@ -211,7 +256,7 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
|
|
|
211
256
|
return;
|
|
212
257
|
}
|
|
213
258
|
let e = a.peek(b);
|
|
214
|
-
e && e.final && e.channel === "voice" && e.voiceSessionId !== void 0 && e.voiceSessionId ===
|
|
259
|
+
e && e.final && e.channel === "voice" && e.voiceSessionId !== void 0 && e.voiceSessionId === $.current && (k.current = b, j.current = {
|
|
215
260
|
id: b,
|
|
216
261
|
text: e.text
|
|
217
262
|
}, g({
|
|
@@ -234,7 +279,7 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
|
|
|
234
279
|
if (e.state === "ended") {
|
|
235
280
|
if (k.current !== e.messageId || j.current?.id !== e.messageId) return;
|
|
236
281
|
let n = a.peek(e.messageId);
|
|
237
|
-
n?.channel === "voice" && n.voiceSessionId ===
|
|
282
|
+
n?.channel === "voice" && n.voiceSessionId === $.current && (j.current = {
|
|
238
283
|
id: e.messageId,
|
|
239
284
|
text: n.text
|
|
240
285
|
}), A(null);
|
|
@@ -246,11 +291,11 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
|
|
|
246
291
|
}
|
|
247
292
|
if (le(e.messageId)) return;
|
|
248
293
|
let n = a.peek(e.messageId);
|
|
249
|
-
if (n && n.channel === "voice" && n.voiceSessionId ===
|
|
294
|
+
if (n && n.channel === "voice" && n.voiceSessionId === $.current) {
|
|
250
295
|
if (e.state === "queued") A(e.messageId), k.current = e.messageId, j.current = {
|
|
251
296
|
id: e.messageId,
|
|
252
297
|
text: n.text
|
|
253
|
-
},
|
|
298
|
+
}, ot();
|
|
254
299
|
else if (k.current !== e.messageId) return;
|
|
255
300
|
else e.state === "started" ? (k.current = e.messageId, j.current = {
|
|
256
301
|
id: e.messageId,
|
|
@@ -261,51 +306,51 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
|
|
|
261
306
|
partial: !n.final
|
|
262
307
|
})) : e.state === "paused" && k.current === e.messageId && g({ type: "reply-audio-paused" });
|
|
263
308
|
}
|
|
264
|
-
}), [
|
|
309
|
+
}), [ot]), c(() => {
|
|
265
310
|
h.phase !== "thinking" && h.phase !== "speaking" && A(null);
|
|
266
311
|
}, [h.phase]), c(() => {
|
|
267
312
|
let e = b !== null;
|
|
268
|
-
|
|
313
|
+
Ke.current && !e && (B.current = null, R.current.phase === "speaking" && U() || g({ type: "speech-ended" })), Ke.current = e;
|
|
269
314
|
}, [b, U]), c(() => {
|
|
270
315
|
h.phase !== "listening" && M((e) => e === "nothing-heard" ? null : e);
|
|
271
316
|
}, [h.phase]), c(() => {
|
|
272
317
|
if (h.phase !== "speaking" || b !== null) return;
|
|
273
318
|
let e = setTimeout(() => {
|
|
274
|
-
|
|
275
|
-
},
|
|
319
|
+
Ke.current || (H(), g({ type: "speech-ended" }));
|
|
320
|
+
}, Ae);
|
|
276
321
|
return () => clearTimeout(e);
|
|
277
322
|
}, [
|
|
278
323
|
h.phase,
|
|
279
324
|
b,
|
|
280
325
|
H
|
|
281
326
|
]);
|
|
282
|
-
let
|
|
327
|
+
let ht = _.outputNotCleared;
|
|
283
328
|
c(() => {
|
|
284
|
-
if (
|
|
329
|
+
if (ht === null || k.current !== ht.messageId) return;
|
|
285
330
|
let { phase: e } = R.current;
|
|
286
331
|
e !== "idle" && e !== "ended" && e !== "thinking" && M("reply-not-heard");
|
|
287
|
-
}, [
|
|
332
|
+
}, [ht]), c(() => {
|
|
288
333
|
h.phase !== "listening" && h.phase !== "thinking" && M((e) => e === "reply-not-heard" ? null : e);
|
|
289
334
|
}, [h.phase]);
|
|
290
|
-
let
|
|
291
|
-
|
|
292
|
-
let
|
|
335
|
+
let gt = l(Ie);
|
|
336
|
+
gt.current = Ie;
|
|
337
|
+
let _t = l(0);
|
|
293
338
|
c(() => {
|
|
294
339
|
let e = h.superseded;
|
|
295
|
-
e !==
|
|
340
|
+
e !== _t.current && (_t.current = e, e !== 0 && (H(), x(), gt.current?.()));
|
|
296
341
|
}, [
|
|
297
342
|
h.superseded,
|
|
298
343
|
H,
|
|
299
344
|
x
|
|
300
345
|
]), c(() => {
|
|
301
|
-
let e =
|
|
302
|
-
y(e),
|
|
346
|
+
let e = be(h);
|
|
347
|
+
y(e), Te(h) && qe === null && !X.suppressWebSpeech ? J.isActive || J.start("auto") : J.isActive && J.stop();
|
|
303
348
|
}, [
|
|
304
349
|
h,
|
|
305
350
|
J,
|
|
306
351
|
y,
|
|
307
|
-
|
|
308
|
-
|
|
352
|
+
X.suppressWebSpeech,
|
|
353
|
+
qe
|
|
309
354
|
]), c(() => {
|
|
310
355
|
h.phase === "speaking" && V.current && (V.current = !1, U() || g({ type: "speech-ended" }));
|
|
311
356
|
}, [h.phase, U]), c(() => {
|
|
@@ -317,23 +362,23 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
|
|
|
317
362
|
error: "no-speech-support"
|
|
318
363
|
}) : J.error === "network" ? M("network") : J.error === "unknown" && M("recognition-failed");
|
|
319
364
|
}, [J.error]), c(() => {
|
|
320
|
-
J.error === null &&
|
|
321
|
-
}, [J.error,
|
|
322
|
-
if (
|
|
323
|
-
let e = setTimeout(() => M("not-capturing"),
|
|
365
|
+
J.error === null && Z && M((e) => e === "network" || e === "recognition-failed" ? null : e);
|
|
366
|
+
}, [J.error, Z]), c(() => {
|
|
367
|
+
if (Z && M((e) => e === "not-capturing" ? null : e), !be(h) || Z || ut) return;
|
|
368
|
+
let e = setTimeout(() => M("not-capturing"), Me);
|
|
324
369
|
return () => clearTimeout(e);
|
|
325
370
|
}, [
|
|
326
371
|
h,
|
|
327
|
-
|
|
328
|
-
|
|
372
|
+
Z,
|
|
373
|
+
ut
|
|
329
374
|
]), c(() => {
|
|
330
|
-
if (h.phase !== "listening" || h.muted || !
|
|
331
|
-
let e = setTimeout(() => M("nothing-heard"),
|
|
375
|
+
if (h.phase !== "listening" || h.muted || !Z || o(h) !== "") return;
|
|
376
|
+
let e = setTimeout(() => M("nothing-heard"), Ne);
|
|
332
377
|
return () => clearTimeout(e);
|
|
333
|
-
}, [h,
|
|
378
|
+
}, [h, Z]), c(() => {
|
|
334
379
|
o(h) !== "" && M(null);
|
|
335
380
|
}, [h]);
|
|
336
|
-
let
|
|
381
|
+
let $ = l(null), vt = s(() => {
|
|
337
382
|
if (P(!1), F(!1), L(!1), H(), W.current = !1, !J.isSupported) g({
|
|
338
383
|
type: "fail",
|
|
339
384
|
error: "no-speech-support"
|
|
@@ -350,25 +395,26 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
|
|
|
350
395
|
t.volume = 0, e.speak(t);
|
|
351
396
|
}
|
|
352
397
|
} catch {}
|
|
353
|
-
ne(), v(!0), M(null), k.current =
|
|
398
|
+
ne(), he() && Q.prime(), v(!0), M(null), k.current = Qe.current?.id ?? null, j.current = null, $.current = `vs-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`, g({ type: "start" });
|
|
354
399
|
}
|
|
355
400
|
}, [
|
|
356
401
|
J.isSupported,
|
|
357
402
|
_.isBlocked,
|
|
358
403
|
v,
|
|
359
|
-
H
|
|
360
|
-
|
|
361
|
-
|
|
404
|
+
H,
|
|
405
|
+
Q
|
|
406
|
+
]), yt = s(() => {
|
|
407
|
+
P(!1), F(!1), L(!1), H(), W.current = !1, $.current = null, g({ type: "end" }), x(), v(!1);
|
|
362
408
|
}, [
|
|
363
409
|
x,
|
|
364
410
|
v,
|
|
365
411
|
H
|
|
366
|
-
]),
|
|
412
|
+
]), bt = s((e) => $.current === e, []), xt = s(() => {
|
|
367
413
|
let e = R.current;
|
|
368
414
|
e.phase !== "listening" || e.muted || L(!0);
|
|
369
|
-
}, []),
|
|
415
|
+
}, []), St = s(() => {
|
|
370
416
|
let e = R.current;
|
|
371
|
-
if (e.phase !== "listening" || e.muted || !
|
|
417
|
+
if (e.phase !== "listening" || e.muted || !xe(o(e))) return;
|
|
372
418
|
let t = i();
|
|
373
419
|
C.current = {
|
|
374
420
|
speechEnded: w.current.at ?? t,
|
|
@@ -381,15 +427,15 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
|
|
|
381
427
|
type: "silence",
|
|
382
428
|
at: Date.now()
|
|
383
429
|
});
|
|
384
|
-
}, [p]),
|
|
430
|
+
}, [p]), Ct = l(!1);
|
|
385
431
|
c(() => {
|
|
386
|
-
(h.phase !== "listening" || h.muted) && (
|
|
432
|
+
(h.phase !== "listening" || h.muted) && (Ct.current = !1);
|
|
387
433
|
}, [h.phase, h.muted]), c(() => {
|
|
388
|
-
!
|
|
389
|
-
}, [
|
|
390
|
-
let
|
|
391
|
-
L(!1),
|
|
392
|
-
}, [
|
|
434
|
+
!X.wordsPending && Ct.current && (Ct.current = !1, St());
|
|
435
|
+
}, [X.wordsPending, St]);
|
|
436
|
+
let wt = s(() => {
|
|
437
|
+
L(!1), X.wordsPending ? Ct.current = !0 : St();
|
|
438
|
+
}, [X.wordsPending, St]), Tt = s(() => {
|
|
393
439
|
g({
|
|
394
440
|
type: "mute",
|
|
395
441
|
muted: !R.current.muted
|
|
@@ -398,60 +444,60 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
|
|
|
398
444
|
c(() => () => {
|
|
399
445
|
v(!1), y(!1);
|
|
400
446
|
}, [v, y]);
|
|
401
|
-
let
|
|
402
|
-
return
|
|
447
|
+
let Et = oe(_.spokenChunks, h.phase, b);
|
|
448
|
+
return Oe(() => ({
|
|
403
449
|
session: h,
|
|
404
|
-
notice:
|
|
405
|
-
spokenChunks:
|
|
406
|
-
capturing:
|
|
450
|
+
notice: Je ?? (X.fallbackReason !== null && X.fallbackReason !== "notice-declined" ? "hands-free-fallback" : X.nothingHeard ? "hands-free-nothing-heard" : null),
|
|
451
|
+
spokenChunks: Et,
|
|
452
|
+
capturing: Z,
|
|
407
453
|
active: h.phase !== "idle" && (h.phase !== "ended" || h.error !== null),
|
|
408
454
|
interrupting: N,
|
|
409
|
-
awaitingEndpoint:
|
|
455
|
+
awaitingEndpoint: Ye,
|
|
410
456
|
holding: I,
|
|
411
457
|
correcting: h.correcting,
|
|
412
458
|
handsFree: {
|
|
413
|
-
mode:
|
|
414
|
-
nothingHeard:
|
|
415
|
-
transportKind:
|
|
416
|
-
fallbackReason:
|
|
417
|
-
privacyNotice:
|
|
459
|
+
mode: X.mode,
|
|
460
|
+
nothingHeard: X.nothingHeard,
|
|
461
|
+
transportKind: X.transportKind,
|
|
462
|
+
fallbackReason: X.fallbackReason,
|
|
463
|
+
privacyNotice: X.privacyNotice
|
|
418
464
|
},
|
|
419
465
|
available: J.isSupported && !_.isBlocked,
|
|
420
|
-
start:
|
|
421
|
-
end:
|
|
422
|
-
isCurrentSession:
|
|
423
|
-
toggleMute:
|
|
424
|
-
interrupt:
|
|
425
|
-
letMeFinish:
|
|
426
|
-
imDone:
|
|
466
|
+
start: vt,
|
|
467
|
+
end: yt,
|
|
468
|
+
isCurrentSession: bt,
|
|
469
|
+
toggleMute: Tt,
|
|
470
|
+
interrupt: rt,
|
|
471
|
+
letMeFinish: xt,
|
|
472
|
+
imDone: wt,
|
|
427
473
|
announce: G,
|
|
428
|
-
holdListening:
|
|
429
|
-
answerLocally:
|
|
474
|
+
holdListening: Xe,
|
|
475
|
+
answerLocally: Ze
|
|
430
476
|
}), [
|
|
431
477
|
h,
|
|
432
|
-
|
|
478
|
+
Je,
|
|
433
479
|
N,
|
|
434
|
-
|
|
480
|
+
Ye,
|
|
435
481
|
I,
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
482
|
+
Z,
|
|
483
|
+
X.mode,
|
|
484
|
+
X.nothingHeard,
|
|
485
|
+
X.transportKind,
|
|
486
|
+
X.fallbackReason,
|
|
487
|
+
X.privacyNotice,
|
|
442
488
|
J.isSupported,
|
|
443
489
|
_.isBlocked,
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
490
|
+
Et,
|
|
491
|
+
vt,
|
|
492
|
+
yt,
|
|
493
|
+
bt,
|
|
494
|
+
Tt,
|
|
495
|
+
rt,
|
|
496
|
+
xt,
|
|
497
|
+
wt,
|
|
452
498
|
G,
|
|
453
|
-
|
|
454
|
-
|
|
499
|
+
Xe,
|
|
500
|
+
Ze
|
|
455
501
|
]);
|
|
456
502
|
}
|
|
457
|
-
export {
|
|
503
|
+
export { Pe as useVoiceSession };
|
|
@@ -167,7 +167,9 @@ export type ThinkingSpeechPlan = {
|
|
|
167
167
|
*
|
|
168
168
|
* Echo is not checked here: nothing plays during `thinking`. The caller still
|
|
169
169
|
* passes the previous reply through `isEcho` first, because its tail can sound
|
|
170
|
-
* for a moment after playback ends.
|
|
170
|
+
* for a moment after playback ends. The one thing that does play then, the
|
|
171
|
+
* thinking tone (D3, BOFF-12936), is refused by the caller before this
|
|
172
|
+
* (`mayBeThinkingTone` in `voiceSession.ts`): no words are ever read into it.
|
|
171
173
|
*/
|
|
172
174
|
export declare function planThinkingSpeech(input: {
|
|
173
175
|
transcript: string;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { SttTransport } from './sttTransport';
|
|
2
2
|
export declare const BRANCH_DELAY_S = 0.3;
|
|
3
3
|
export declare const TRAILING_RESULT_MS = 1500;
|
|
4
|
+
/** How long the branch stays open after an utterance closes, so its last word is not clipped. */
|
|
5
|
+
export declare const CLOSE_HOLD_MS = 400;
|
|
6
|
+
/**
|
|
7
|
+
* The branch opens and closes as an exponential approach with this time
|
|
8
|
+
* constant: smooth, so the recogniser hears no click, and within 1% of the
|
|
9
|
+
* target after five of them.
|
|
10
|
+
*/
|
|
11
|
+
export declare const GAIN_TIME_CONSTANT_S = 0.005;
|
|
4
12
|
/** The slice of `SpeechRecognition` this transport uses. */
|
|
5
13
|
export interface TrackRecognitionLike {
|
|
6
14
|
lang: string;
|