@burdenoff/fe-libs 2026.1114.12 → 2026.1114.14
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/conversation.d.ts +16 -0
- package/dist/shared/assistant/i18nManifest.d.ts +32 -0
- package/dist/shared/assistant/i18nManifest.js +32 -0
- package/dist/shared/assistant/index.d.ts +10 -0
- package/dist/shared/assistant/store.d.ts +7 -0
- package/dist/shared/assistant/store.js +3 -0
- package/dist/shared/assistant/ui/AssistantChatArea.js +1275 -1181
- package/dist/shared/assistant/ui/AssistantMessageList.d.ts +14 -0
- package/dist/shared/assistant/ui/AssistantMessageList.js +55 -52
- package/dist/shared/assistant/ui/composer/AssistantComposer.d.ts +6 -0
- package/dist/shared/assistant/ui/composer/AssistantComposer.js +400 -311
- package/dist/shared/assistant/ui/composer/AssistantDictation.d.ts +42 -0
- package/dist/shared/assistant/ui/composer/AssistantDictation.js +127 -0
- package/dist/shared/assistant/ui/composer/AssistantMicMenu.d.ts +23 -0
- package/dist/shared/assistant/ui/composer/AssistantMicMenu.js +176 -0
- package/dist/shared/assistant/ui/composer/microphones.d.ts +13 -0
- package/dist/shared/assistant/ui/composer/microphones.js +15 -0
- package/dist/shared/assistant/ui/composer/useCompactDictation.d.ts +70 -0
- package/dist/shared/assistant/ui/composer/useCompactDictation.js +136 -0
- package/dist/shared/assistant/ui/useVoiceSession.js +166 -164
- package/dist/shared/assistant/ui/voice/AssistantPageVoiceBar.d.ts +67 -0
- package/dist/shared/assistant/ui/voice/AssistantPageVoiceBar.js +290 -0
- package/dist/shared/assistant/ui/voice/AssistantVoiceSession.d.ts +11 -1
- package/dist/shared/assistant/ui/voice/AssistantVoiceSession.js +288 -244
- package/dist/shared/assistant/ui/voice/AssistantVoiceSessionButton.d.ts +5 -0
- package/dist/shared/assistant/ui/voice/AssistantVoiceSessionButton.js +6 -6
- package/dist/shared/assistant/ui/voice/LiveWaveform.d.ts +32 -0
- package/dist/shared/assistant/ui/voice/LiveWaveform.js +52 -0
- package/dist/shared/assistant/ui/voice/VoiceTurnMarks.d.ts +15 -0
- package/dist/shared/assistant/ui/voice/VoiceTurnMarks.js +43 -0
- package/dist/shared/assistant/ui/voice/formatClock.d.ts +2 -0
- package/dist/shared/assistant/ui/voice/formatClock.js +3 -0
- package/dist/shared/assistant/ui/voice/useLiveLevel.d.ts +23 -0
- package/dist/shared/assistant/ui/voice/useLiveLevel.js +56 -0
- package/dist/shared/assistant/voice/liveLevel.d.ts +85 -0
- package/dist/shared/assistant/voice/liveLevel.js +78 -0
- package/dist/shared/assistant/voice/useVoiceInput.d.ts +27 -1
- package/dist/shared/assistant/voice/useVoiceInput.js +141 -71
- package/dist/shared-assistant.js +393 -383
- package/package.json +1 -1
|
@@ -23,4 +23,9 @@ export declare const AssistantVoiceSessionButton: FC<{
|
|
|
23
23
|
compact?: boolean;
|
|
24
24
|
/** Keep the compact opener mounted for focus return while its session is live. */
|
|
25
25
|
invisible?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* ★ BOFF-13461 (page): a secondary circle beside Send, the wave in the
|
|
28
|
+
* assistant's blue, as the operator's design draws it.
|
|
29
|
+
*/
|
|
30
|
+
secondary?: boolean;
|
|
26
31
|
}>;
|
|
@@ -2,17 +2,17 @@ import { useAssistantTr as e } from "../../i18n.js";
|
|
|
2
2
|
import { AudioLines as t } from "lucide-react";
|
|
3
3
|
import { jsx as n } from "react/jsx-runtime";
|
|
4
4
|
// src/shared/assistant/ui/voice/AssistantVoiceSessionButton.tsx
|
|
5
|
-
var r = ({ onStart: r, disabled: i = !1, compact: a = !1, invisible: o = !1 }) => {
|
|
6
|
-
let
|
|
5
|
+
var r = ({ onStart: r, disabled: i = !1, compact: a = !1, invisible: o = !1, secondary: s = !1 }) => {
|
|
6
|
+
let c = e();
|
|
7
7
|
return /* @__PURE__ */ n("button", {
|
|
8
8
|
type: "button",
|
|
9
9
|
onClick: r,
|
|
10
10
|
disabled: i,
|
|
11
|
-
className: a ? `flex size-11 shrink-0 items-center justify-center rounded-full bg-action-primary-bg text-action-primary-text transition-colors hover:bg-action-primary-bg-hover focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50 sm:size-10${o ? " invisible" : ""}` : "flex size-9 flex-shrink-0 items-center justify-center rounded-full bg-bg-elevated text-text-secondary shadow-sm transition-all hover:scale-105 hover:bg-bg-raised hover:text-text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:scale-100",
|
|
12
|
-
"aria-label":
|
|
13
|
-
title:
|
|
11
|
+
className: s ? `flex size-11 shrink-0 items-center justify-center rounded-full border border-border-default text-status-info-bg transition-colors hover:bg-bg-sunken focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50 sm:size-10${o ? " invisible" : ""}` : a ? `flex size-11 shrink-0 items-center justify-center rounded-full bg-action-primary-bg text-action-primary-text transition-colors hover:bg-action-primary-bg-hover focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50 sm:size-10${o ? " invisible" : ""}` : "flex size-9 flex-shrink-0 items-center justify-center rounded-full bg-bg-elevated text-text-secondary shadow-sm transition-all hover:scale-105 hover:bg-bg-raised hover:text-text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:scale-100",
|
|
12
|
+
"aria-label": c("voiceSession.start", "Start a voice conversation"),
|
|
13
|
+
title: c("voiceSession.start", "Start a voice conversation"),
|
|
14
14
|
"data-testid": "assistant-voice-session-start",
|
|
15
|
-
children: /* @__PURE__ */ n(t, { className: a ? "size-5" : "size-4" })
|
|
15
|
+
children: /* @__PURE__ */ n(t, { className: a || s ? "size-5" : "size-4" })
|
|
16
16
|
});
|
|
17
17
|
};
|
|
18
18
|
export { r as AssistantVoiceSessionButton };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { LiveLevelSource } from '../../voice/liveLevel';
|
|
3
|
+
interface Props {
|
|
4
|
+
/** The level to draw (`useLiveLevel`). */
|
|
5
|
+
source: LiveLevelSource;
|
|
6
|
+
/** `listening`: the person's voice. `speaking`: the assistant's. */
|
|
7
|
+
tone: 'listening' | 'speaking';
|
|
8
|
+
/** Sizes the waveform; it fills its box. */
|
|
9
|
+
className?: string;
|
|
10
|
+
testId?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A live, scrolling waveform (BOFF-13461, the operator, 14 Nov: "the mic for
|
|
14
|
+
* listening… animation is good [on claude.ai], make it in ours").
|
|
15
|
+
*
|
|
16
|
+
* Each frame's level enters as a bar on the right and the bars move left, so
|
|
17
|
+
* speech draws as a moving trace and a pause as a quiet line. Drawn on a canvas,
|
|
18
|
+
* outside React's render, at about 30 frames a second, and only while its source
|
|
19
|
+
* runs.
|
|
20
|
+
*
|
|
21
|
+
* Colours are the theme's: the canvas reads its own CSS `color`, which the tone's
|
|
22
|
+
* semantic token class sets, so it follows light, dark and any product theme
|
|
23
|
+
* without a colour value in code. The operator's design (14 Nov): amber
|
|
24
|
+
* (`status-warning`) always means "we are hearing you", blue (`accent-blue`)
|
|
25
|
+
* always means "the assistant is talking".
|
|
26
|
+
*
|
|
27
|
+
* ★ Under either reduced-motion signal (BOFF-8566) nothing scrolls: the bars stay
|
|
28
|
+
* a still, short line. The words next to it (the status, or the words appearing
|
|
29
|
+
* in the box) carry the meaning; the waveform is decoration and `aria-hidden`.
|
|
30
|
+
*/
|
|
31
|
+
export declare const LiveWaveform: FC<Props>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { pushLevel as e } from "../../voice/liveLevel.js";
|
|
2
|
+
import { usePrefersReducedMotion as t } from "../usePrefersReducedMotion.js";
|
|
3
|
+
import { useEffect as n, useRef as r } from "react";
|
|
4
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
5
|
+
// src/shared/assistant/ui/voice/LiveWaveform.tsx
|
|
6
|
+
var a = 3, o = 2, s = 2, c = ({ source: c, tone: l, className: u = "", testId: d }) => {
|
|
7
|
+
let f = t(), p = r(null), m = r(null);
|
|
8
|
+
return n(() => {
|
|
9
|
+
let t = p.current, n = m.current;
|
|
10
|
+
if (!t || !n) return;
|
|
11
|
+
let r = typeof n.getContext == "function" ? n.getContext("2d") : null;
|
|
12
|
+
if (!r) return;
|
|
13
|
+
let i = 0, l = 0, u = 0, d = [], h = "", g = () => {
|
|
14
|
+
if (i === 0 || l === 0) return;
|
|
15
|
+
let e = typeof window > "u" ? 1 : window.devicePixelRatio || 1;
|
|
16
|
+
r.setTransform(e, 0, 0, e, 0, 0), r.clearRect(0, 0, i, l), r.fillStyle = h;
|
|
17
|
+
let t = u * 5 - o, n = i - t;
|
|
18
|
+
for (let e = 0; e < u; e += 1) {
|
|
19
|
+
let t = f ? 0 : d[e] ?? 0, i = Math.max(s, t * l), o = n + e * 5, c = (l - i) / 2, u = Math.min(a / 2, i / 2);
|
|
20
|
+
typeof r.roundRect == "function" ? (r.beginPath(), r.roundRect(o, c, a, i, u), r.fill()) : r.fillRect(o, c, a, i);
|
|
21
|
+
}
|
|
22
|
+
}, _ = () => {
|
|
23
|
+
let e = t.getBoundingClientRect(), r = typeof window > "u" ? 1 : window.devicePixelRatio || 1;
|
|
24
|
+
for (i = Math.max(0, Math.floor(e.width)), l = Math.max(0, Math.floor(e.height)), n.width = Math.round(i * r), n.height = Math.round(l * r), n.style.width = `${i}px`, n.style.height = `${l}px`, u = Math.max(0, Math.floor((i + o) / 5)), d = d.length > u ? d.slice(d.length - u) : d; d.length < u;) d.unshift(0);
|
|
25
|
+
h = typeof getComputedStyle == "function" ? getComputedStyle(n).color : "", g();
|
|
26
|
+
};
|
|
27
|
+
_();
|
|
28
|
+
let v = typeof ResizeObserver > "u" ? null : new ResizeObserver(_);
|
|
29
|
+
v?.observe(t);
|
|
30
|
+
let y = c.subscribe((t) => {
|
|
31
|
+
f || (d = e(d, t, u), g());
|
|
32
|
+
});
|
|
33
|
+
return () => {
|
|
34
|
+
y(), v?.disconnect();
|
|
35
|
+
};
|
|
36
|
+
}, [
|
|
37
|
+
c,
|
|
38
|
+
l,
|
|
39
|
+
f
|
|
40
|
+
]), /* @__PURE__ */ i("div", {
|
|
41
|
+
ref: p,
|
|
42
|
+
className: `relative min-w-0 overflow-hidden ${u}`,
|
|
43
|
+
"aria-hidden": "true",
|
|
44
|
+
"data-testid": d,
|
|
45
|
+
"data-tone": l,
|
|
46
|
+
children: /* @__PURE__ */ i("canvas", {
|
|
47
|
+
ref: m,
|
|
48
|
+
className: `absolute inset-0 ${l === "speaking" ? "text-status-info-bg" : "text-status-warning-bg"}`
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
export { c as LiveWaveform };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* What the page's thread says about voice turns (BOFF-13461; the operator's design
|
|
4
|
+
* of 14 Nov, "How the answer reaches the chat"): the voice chat's turns are the
|
|
5
|
+
* thread's own, and each says how it happened.
|
|
6
|
+
*/
|
|
7
|
+
export type VoiceTurnMark = 'spoken' | 'spokenAloud' | 'interrupted';
|
|
8
|
+
/** Under a voice turn: "Spoken", "Spoken aloud", or "Interrupted…". */
|
|
9
|
+
export declare const VoiceTurnTag: FC<{
|
|
10
|
+
mark: VoiceTurnMark;
|
|
11
|
+
}>;
|
|
12
|
+
/** After a voice chat's last turn: "Voice chat ended", with its length when known. */
|
|
13
|
+
export declare const VoiceChatEnded: FC<{
|
|
14
|
+
seconds?: number;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useAssistantTr as e } from "../../i18n.js";
|
|
2
|
+
import { formatClock as t } from "./formatClock.js";
|
|
3
|
+
import { AudioLines as n, Mic as r } from "lucide-react";
|
|
4
|
+
import { jsx as i, jsxs as a } from "react/jsx-runtime";
|
|
5
|
+
// src/shared/assistant/ui/voice/VoiceTurnMarks.tsx
|
|
6
|
+
var o = ({ mark: t }) => {
|
|
7
|
+
let o = e(), s = t === "spoken", c = t === "spoken" ? o("voiceTurn.spoken", "Spoken") : t === "interrupted" ? o("voiceTurn.interrupted", "Interrupted. Only the spoken part is kept.") : o("voiceTurn.spokenAloud", "Spoken aloud");
|
|
8
|
+
return /* @__PURE__ */ i("div", {
|
|
9
|
+
className: `-mt-2 flex px-1 ${s ? "justify-end" : "justify-start ps-10"}`,
|
|
10
|
+
"data-testid": "assistant-voice-turn-tag",
|
|
11
|
+
"data-mark": t,
|
|
12
|
+
children: /* @__PURE__ */ a("span", {
|
|
13
|
+
className: "inline-flex items-center gap-1 text-xs text-text-muted",
|
|
14
|
+
children: [/* @__PURE__ */ i(s ? r : n, {
|
|
15
|
+
className: "size-3",
|
|
16
|
+
"aria-hidden": "true"
|
|
17
|
+
}), c]
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
}, s = ({ seconds: n }) => {
|
|
21
|
+
let r = e(), o = n !== void 0 && n > 0 ? r("voiceTurn.endedAfter", "Voice chat ended · {{duration}}", { duration: t(n) }) : r("voiceTurn.ended", "Voice chat ended");
|
|
22
|
+
return /* @__PURE__ */ a("div", {
|
|
23
|
+
role: "separator",
|
|
24
|
+
"aria-label": o,
|
|
25
|
+
className: "flex items-center gap-3 py-1 text-xs text-text-muted",
|
|
26
|
+
"data-testid": "assistant-voice-chat-ended",
|
|
27
|
+
children: [
|
|
28
|
+
/* @__PURE__ */ i("span", {
|
|
29
|
+
"aria-hidden": "true",
|
|
30
|
+
className: "h-px flex-1 bg-border-subtle"
|
|
31
|
+
}),
|
|
32
|
+
/* @__PURE__ */ i("span", {
|
|
33
|
+
"aria-hidden": "true",
|
|
34
|
+
children: o
|
|
35
|
+
}),
|
|
36
|
+
/* @__PURE__ */ i("span", {
|
|
37
|
+
"aria-hidden": "true",
|
|
38
|
+
className: "h-px flex-1 bg-border-subtle"
|
|
39
|
+
})
|
|
40
|
+
]
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
export { s as VoiceChatEnded, o as VoiceTurnTag };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { LiveLevelSource } from '../../voice/liveLevel';
|
|
2
|
+
export interface UseLiveLevelOptions {
|
|
3
|
+
/** Levels are produced while true, and a 0 is sent once when it turns false. */
|
|
4
|
+
active: boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Read the person's microphone where a second capture is harmless (a desktop
|
|
7
|
+
* browser, `micLevelAllowed`). Elsewhere, and if the browser refuses, the
|
|
8
|
+
* level follows `pulseKey`.
|
|
9
|
+
*/
|
|
10
|
+
mic?: boolean;
|
|
11
|
+
/** Changes whenever new words are heard (the interim text): each change is a pulse. */
|
|
12
|
+
pulseKey?: string;
|
|
13
|
+
/** The assistant is speaking: a steady, speech-like motion, never the microphone. */
|
|
14
|
+
speaking?: boolean;
|
|
15
|
+
/** The microphone chosen in the options (absent or null: the system default). */
|
|
16
|
+
deviceId?: string | null;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The level a `LiveWaveform` draws (BOFF-13461). Stable for the component's
|
|
20
|
+
* life; the frames run only while `active`. See `voice/liveLevel.ts` for the two
|
|
21
|
+
* sources and why a phone never gets the microphone's own level.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useLiveLevel({ active, mic, pulseKey, speaking, deviceId, }: UseLiveLevelOptions): LiveLevelSource;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createSpeechPulse as e, micLevelAllowed as t, openMicLevel as n, smoothLevel as r } from "../../voice/liveLevel.js";
|
|
2
|
+
import { useEffect as i, useMemo as a, useRef as o, useState as s } from "react";
|
|
3
|
+
// src/shared/assistant/ui/voice/useLiveLevel.ts
|
|
4
|
+
var c = 33;
|
|
5
|
+
function l({ active: l, mic: u = !1, pulseKey: d = "", speaking: f = !1, deviceId: p = null }) {
|
|
6
|
+
let [m] = s(() => /* @__PURE__ */ new Set()), [h] = s(e), g = o(null), _ = o(f);
|
|
7
|
+
i(() => {
|
|
8
|
+
_.current = f;
|
|
9
|
+
}, [f]);
|
|
10
|
+
let v = a(() => ({ subscribe(e) {
|
|
11
|
+
return m.add(e), () => {
|
|
12
|
+
m.delete(e);
|
|
13
|
+
};
|
|
14
|
+
} }), [m]);
|
|
15
|
+
return i(() => {
|
|
16
|
+
l && d !== "" && h.pulse();
|
|
17
|
+
}, [
|
|
18
|
+
l,
|
|
19
|
+
d,
|
|
20
|
+
h
|
|
21
|
+
]), i(() => {
|
|
22
|
+
if (!l || !u || !t(typeof navigator > "u" ? void 0 : navigator, typeof AudioContext < "u")) return;
|
|
23
|
+
let e = !1;
|
|
24
|
+
return n(p).then((t) => {
|
|
25
|
+
e ? t?.close() : g.current = t;
|
|
26
|
+
}), () => {
|
|
27
|
+
e = !0, g.current?.close(), g.current = null;
|
|
28
|
+
};
|
|
29
|
+
}, [
|
|
30
|
+
l,
|
|
31
|
+
u,
|
|
32
|
+
p
|
|
33
|
+
]), i(() => {
|
|
34
|
+
let e = (e) => {
|
|
35
|
+
for (let t of m) t(e);
|
|
36
|
+
};
|
|
37
|
+
if (!l || typeof requestAnimationFrame > "u") {
|
|
38
|
+
e(0);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
let t = 0, n = 0, i = 0, a = 0, o = (s) => {
|
|
42
|
+
if (t = requestAnimationFrame(o), s - n < c) return;
|
|
43
|
+
n = s, _.current && s - i > 170 && (i = s, h.pulse(.45 + .45 * Math.abs(Math.sin(s / 53))));
|
|
44
|
+
let l = g.current, u = l && !_.current ? l.read() : h.next(s);
|
|
45
|
+
a = r(a, u), e(a);
|
|
46
|
+
};
|
|
47
|
+
return t = requestAnimationFrame(o), () => {
|
|
48
|
+
cancelAnimationFrame(t), e(0);
|
|
49
|
+
};
|
|
50
|
+
}, [
|
|
51
|
+
l,
|
|
52
|
+
m,
|
|
53
|
+
h
|
|
54
|
+
]), v;
|
|
55
|
+
}
|
|
56
|
+
export { l as useLiveLevel };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The live level behind the assistant's waveforms (BOFF-13461: dictation and the
|
|
3
|
+
* page's voice conversation, the operator, 14 Nov: "like claude.ai/new").
|
|
4
|
+
*
|
|
5
|
+
* A level is a number from 0 (silence) to 1 (loud), produced about 30 times a
|
|
6
|
+
* second while a waveform is on screen. Two sources:
|
|
7
|
+
*
|
|
8
|
+
* - **The microphone itself** (`openMicLevel`): an `AnalyserNode` on a capture of
|
|
9
|
+
* our own, so the bars follow the person's real voice. Only where a second
|
|
10
|
+
* capture is harmless (`micLevelAllowed`): a desktop browser. On a phone the
|
|
11
|
+
* recogniser may be a separate system service (Chrome on Android hands Web
|
|
12
|
+
* Speech to Android's recogniser; iOS to its dictation), and a page capture
|
|
13
|
+
* running beside it can take the microphone from it, which would cost the very
|
|
14
|
+
* words being dictated. A bar meter is never worth that.
|
|
15
|
+
* - **What the recogniser reports** (`createSpeechPulse`): where the microphone
|
|
16
|
+
* cannot be read, each new word heard (an interim result) is a pulse that
|
|
17
|
+
* decays, over a quiet idle ripple. It moves when the person speaks and settles
|
|
18
|
+
* when they stop, which is what the bars are there to say: "I hear you".
|
|
19
|
+
*
|
|
20
|
+
* Pure apart from `openMicLevel`; the hook (`ui/voice/useLiveLevel.ts`) runs the
|
|
21
|
+
* frames and picks the source.
|
|
22
|
+
*/
|
|
23
|
+
/** Something that produces levels; `subscribe` returns the unsubscribe. */
|
|
24
|
+
export interface LiveLevelSource {
|
|
25
|
+
subscribe(listener: (level: number) => void): () => void;
|
|
26
|
+
}
|
|
27
|
+
/** RMS of a time-domain frame (bytes centred on 128), 0..1. */
|
|
28
|
+
export declare function rmsOfFrame(frame: ArrayLike<number>): number;
|
|
29
|
+
/**
|
|
30
|
+
* RMS → a level that reads well as bar heights. Speech RMS sits around
|
|
31
|
+
* 0.02–0.2, so a linear map would leave every bar near the floor: a gentle
|
|
32
|
+
* logarithmic curve between a noise floor (about -46 dBFS) and a loud voice
|
|
33
|
+
* (about -10 dBFS), clamped to 0..1.
|
|
34
|
+
*/
|
|
35
|
+
export declare function levelFromRms(rms: number): number;
|
|
36
|
+
/**
|
|
37
|
+
* One step of a level that rises quickly and falls slowly, like a VU meter, so
|
|
38
|
+
* the bars follow syllables without flickering.
|
|
39
|
+
*/
|
|
40
|
+
export declare function smoothLevel(previous: number, next: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* The bars' history: the newest level enters at the end and the oldest leaves,
|
|
43
|
+
* so the waveform scrolls from right to left. Never longer than `size`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function pushLevel(history: readonly number[], level: number, size: number): number[];
|
|
46
|
+
/** What `micLevelAllowed` reads (a `Navigator` satisfies it). */
|
|
47
|
+
export interface NavigatorLike {
|
|
48
|
+
userAgent?: string;
|
|
49
|
+
maxTouchPoints?: number;
|
|
50
|
+
mediaDevices?: {
|
|
51
|
+
getUserMedia?: unknown;
|
|
52
|
+
} | undefined;
|
|
53
|
+
userAgentData?: {
|
|
54
|
+
mobile?: boolean;
|
|
55
|
+
} | undefined;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* May the waveform open a capture of its own beside the recogniser? Only on a
|
|
59
|
+
* desktop browser that can capture at all; never on a phone or a tablet (see the
|
|
60
|
+
* header). An iPad presents itself as a Mac, so a Mac with touch is a tablet.
|
|
61
|
+
*/
|
|
62
|
+
export declare function micLevelAllowed(nav: NavigatorLike | undefined, hasAudioContext: boolean): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* The recogniser-driven level: an idle ripple, raised by `pulse()` for each word
|
|
65
|
+
* heard and decaying back. `next(now)` is called once per frame.
|
|
66
|
+
*/
|
|
67
|
+
export interface SpeechPulse {
|
|
68
|
+
pulse(strength?: number): void;
|
|
69
|
+
next(nowMs: number): number;
|
|
70
|
+
}
|
|
71
|
+
export declare function createSpeechPulse(): SpeechPulse;
|
|
72
|
+
/** A capture of our own and its analyser (`openMicLevel`). */
|
|
73
|
+
export interface MicLevelHandle {
|
|
74
|
+
/** The current level, read once per frame. */
|
|
75
|
+
read(): number;
|
|
76
|
+
close(): void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Open a capture of our own and an analyser on it. Echo cancellation, noise
|
|
80
|
+
* suppression and auto gain are asked for (plain `true`, never `exact`): the
|
|
81
|
+
* assistant's own voice must not drive the person's bars. `deviceId`: the chosen
|
|
82
|
+
* microphone (absent or null: the system default). Resolves null when the browser
|
|
83
|
+
* refuses; the caller then falls back to the recogniser's pulses.
|
|
84
|
+
*/
|
|
85
|
+
export declare function openMicLevel(deviceId?: string | null): Promise<MicLevelHandle | null>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/shared/assistant/voice/liveLevel.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
if (e.length === 0) return 0;
|
|
4
|
+
let t = 0;
|
|
5
|
+
for (let n = 0; n < e.length; n += 1) {
|
|
6
|
+
let r = ((e[n] ?? 128) - 128) / 128;
|
|
7
|
+
t += r * r;
|
|
8
|
+
}
|
|
9
|
+
return Math.sqrt(t / e.length);
|
|
10
|
+
}
|
|
11
|
+
function t(e) {
|
|
12
|
+
if (!(e > 0)) return 0;
|
|
13
|
+
let t = 20 * Math.log10(e);
|
|
14
|
+
return t <= -46 ? 0 : t >= -10 ? 1 : (t - -46) / 36;
|
|
15
|
+
}
|
|
16
|
+
function n(e, t) {
|
|
17
|
+
let n = t > e ? .6 : .18;
|
|
18
|
+
return e + (t - e) * n;
|
|
19
|
+
}
|
|
20
|
+
function r(e, t, n) {
|
|
21
|
+
if (n <= 0) return [];
|
|
22
|
+
let r = e.length >= n ? e.slice(e.length - n + 1) : e.slice();
|
|
23
|
+
for (r.push(Math.max(0, Math.min(1, t))); r.length < n;) r.unshift(0);
|
|
24
|
+
return r;
|
|
25
|
+
}
|
|
26
|
+
function i(e, t) {
|
|
27
|
+
if (!e || !t || typeof e.mediaDevices?.getUserMedia != "function" || e.userAgentData?.mobile === !0) return !1;
|
|
28
|
+
let n = e.userAgent ?? "";
|
|
29
|
+
return !(/Android|iPhone|iPad|iPod|Mobile/i.test(n) || /Macintosh/i.test(n) && (e.maxTouchPoints ?? 0) > 1);
|
|
30
|
+
}
|
|
31
|
+
function a() {
|
|
32
|
+
let e = 0, t = null;
|
|
33
|
+
return {
|
|
34
|
+
pulse(t = .85) {
|
|
35
|
+
e = Math.min(1, Math.max(e, t));
|
|
36
|
+
},
|
|
37
|
+
next(n) {
|
|
38
|
+
let r = t === null ? 0 : Math.max(0, n - t);
|
|
39
|
+
t = n, e *= .5 ** (r / 220);
|
|
40
|
+
let i = .65 + .35 * Math.abs(Math.sin(n / 97) * Math.cos(n / 61)), a = .05 + .03 * Math.abs(Math.sin(n / 420));
|
|
41
|
+
return Math.max(a, e * i);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async function o(n) {
|
|
46
|
+
if (typeof navigator > "u" || typeof AudioContext > "u") return null;
|
|
47
|
+
let r = {
|
|
48
|
+
echoCancellation: !0,
|
|
49
|
+
noiseSuppression: !0,
|
|
50
|
+
autoGainControl: !0
|
|
51
|
+
}, i;
|
|
52
|
+
try {
|
|
53
|
+
i = await navigator.mediaDevices.getUserMedia({ audio: n ? {
|
|
54
|
+
...r,
|
|
55
|
+
deviceId: { exact: n }
|
|
56
|
+
} : r });
|
|
57
|
+
} catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
let a;
|
|
61
|
+
try {
|
|
62
|
+
a = new AudioContext();
|
|
63
|
+
} catch {
|
|
64
|
+
return i.getTracks().forEach((e) => e.stop()), null;
|
|
65
|
+
}
|
|
66
|
+
let o = a.createMediaStreamSource(i), s = a.createAnalyser();
|
|
67
|
+
s.fftSize = 512, s.smoothingTimeConstant = .2, o.connect(s);
|
|
68
|
+
let c = new Uint8Array(s.fftSize), l = !1;
|
|
69
|
+
return {
|
|
70
|
+
read() {
|
|
71
|
+
return l ? 0 : (s.getByteTimeDomainData(c), t(e(c)));
|
|
72
|
+
},
|
|
73
|
+
close() {
|
|
74
|
+
l || (l = !0, o.disconnect(), i.getTracks().forEach((e) => e.stop()), a.close().catch(() => void 0));
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export { a as createSpeechPulse, t as levelFromRms, i as micLevelAllowed, o as openMicLevel, r as pushLevel, e as rmsOfFrame, n as smoothLevel };
|
|
@@ -105,7 +105,25 @@ export interface UseVoiceInputOptions {
|
|
|
105
105
|
* only way to dictate Tamil was to translate the entire app.
|
|
106
106
|
*/
|
|
107
107
|
language?: string;
|
|
108
|
+
/**
|
|
109
|
+
* ★ BOFF-13461: the microphone to listen to (a `deviceId`); absent or null is
|
|
110
|
+
* the system default, which is exactly the behaviour before this option.
|
|
111
|
+
* Honoured on a desktop browser only, by handing the recogniser a track of that
|
|
112
|
+
* device (`start(audioTrack)`, Chrome 135+; an older engine ignores the track
|
|
113
|
+
* and listens to the default). Never on a phone or tablet: the recogniser there
|
|
114
|
+
* may be a system service a capture of ours would take the microphone from.
|
|
115
|
+
*/
|
|
116
|
+
deviceId?: string | null;
|
|
117
|
+
/**
|
|
118
|
+
* ★ BOFF-13461: the recogniser went away on its own, with no `finish()` waiting:
|
|
119
|
+
* its own end (the end of a phrase on a phone, an error) or a start that failed.
|
|
120
|
+
* Not called by `stop()`. Dictation lands what it heard so far here, so no
|
|
121
|
+
* word is lost.
|
|
122
|
+
*/
|
|
123
|
+
onEnded?: () => void;
|
|
108
124
|
}
|
|
125
|
+
/** How long `finish()` waits for the recogniser's last words before it gives up. */
|
|
126
|
+
export declare const FINISH_WAIT_MS = 1500;
|
|
109
127
|
export interface UseVoiceInputResult {
|
|
110
128
|
isSupported: boolean;
|
|
111
129
|
isListening: boolean;
|
|
@@ -135,8 +153,16 @@ export interface UseVoiceInputResult {
|
|
|
135
153
|
*/
|
|
136
154
|
start: (source?: StartSource) => void;
|
|
137
155
|
stop: () => void;
|
|
156
|
+
/**
|
|
157
|
+
* ★ BOFF-13461: stop listening, but WAIT for the recogniser's last words: the
|
|
158
|
+
* phrase it was still working on arrives through `onFinalize` before this
|
|
159
|
+
* resolves (or after `FINISH_WAIT_MS`, whichever is first). `stop()` drops it.
|
|
160
|
+
*/
|
|
161
|
+
finish: () => Promise<void>;
|
|
162
|
+
/** `finish()` is waiting for the last words. */
|
|
163
|
+
isFinishing: boolean;
|
|
138
164
|
/** Start if idle, stop if listening — what the mic button binds to. */
|
|
139
165
|
toggle: () => void;
|
|
140
166
|
clearError: () => void;
|
|
141
167
|
}
|
|
142
|
-
export declare function useVoiceInput({ onFinalize, onSpeechEnd, language: requested, }: UseVoiceInputOptions): UseVoiceInputResult;
|
|
168
|
+
export declare function useVoiceInput({ onFinalize, onSpeechEnd, language: requested, deviceId, onEnded, }: UseVoiceInputOptions): UseVoiceInputResult;
|