@kitn.ai/ui 0.18.2 → 0.20.0
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/LICENSE +6 -0
- package/NOTICE +54 -0
- package/dist/components/audio-visualizer/audio-visualizer.voice-fixture.d.ts +59 -0
- package/dist/components/audio-visualizer/aurora.glsl.d.ts +114 -0
- package/dist/components/audio-visualizer/index.d.ts +155 -0
- package/dist/components/audio-visualizer/shader-canvas.d.ts +130 -0
- package/dist/components/audio-visualizer/sizes.d.ts +25 -0
- package/dist/components/audio-visualizer/variant-aurora.d.ts +89 -0
- package/dist/components/audio-visualizer/variant-bar.d.ts +46 -0
- package/dist/components/audio-visualizer/variant-custom.d.ts +73 -0
- package/dist/components/audio-visualizer/variant-grid.d.ts +22 -0
- package/dist/components/audio-visualizer/variant-radial.d.ts +13 -0
- package/dist/components/audio-visualizer/variant-wave.d.ts +11 -0
- package/dist/components/audio-visualizer/wave.glsl.d.ts +16 -0
- package/dist/components/thread.d.ts +54 -0
- package/dist/create-tween-hvpmSuwW.js +7 -0
- package/dist/custom-elements.json +477 -0
- package/dist/elements/agent-card.js +1 -1
- package/dist/elements/artifact.js +1 -1
- package/dist/elements/attachments.js +1 -1
- package/dist/elements/audio-visualizer.d.ts +1 -0
- package/dist/elements/audio-visualizer.js +1 -0
- package/dist/elements/autoloader.js +1 -1
- package/dist/elements/avatar.js +1 -1
- package/dist/elements/badge.js +1 -1
- package/dist/elements/button.js +1 -1
- package/dist/elements/card.js +1 -1
- package/dist/elements/cards.js +1 -1
- package/dist/elements/chain-of-thought.js +1 -1
- package/dist/elements/chat-scope-picker.js +1 -1
- package/dist/elements/chat-workspace.js +1 -1
- package/dist/elements/chat.js +1 -1
- package/dist/elements/checkpoint.js +1 -1
- package/dist/elements/choice.js +1 -1
- package/dist/elements/chunks/{Icon-C2LTALdM.js → Icon-Tj58ES_d.js} +1 -1
- package/dist/elements/chunks/action-icons-ns1Fnedj.js +1 -0
- package/dist/elements/chunks/arrow-left-DQocUFvy.js +1 -0
- package/dist/elements/chunks/{attachments-DLJcWCDV.js → attachments-mCB5F1Fq.js} +1 -1
- package/dist/elements/chunks/audio-visualizer-BqNy7dfm.js +1 -0
- package/dist/elements/chunks/{badge-BTNZTODL.js → badge-B4Zuajl2.js} +1 -1
- package/dist/elements/chunks/{button-DBDZebGr.js → button-ZWNif3--.js} +1 -1
- package/dist/elements/chunks/{card-YfCyI4fH.js → card-BkHbp4BA.js} +1 -1
- package/dist/elements/chunks/chat-thread-CkRN6pZ7.js +1 -0
- package/dist/elements/chunks/check-B9-gn6SS.js +1 -0
- package/dist/elements/chunks/chevron-down-BNsxc2hk.js +1 -0
- package/dist/elements/chunks/chevron-right-Hv00StBO.js +1 -0
- package/dist/elements/chunks/circle-0e3KJTDr.js +1 -0
- package/dist/elements/chunks/circle-check-BNAS0JEy.js +1 -0
- package/dist/elements/chunks/{circle-x-pDtzlghQ.js → circle-x-B7faJFlY.js} +1 -1
- package/dist/elements/chunks/{code-block-DZ6mz6vs.js → code-block-BFUHn6Va.js} +1 -1
- package/dist/elements/chunks/collapsible-DM1Ckd4e.js +1 -0
- package/dist/elements/chunks/{composer-BZyPU6gD.js → composer-BguS0QL_.js} +7 -3
- package/dist/elements/chunks/{context-Cx6eQA_G.js → context-Cb7k4F-v.js} +1 -1
- package/dist/elements/chunks/{conversation-list-C4xTQSpT.js → conversation-list-CvoAkWhN.js} +1 -1
- package/dist/elements/chunks/create-tween-oVvAIG8r.js +7 -0
- package/dist/elements/chunks/{default-input-BZcwyKcP.js → default-input-Cqqilg9t.js} +1 -1
- package/dist/elements/chunks/define-D1din7Ld.js +1 -0
- package/dist/elements/chunks/{disclosure-BcBs--Jf.js → disclosure-CIZ5c8nO.js} +1 -1
- package/dist/elements/chunks/{download-BDQwcFav.js → download-Dsbg3ste.js} +1 -1
- package/dist/elements/chunks/{dropdown-wgs8xCJZ.js → dropdown-BDd1-Zgi.js} +1 -1
- package/dist/elements/chunks/{ellipsis-CUiEJ6R1.js → ellipsis-Dw6qrss-.js} +1 -1
- package/dist/elements/chunks/{external-link-DJUmC7g2.js → external-link-Vt74zAoL.js} +1 -1
- package/dist/elements/chunks/{file-text-DOYfYvrh.js → file-text-CZrZF6_v.js} +1 -1
- package/dist/elements/chunks/{file-tree-DQzNQrbr.js → file-tree-DF4okKyo.js} +1 -1
- package/dist/elements/chunks/{folder-DBDUBANz.js → folder-glP5rha4.js} +1 -1
- package/dist/elements/chunks/hover-card-Cmm6Q53m.js +1 -0
- package/dist/elements/chunks/icon-BLb8beoi.js +1 -0
- package/dist/elements/chunks/{info-DBQl-m6e.js → info-CIsv92JK.js} +1 -1
- package/dist/elements/chunks/{input-DZD67EvW.js → input-Dds1kFyt.js} +1 -1
- package/dist/elements/chunks/{kbd-DbyVrlnU.js → kbd-De_xbgi9.js} +1 -1
- package/dist/elements/chunks/{link-vko7AttA.js → link-i4r_k7z4.js} +1 -1
- package/dist/elements/chunks/{loader-Cg6rO8tQ.js → loader-BmQH4s3V.js} +1 -1
- package/dist/elements/chunks/{markdown-n3Xbj3PR.js → markdown-Zi21WhUz.js} +7 -7
- package/dist/elements/chunks/{message-CgKytiSB.js → message-BqyXDN3-.js} +1 -1
- package/dist/elements/chunks/{message-feedback-Ds3-US0e.js → message-feedback-Djr3z6Yb.js} +1 -1
- package/dist/elements/chunks/message-square-vFAgbDaX.js +1 -0
- package/dist/elements/chunks/{minimize-2-3kCdE0q3.js → minimize-2--ifeCGrl.js} +1 -1
- package/dist/elements/chunks/{model-switcher-BMtXGwLU.js → model-switcher-B94YAKsM.js} +1 -1
- package/dist/elements/chunks/{overlay-B1-MBI6h.js → overlay-kD8dwRv_.js} +1 -1
- package/dist/elements/chunks/{paperclip-DDEfmkHc.js → paperclip-q21dYOSK.js} +1 -1
- package/dist/elements/chunks/{progress-bar-Dwbiyv3s.js → progress-bar-BrAIIaaJ.js} +1 -1
- package/dist/elements/chunks/{prompt-suggestion-9lvgFcEa.js → prompt-suggestion-Bjn2K-fR.js} +1 -1
- package/dist/elements/chunks/{reasoning-DzHWsdAJ.js → reasoning-DTpCGtnY.js} +1 -1
- package/dist/elements/chunks/resizable-Dp4JExql.js +1 -0
- package/dist/elements/chunks/{rotate-cw-jpisOdOV.js → rotate-cw-CFWWkpj2.js} +1 -1
- package/dist/elements/chunks/{scroll-area-g5Ze3K6f.js → scroll-area-Bb0kHH1j.js} +1 -1
- package/dist/elements/chunks/scroll-button-B0cH5fXf.js +1 -0
- package/dist/elements/chunks/{separator-Bmjc5XyX.js → separator-9kRgr1X9.js} +1 -1
- package/dist/elements/chunks/{settings-Cz1bMJP9.js → settings-B8lmec4D.js} +1 -1
- package/dist/elements/chunks/{settings-group-9imY3kRA.js → settings-group-I0hEuXiN.js} +1 -1
- package/dist/elements/chunks/{share-BdenF0wQ.js → share-C3lTiYGt.js} +1 -1
- package/dist/elements/chunks/skeleton-DSXW5Yya.js +1 -0
- package/dist/elements/chunks/{slots-DkZ-Cmha.js → slots--V19HwUb.js} +1 -1
- package/dist/elements/chunks/{star-DY6z1UUH.js → star-CSJtGxgv.js} +1 -1
- package/dist/elements/chunks/{store-th4VyJXM.js → store-CHyW95TP.js} +1 -1
- package/dist/elements/chunks/{text-shimmer-CEi-tlXr.js → text-shimmer-Cn9TmNpI.js} +1 -1
- package/dist/elements/chunks/textarea-CUwqAX0G.js +1 -0
- package/dist/elements/chunks/{thumbs-up-BR33KLfA.js → thumbs-up-PNVVThEF.js} +1 -1
- package/dist/elements/chunks/{toast-store-BEMda0fv.js → toast-store-DKbQn3Wn.js} +1 -1
- package/dist/elements/chunks/{tool-TMued3WO.js → tool-DjTRpIpl.js} +1 -1
- package/dist/elements/chunks/tooltip-CgBZCVKp.js +1 -0
- package/dist/elements/chunks/{triangle-alert-B07fX3Q8.js → triangle-alert-DsHTHCPm.js} +1 -1
- package/dist/elements/chunks/use-card-resolution-BSu_XHjH.js +1 -0
- package/dist/elements/chunks/variant-aurora-Dc4nQUia.js +218 -0
- package/dist/elements/chunks/variant-custom-y_3kVQhS.js +1 -0
- package/dist/elements/chunks/variant-wave-D5OR1-9Z.js +116 -0
- package/dist/elements/chunks/{video-MKp3LmNT.js → video-B7vmenoC.js} +1 -1
- package/dist/elements/chunks/x-GRUeeQFT.js +1 -0
- package/dist/elements/coachmark.js +1 -1
- package/dist/elements/code-block.js +1 -1
- package/dist/elements/command.js +1 -1
- package/dist/elements/compare.js +1 -1
- package/dist/elements/composer.js +1 -1
- package/dist/elements/confirm-card.js +1 -1
- package/dist/elements/context-meter.js +1 -1
- package/dist/elements/conversation-list.js +1 -1
- package/dist/elements/define.d.ts +11 -0
- package/dist/elements/dialog.js +1 -1
- package/dist/elements/editable-label.js +1 -1
- package/dist/elements/embed.js +1 -1
- package/dist/elements/empty.js +1 -1
- package/dist/elements/feedback-bar.js +1 -1
- package/dist/elements/file-tree.js +1 -1
- package/dist/elements/file-upload.js +1 -1
- package/dist/elements/form.js +1 -1
- package/dist/elements/hover-card.js +1 -1
- package/dist/elements/icon.js +1 -1
- package/dist/elements/image.js +1 -1
- package/dist/elements/input.js +1 -1
- package/dist/elements/kbd.js +1 -1
- package/dist/elements/link-preview.js +1 -1
- package/dist/elements/loader.js +1 -1
- package/dist/elements/markdown.js +1 -1
- package/dist/elements/menu.js +1 -1
- package/dist/elements/message-skills.js +1 -1
- package/dist/elements/message.js +1 -1
- package/dist/elements/model-switcher.js +1 -1
- package/dist/elements/nav.js +1 -1
- package/dist/elements/notice.js +1 -1
- package/dist/elements/pane-group.js +1 -1
- package/dist/elements/pane.js +1 -1
- package/dist/elements/popover.js +1 -1
- package/dist/elements/progress-bar.js +1 -1
- package/dist/elements/prompt-dock.js +1 -1
- package/dist/elements/prompt-input.js +1 -1
- package/dist/elements/prompt-suggestions.js +1 -1
- package/dist/elements/reasoning.js +1 -1
- package/dist/elements/remote.js +1 -1
- package/dist/elements/resizable.js +1 -1
- package/dist/elements/response-stream.js +1 -1
- package/dist/elements/screen.js +1 -1
- package/dist/elements/scroll-area.js +1 -1
- package/dist/elements/scroll-button.js +1 -1
- package/dist/elements/search.js +1 -1
- package/dist/elements/segmented.js +1 -1
- package/dist/elements/separator.js +1 -1
- package/dist/elements/setting-item.js +1 -1
- package/dist/elements/settings-group.js +1 -1
- package/dist/elements/skeleton.js +1 -1
- package/dist/elements/slots.d.ts +15 -0
- package/dist/elements/source.js +1 -1
- package/dist/elements/status.js +1 -1
- package/dist/elements/switch.js +1 -1
- package/dist/elements/tabs.js +1 -1
- package/dist/elements/tasks.js +1 -1
- package/dist/elements/text-shimmer.js +1 -1
- package/dist/elements/thinking-bar.js +1 -1
- package/dist/elements/thread.d.ts +1 -0
- package/dist/elements/thread.js +1 -0
- package/dist/elements/toast.js +1 -1
- package/dist/elements/tool.js +1 -1
- package/dist/elements/tooltip.js +1 -1
- package/dist/elements/voice-input.js +1 -1
- package/dist/elements/voice-output.js +1 -1
- package/dist/elements.d.ts +62 -0
- package/dist/index.js +3411 -3328
- package/dist/kai.es.js +1 -1
- package/dist/llms/llms-full.txt +70 -4
- package/dist/llms/llms.txt +3 -3
- package/dist/primitives/audio-bands.d.ts +106 -0
- package/dist/primitives/create-tween.d.ts +33 -0
- package/dist/primitives/use-audio-analysis.d.ts +149 -0
- package/dist/primitives/use-sequencer.d.ts +13 -0
- package/dist/primitives/use-voice-recorder.d.ts +1 -0
- package/dist/primitives/visualizer-sequences.d.ts +39 -0
- package/dist/react/index.d.ts +105 -0
- package/dist/react/use-voice-input.d.ts +15 -0
- package/dist/react.js +269 -240
- package/dist/register-impl-DQyejdfb.js +145 -0
- package/dist/test-utils/fake-clock.d.ts +45 -0
- package/dist/ui/resizable.d.ts +9 -3
- package/dist/variant-aurora-DVtGqVH6.js +218 -0
- package/dist/variant-custom-Dif-IV4u.js +1 -0
- package/dist/variant-wave-DbfNdvSi.js +116 -0
- package/frameworks/react/index.tsx +74 -1
- package/frameworks/react/use-voice-input.tsx +59 -0
- package/llms-full.txt +70 -4
- package/llms.txt +3 -3
- package/package.json +32 -7
- package/src/components/audio-visualizer/audio-visualizer.voice-fixture.ts +257 -0
- package/src/components/audio-visualizer/aurora.glsl.ts +330 -0
- package/src/components/audio-visualizer/index.tsx +442 -0
- package/src/components/audio-visualizer/shader-canvas.tsx +846 -0
- package/src/components/audio-visualizer/sizes.ts +54 -0
- package/src/components/audio-visualizer/variant-aurora.tsx +299 -0
- package/src/components/audio-visualizer/variant-bar.tsx +143 -0
- package/src/components/audio-visualizer/variant-custom.tsx +338 -0
- package/src/components/audio-visualizer/variant-grid.tsx +170 -0
- package/src/components/audio-visualizer/variant-radial.tsx +158 -0
- package/src/components/audio-visualizer/variant-wave.tsx +125 -0
- package/src/components/audio-visualizer/wave.glsl.ts +130 -0
- package/src/components/component-meta.json +34 -32
- package/src/components/composer.tsx +5 -0
- package/src/components/thread.tsx +177 -0
- package/src/elements/audio-visualizer.tsx +183 -0
- package/src/elements/chat-workspace.tsx +1 -1
- package/src/elements/compiled.css +1 -1
- package/src/elements/define.tsx +12 -1
- package/src/elements/element-manifest.json +8 -0
- package/src/elements/element-meta.json +287 -0
- package/src/elements/element-types.d.ts +62 -0
- package/src/elements/icon-names.json +2 -0
- package/src/elements/menu.tsx +7 -4
- package/src/elements/register-impl.ts +3 -0
- package/src/elements/resizable.tsx +78 -2
- package/src/elements/slots.ts +42 -0
- package/src/elements/thread.tsx +105 -0
- package/src/primitives/audio-bands.ts +174 -0
- package/src/primitives/create-tween.ts +214 -0
- package/src/primitives/use-audio-analysis.ts +321 -0
- package/src/primitives/use-sequencer.ts +53 -0
- package/src/primitives/use-voice-recorder.ts +16 -4
- package/src/primitives/visualizer-sequences.ts +350 -0
- package/src/test-utils/fake-clock.ts +88 -0
- package/src/ui/action-icons.ts +2 -1
- package/src/ui/icon.tsx +4 -0
- package/src/ui/overlay.tsx +8 -1
- package/src/ui/resizable.tsx +47 -9
- package/dist/elements/chunks/action-icons-Dtl8Ox5D.js +0 -1
- package/dist/elements/chunks/arrow-left-GbBceGBE.js +0 -1
- package/dist/elements/chunks/chat-thread-Dz2qbzvI.js +0 -1
- package/dist/elements/chunks/check-fhmRksq_.js +0 -1
- package/dist/elements/chunks/chevron-down-DcRg1aRU.js +0 -1
- package/dist/elements/chunks/chevron-right-ChzBcNJ-.js +0 -1
- package/dist/elements/chunks/circle-B4fTe9v6.js +0 -1
- package/dist/elements/chunks/circle-check-CJV-3Rem.js +0 -1
- package/dist/elements/chunks/collapsible-CWUAShMC.js +0 -1
- package/dist/elements/chunks/define-CNSKFZCd.js +0 -1
- package/dist/elements/chunks/hover-card-BQGdGAQ3.js +0 -1
- package/dist/elements/chunks/icon-CAyRqVrg.js +0 -1
- package/dist/elements/chunks/message-square-MmRkvc-M.js +0 -1
- package/dist/elements/chunks/resizable-Bq_eHxUm.js +0 -1
- package/dist/elements/chunks/skeleton-Pjc5jiaY.js +0 -1
- package/dist/elements/chunks/textarea-CboigarR.js +0 -1
- package/dist/elements/chunks/tooltip-Cft_Rxiw.js +0 -1
- package/dist/elements/chunks/use-card-resolution-M36zVciB.js +0 -1
- package/dist/elements/chunks/x-Ckwicf6g.js +0 -1
- package/dist/register-impl-DcjZDELj.js +0 -141
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { createSignal, createEffect, onCleanup, type Accessor } from 'solid-js';
|
|
2
|
+
import { reduceToBands, reduceToVolume } from './audio-bands';
|
|
3
|
+
|
|
4
|
+
export interface AudioAnalysisOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Number of frequency buckets to produce, or a live accessor for it.
|
|
7
|
+
* Default 5.
|
|
8
|
+
*
|
|
9
|
+
* An accessor is resolved INSIDE the analysis effect, so a change to
|
|
10
|
+
* whatever signal backs it (e.g. a caller's variant or size switching)
|
|
11
|
+
* rebuilds the analyser at the new bucket count instead of silently
|
|
12
|
+
* leaving `bands()` padded or truncated to a stale size.
|
|
13
|
+
*/
|
|
14
|
+
bands?: number | (() => number);
|
|
15
|
+
/**
|
|
16
|
+
* Low bin index of the pass window. NOT a frequency. Default 100 --
|
|
17
|
+
* upstream LiveKit's component value (see DEFAULTS below).
|
|
18
|
+
*/
|
|
19
|
+
loPass?: number;
|
|
20
|
+
/**
|
|
21
|
+
* High bin index of the pass window. NOT a frequency. Default 200 --
|
|
22
|
+
* upstream LiveKit's component value (see DEFAULTS below).
|
|
23
|
+
*
|
|
24
|
+
* Legitimately input-dependent, unlike `fftSize`/`smoothingTimeConstant`:
|
|
25
|
+
* the default window expects PROCESSED speech (an agent's TTS track, or a
|
|
26
|
+
* mic captured with AGC/noise suppression on). For raw, unprocessed input
|
|
27
|
+
* -- an un-gained recording, music, ambience -- a wide low window such as
|
|
28
|
+
* `loPass: 4, hiPass: 120` reads energy the default deliberately gates
|
|
29
|
+
* out; see DEFAULTS below for the trade both ways.
|
|
30
|
+
*/
|
|
31
|
+
hiPass?: number;
|
|
32
|
+
/** Minimum ms between updates. Default 32 (about 30fps). */
|
|
33
|
+
updateInterval?: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The default window is upstream LiveKit's COMPONENT window, bins 100-200:
|
|
38
|
+
* every shipped agents-ui visualizer passes `{ loPass: 100, hiPass: 200 }`
|
|
39
|
+
* (agent-audio-visualizer-bar.tsx:181-183, grid.tsx:279-281,
|
|
40
|
+
* radial.tsx:142-144 -- radial's loPass was 80 until their PR #1265). Their
|
|
41
|
+
* HOOK's own default is 100-600 (useTrackVolume.ts:95-101), but no shipped
|
|
42
|
+
* component uses it, so parity means matching the components.
|
|
43
|
+
*
|
|
44
|
+
* At fftSize 2048 that is ~2.34-4.69kHz at 48kHz (2.15-4.31kHz at 44.1kHz):
|
|
45
|
+
* the sibilance band, ABOVE where a room's noise floor lives. Everything at
|
|
46
|
+
* or below -100dB normalizes to exactly 0 (see normalizeDb), and a real
|
|
47
|
+
* room's tone measures ~17dB BELOW that floor across this window while
|
|
48
|
+
* sitting ~27dB ABOVE it across 86-258Hz (noise-floor diagnosis, table A).
|
|
49
|
+
* The narrow high window plus the hard -100dB floor IS upstream's noise
|
|
50
|
+
* gate -- there is no explicit gate anywhere in their pipeline -- and it is
|
|
51
|
+
* what keeps their idle bars perfectly still where a wide window shows the
|
|
52
|
+
* room breathing.
|
|
53
|
+
*
|
|
54
|
+
* The trade, measured on a real un-processed recording ("this is a test,
|
|
55
|
+
* testing one two three, hello world"): through 100-200, quiet
|
|
56
|
+
* natural-volume speech frames read all-zero (54% of that clip's frames;
|
|
57
|
+
* consonants and sibilance still register on the louder ones). Upstream
|
|
58
|
+
* lives with that because their input is conditioned before analysis -- an
|
|
59
|
+
* agent's loud TTS track, or a local mic captured with autoGainControl +
|
|
60
|
+
* noiseSuppression + echoCancellation + voiceIsolation (livekit-client
|
|
61
|
+
* defaults.ts:27-30) that lifts speech toward target level. Ours follows:
|
|
62
|
+
* the mic stories request the same constraint set. For RAW input where that
|
|
63
|
+
* trade reads wrong (un-gained recordings, music), `loPass: 4, hiPass: 120`
|
|
64
|
+
* (86Hz-2.6kHz: fundamental + first two formants) remains the measured
|
|
65
|
+
* opt-in -- it read those same quiet frames at mean 0.234 with only true
|
|
66
|
+
* silence at zero -- at the documented cost of visualizing the room's noise
|
|
67
|
+
* floor on the centre elements (the defect that reverted this default).
|
|
68
|
+
*/
|
|
69
|
+
export const DEFAULTS = {
|
|
70
|
+
bands: 5,
|
|
71
|
+
loPass: 100,
|
|
72
|
+
hiPass: 200,
|
|
73
|
+
updateInterval: 32,
|
|
74
|
+
} as const;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* `fftSize`/`smoothingTimeConstant` are deliberately NOT caller-configurable
|
|
78
|
+
* options, unlike everything above. They exist in two different, non-tunable
|
|
79
|
+
* shapes below instead: one AnalyserNode per reduction, each matching
|
|
80
|
+
* upstream LiveKit's own hook for that reduction. A single flat
|
|
81
|
+
* `smoothingTimeConstant` option (this hook's original design) is exactly
|
|
82
|
+
* the bug that made bars snap back to rest instead of easing like upstream's
|
|
83
|
+
* do: one value silently applied to both a fast reduction and a slow one.
|
|
84
|
+
* Hard-coding removes the only way a caller (or a future edit here) could
|
|
85
|
+
* reintroduce that.
|
|
86
|
+
*
|
|
87
|
+
* These analyser shapes (and DEFAULTS above) are EXPORTED as the kit's
|
|
88
|
+
* analysis-settings contract: external instrumentation -- the
|
|
89
|
+
* examples/internal/livekit-parity probe -- imports them instead of
|
|
90
|
+
* restating the numbers, so a change here propagates instead of drifting.
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Matches upstream's `useMultibandTrackVolume`, which drives the DOM
|
|
95
|
+
* bar/grid/radial variants: `{ fftSize: 2048 }`, no `smoothingTimeConstant`
|
|
96
|
+
* given, so the AnalyserNode uses the Web Audio spec default of 0.8. That
|
|
97
|
+
* slow decay (roughly 330ms to fall to 10% of a peak, at this hook's 32ms
|
|
98
|
+
* sample interval) is what makes bars ease back to rest after speech stops
|
|
99
|
+
* instead of snapping.
|
|
100
|
+
*/
|
|
101
|
+
export const BANDS_ANALYSER = {
|
|
102
|
+
fftSize: 2048,
|
|
103
|
+
smoothingTimeConstant: 0.8,
|
|
104
|
+
} as const;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Matches upstream's `useTrackVolume` as the wave/aura hooks call it:
|
|
108
|
+
* `{ fftSize: 512, smoothingTimeConstant: 0.55 }`
|
|
109
|
+
* (use-agent-audio-visualizer-wave.ts:55-56, aura.ts:62-63). Faster decay
|
|
110
|
+
* (roughly 123ms to 10% of peak) keeps the shaders' reactivity within the
|
|
111
|
+
* ~33ms lag the aurora variant was tuned against; the bands' slower 0.8
|
|
112
|
+
* here would make the shaders visibly sluggish. Upstream reaches the same
|
|
113
|
+
* two-analyser structure differently -- two hooks, each with its own
|
|
114
|
+
* analyser (and its own AudioContext) -- but the constants match ours
|
|
115
|
+
* exactly.
|
|
116
|
+
*
|
|
117
|
+
* `minDecibels`/`maxDecibels` are upstream's `createAudioAnalyser` defaults
|
|
118
|
+
* (livekit-client src/room/utils.ts:548-553), NOT the Web Audio spec's
|
|
119
|
+
* -100/-30. They only rescale getByteFrequencyData -- this analyser's whole
|
|
120
|
+
* output -- mapping the byte range over a 20dB window that saturates at
|
|
121
|
+
* -80dB. That is what makes upstream's volume scalar run hot (speech
|
|
122
|
+
* ~0.5-0.9) and their wave/aura feel alive; on the spec scale the same
|
|
123
|
+
* speech read ~3x colder here (0.31 vs 0.80, noise-floor diagnosis,
|
|
124
|
+
* addendum 1), leaving our shaders under-reacting. The BANDS analyser gets
|
|
125
|
+
* no such pair: it is read with getFloatFrequencyData, where these two
|
|
126
|
+
* properties have no effect at all.
|
|
127
|
+
*/
|
|
128
|
+
export const VOLUME_ANALYSER = {
|
|
129
|
+
fftSize: 512,
|
|
130
|
+
smoothingTimeConstant: 0.55,
|
|
131
|
+
minDecibels: -100,
|
|
132
|
+
maxDecibels: -80,
|
|
133
|
+
} as const;
|
|
134
|
+
|
|
135
|
+
/** `bands` accepts a plain number or a live accessor; read whichever was given. */
|
|
136
|
+
function resolveBandCount(bands: number | (() => number)): number {
|
|
137
|
+
return typeof bands === 'function' ? bands() : bands;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* One AudioContext for the whole page. Contexts are expensive and browsers cap
|
|
142
|
+
* how many can exist, so a per-mount context would break a page with several
|
|
143
|
+
* visualizers on it.
|
|
144
|
+
*/
|
|
145
|
+
let sharedContext: AudioContext | undefined;
|
|
146
|
+
|
|
147
|
+
function getContext(): AudioContext | undefined {
|
|
148
|
+
if (typeof AudioContext === 'undefined') return undefined;
|
|
149
|
+
sharedContext ??= new AudioContext();
|
|
150
|
+
return sharedContext;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* `createMediaElementSource` THROWS if called twice for the same element, and
|
|
155
|
+
* there is no API to ask whether an element already has a source node. Cache
|
|
156
|
+
* them. A WeakMap so a removed <audio> can still be collected.
|
|
157
|
+
*/
|
|
158
|
+
const elementSources = new WeakMap<HTMLMediaElement, MediaElementAudioSourceNode>();
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* `createMediaStreamSource` does NOT throw on a second call for the same
|
|
162
|
+
* stream, unlike the element API above -- it is legal per spec to build
|
|
163
|
+
* several independent source nodes from one MediaStream. In practice several
|
|
164
|
+
* simultaneous nodes reading the same stream is a known source of
|
|
165
|
+
* intermittent silent data loss in Chromium (observed here as `volume`
|
|
166
|
+
* sticking at 0 for several seconds with three or more visualizers on one
|
|
167
|
+
* live microphone). Cache and share one node per stream, exactly like the
|
|
168
|
+
* element path, so N consumers is one node with N analyser taps rather than
|
|
169
|
+
* N nodes racing each other.
|
|
170
|
+
*/
|
|
171
|
+
const streamSources = new WeakMap<MediaStream, MediaStreamAudioSourceNode>();
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* `instanceof MediaStream` is not usable here: that global does not exist in
|
|
175
|
+
* every environment (jsdom included), and referencing it throws a
|
|
176
|
+
* ReferenceError instead of returning false. Every DOM element carries a
|
|
177
|
+
* `tagName`; a MediaStream never does, so it is a safe, environment-agnostic
|
|
178
|
+
* discriminator between the two accepted source types.
|
|
179
|
+
*/
|
|
180
|
+
function isMediaElement(src: MediaStream | HTMLMediaElement): src is HTMLMediaElement {
|
|
181
|
+
return 'tagName' in src;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Resume a context parked by the autoplay policy, on the first user gesture. */
|
|
185
|
+
function resumeOnGesture(ctx: AudioContext): () => void {
|
|
186
|
+
if (ctx.state !== 'suspended') return () => {};
|
|
187
|
+
if (typeof document === 'undefined') return () => {};
|
|
188
|
+
|
|
189
|
+
const resume = () => void ctx.resume().catch(() => {});
|
|
190
|
+
const events = ['pointerdown', 'keydown', 'touchstart'] as const;
|
|
191
|
+
events.forEach((e) => document.addEventListener(e, resume, { once: true, passive: true }));
|
|
192
|
+
return () => events.forEach((e) => document.removeEventListener(e, resume));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Turn a live audio source into numbers a visualizer can draw.
|
|
197
|
+
*
|
|
198
|
+
* Runs TWO analysers off one source node: `bands` for the DOM variants and a
|
|
199
|
+
* scalar `volume` for the shader ones, each with its own `fftSize` and
|
|
200
|
+
* `smoothingTimeConstant` matching upstream's two separate hooks (see
|
|
201
|
+
* BANDS_ANALYSER / VOLUME_ANALYSER above). An earlier version of this hook
|
|
202
|
+
* shared a single analyser between both reductions as an optimization; that
|
|
203
|
+
* silently forced one smoothing behavior onto both and made bars snap back
|
|
204
|
+
* to rest instead of easing like upstream's do. What this still saves over
|
|
205
|
+
* upstream: one shared, cached source node per element/stream (see
|
|
206
|
+
* elementSources/streamSources below) instead of a fresh one per hook
|
|
207
|
+
* instance, and one requestAnimationFrame loop reading both analysers each
|
|
208
|
+
* tick instead of two independent timers.
|
|
209
|
+
*
|
|
210
|
+
* Safe to call with no source: it emits zeros and never constructs a context,
|
|
211
|
+
* which is what makes the state-driven (no audio) mode work.
|
|
212
|
+
*/
|
|
213
|
+
export function useAudioAnalysis(
|
|
214
|
+
source: () => MediaStream | HTMLMediaElement | undefined,
|
|
215
|
+
options: AudioAnalysisOptions = {},
|
|
216
|
+
): { bands: Accessor<number[]>; volume: Accessor<number> } {
|
|
217
|
+
const opts = { ...DEFAULTS, ...options };
|
|
218
|
+
const [bands, setBands] = createSignal<number[]>(new Array(resolveBandCount(opts.bands)).fill(0));
|
|
219
|
+
const [volume, setVolume] = createSignal(0);
|
|
220
|
+
|
|
221
|
+
createEffect(() => {
|
|
222
|
+
const src = source();
|
|
223
|
+
// Read INSIDE the effect, not from the outer `opts.bands` closure: when
|
|
224
|
+
// this is an accessor, calling it here is what makes the effect track it,
|
|
225
|
+
// so a later change reruns this whole setup (new analyser, right-sized
|
|
226
|
+
// arrays) instead of leaving the old bucket count wired up forever.
|
|
227
|
+
const bandCount = resolveBandCount(opts.bands);
|
|
228
|
+
|
|
229
|
+
// Reset to a correctly-sized zero array whenever the source or the band
|
|
230
|
+
// count changes, so a stale picture never lingers after the mic stops or
|
|
231
|
+
// the requested resolution changes.
|
|
232
|
+
setBands(new Array(bandCount).fill(0));
|
|
233
|
+
setVolume(0);
|
|
234
|
+
|
|
235
|
+
if (!src) return;
|
|
236
|
+
|
|
237
|
+
const ctx = getContext();
|
|
238
|
+
if (!ctx) return; // SSR, or a browser without Web Audio.
|
|
239
|
+
if (typeof requestAnimationFrame === 'undefined') return;
|
|
240
|
+
|
|
241
|
+
const stopResume = resumeOnGesture(ctx);
|
|
242
|
+
|
|
243
|
+
let node: AudioNode;
|
|
244
|
+
if (!isMediaElement(src)) {
|
|
245
|
+
let streamNode = streamSources.get(src);
|
|
246
|
+
if (!streamNode) {
|
|
247
|
+
streamNode = ctx.createMediaStreamSource(src);
|
|
248
|
+
streamSources.set(src, streamNode);
|
|
249
|
+
}
|
|
250
|
+
node = streamNode;
|
|
251
|
+
// Deliberately NOT connected to destination: that would echo the mic.
|
|
252
|
+
// Unlike the element path below, a stream source NEVER reaches
|
|
253
|
+
// destination, cached or not.
|
|
254
|
+
} else {
|
|
255
|
+
const el = src;
|
|
256
|
+
let elNode = elementSources.get(el);
|
|
257
|
+
if (!elNode) {
|
|
258
|
+
elNode = ctx.createMediaElementSource(el);
|
|
259
|
+
// Connect to destination exactly once, right here at creation, so the
|
|
260
|
+
// audio path does not depend on how many visualizers attach. Both
|
|
261
|
+
// analysers below are terminal side-taps: an AnalyserNode still
|
|
262
|
+
// receives data with nothing connected downstream of it, so neither
|
|
263
|
+
// one also connects to destination. If either did, N consumers on
|
|
264
|
+
// one element would sum to N times the amplitude.
|
|
265
|
+
elNode.connect(ctx.destination);
|
|
266
|
+
elementSources.set(el, elNode);
|
|
267
|
+
}
|
|
268
|
+
node = elNode;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Two analysers off the same source node, not one: see BANDS_ANALYSER /
|
|
272
|
+
// VOLUME_ANALYSER above for why they cannot share a smoothingTimeConstant.
|
|
273
|
+
const bandsAnalyser = ctx.createAnalyser();
|
|
274
|
+
bandsAnalyser.fftSize = BANDS_ANALYSER.fftSize;
|
|
275
|
+
bandsAnalyser.smoothingTimeConstant = BANDS_ANALYSER.smoothingTimeConstant;
|
|
276
|
+
|
|
277
|
+
const volumeAnalyser = ctx.createAnalyser();
|
|
278
|
+
volumeAnalyser.fftSize = VOLUME_ANALYSER.fftSize;
|
|
279
|
+
volumeAnalyser.smoothingTimeConstant = VOLUME_ANALYSER.smoothingTimeConstant;
|
|
280
|
+
// Byte-scale rescale, volume analyser ONLY -- see VOLUME_ANALYSER above.
|
|
281
|
+
volumeAnalyser.minDecibels = VOLUME_ANALYSER.minDecibels;
|
|
282
|
+
volumeAnalyser.maxDecibels = VOLUME_ANALYSER.maxDecibels;
|
|
283
|
+
|
|
284
|
+
node.connect(bandsAnalyser);
|
|
285
|
+
node.connect(volumeAnalyser);
|
|
286
|
+
|
|
287
|
+
const freq = new Float32Array(bandsAnalyser.frequencyBinCount);
|
|
288
|
+
const bytes = new Uint8Array(volumeAnalyser.frequencyBinCount);
|
|
289
|
+
|
|
290
|
+
let raf = 0;
|
|
291
|
+
let last = 0;
|
|
292
|
+
const step = (now: number) => {
|
|
293
|
+
if (now - last >= opts.updateInterval) {
|
|
294
|
+
bandsAnalyser.getFloatFrequencyData(freq);
|
|
295
|
+
volumeAnalyser.getByteFrequencyData(bytes);
|
|
296
|
+
setBands(reduceToBands(freq, bandCount, opts.loPass, opts.hiPass));
|
|
297
|
+
setVolume(reduceToVolume(bytes));
|
|
298
|
+
last = now;
|
|
299
|
+
}
|
|
300
|
+
raf = requestAnimationFrame(step);
|
|
301
|
+
};
|
|
302
|
+
raf = requestAnimationFrame(step);
|
|
303
|
+
|
|
304
|
+
onCleanup(() => {
|
|
305
|
+
cancelAnimationFrame(raf);
|
|
306
|
+
stopResume();
|
|
307
|
+
bandsAnalyser.disconnect();
|
|
308
|
+
volumeAnalyser.disconnect();
|
|
309
|
+
// Both the element and stream source nodes above are cached and shared
|
|
310
|
+
// across every consumer of the same element/stream: another consumer
|
|
311
|
+
// may still be using this one, and it can never be recreated. Drop
|
|
312
|
+
// only this consumer's own taps into it (the two-argument form, once
|
|
313
|
+
// per analyser), never the no-argument node.disconnect() -- that would
|
|
314
|
+
// tear the source down for everyone still using it.
|
|
315
|
+
node.disconnect(bandsAnalyser);
|
|
316
|
+
node.disconnect(volumeAnalyser);
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
return { bands, volume };
|
|
321
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createSignal, createEffect, onCleanup, createMemo, type Accessor } from 'solid-js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One requestAnimationFrame loop emitting a monotonically increasing tick
|
|
5
|
+
* whenever `interval()` milliseconds have elapsed.
|
|
6
|
+
*
|
|
7
|
+
* RAF rather than setInterval: the browser parks it on hidden tabs, so an
|
|
8
|
+
* off-screen visualizer costs nothing. Upstream leaks a timer here.
|
|
9
|
+
*
|
|
10
|
+
* An interval of `Infinity` (or anything non-finite) parks the loop entirely
|
|
11
|
+
* and holds the tick at 0. The radial variant uses that while `thinking`,
|
|
12
|
+
* where a CSS spin drives the motion instead.
|
|
13
|
+
*/
|
|
14
|
+
export function useSequencer(interval: () => number): Accessor<number> {
|
|
15
|
+
const [tick, setTick] = createSignal(0);
|
|
16
|
+
|
|
17
|
+
// Memoize the interval VALUE to isolate the effect from whatever else the
|
|
18
|
+
// interval getter might be transitively subscribed to (e.g. a props proxy
|
|
19
|
+
// that includes unrelated signals like `bands`). The memo only notifies
|
|
20
|
+
// downstream when the number itself changes, not when intermediate accessors
|
|
21
|
+
// that feed it change to the same final value. This is the same pattern as
|
|
22
|
+
// `uniformShapeKey` in `shader-canvas.tsx`.
|
|
23
|
+
const intervalMs = createMemo(() => interval());
|
|
24
|
+
|
|
25
|
+
createEffect(() => {
|
|
26
|
+
const ms = intervalMs();
|
|
27
|
+
|
|
28
|
+
// Reset on every interval change so a state transition restarts the
|
|
29
|
+
// sequence from its first frame rather than resuming mid-pattern.
|
|
30
|
+
// With the memo, this only fires on real changes (the interval VALUE),
|
|
31
|
+
// not on spurious re-runs from unrelated props churn.
|
|
32
|
+
setTick(0);
|
|
33
|
+
|
|
34
|
+
if (!Number.isFinite(ms) || ms <= 0) return;
|
|
35
|
+
if (typeof requestAnimationFrame === 'undefined') return;
|
|
36
|
+
|
|
37
|
+
let raf = 0;
|
|
38
|
+
let last = performance.now();
|
|
39
|
+
|
|
40
|
+
const step = (now: number) => {
|
|
41
|
+
if (now - last >= ms) {
|
|
42
|
+
setTick((t) => t + 1);
|
|
43
|
+
last = now;
|
|
44
|
+
}
|
|
45
|
+
raf = requestAnimationFrame(step);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
raf = requestAnimationFrame(step);
|
|
49
|
+
onCleanup(() => cancelAnimationFrame(raf));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return tick;
|
|
53
|
+
}
|
|
@@ -8,6 +8,7 @@ export function useVoiceRecorder(options: UseVoiceRecorderOptions = {}) {
|
|
|
8
8
|
const mimeType = options.mimeType ?? 'audio/webm;codecs=opus';
|
|
9
9
|
const [isRecording, setIsRecording] = createSignal(false);
|
|
10
10
|
const [error, setError] = createSignal<string | null>(null);
|
|
11
|
+
const [stream, setStream] = createSignal<MediaStream | undefined>();
|
|
11
12
|
|
|
12
13
|
let mediaRecorder: MediaRecorder | undefined;
|
|
13
14
|
let chunks: Blob[] = [];
|
|
@@ -17,14 +18,16 @@ export function useVoiceRecorder(options: UseVoiceRecorderOptions = {}) {
|
|
|
17
18
|
setError(null);
|
|
18
19
|
chunks = [];
|
|
19
20
|
try {
|
|
20
|
-
const
|
|
21
|
-
|
|
21
|
+
const mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
22
|
+
setStream(mediaStream);
|
|
23
|
+
mediaRecorder = new MediaRecorder(mediaStream, { mimeType });
|
|
22
24
|
mediaRecorder.ondataavailable = (e) => {
|
|
23
25
|
if (e.data.size > 0) chunks.push(e.data);
|
|
24
26
|
};
|
|
25
27
|
mediaRecorder.onstop = () => {
|
|
26
28
|
const blob = new Blob(chunks, { type: mimeType });
|
|
27
|
-
|
|
29
|
+
mediaStream.getTracks().forEach((t) => t.stop());
|
|
30
|
+
setStream(undefined);
|
|
28
31
|
setIsRecording(false);
|
|
29
32
|
resolveBlob?.(blob);
|
|
30
33
|
};
|
|
@@ -32,6 +35,15 @@ export function useVoiceRecorder(options: UseVoiceRecorderOptions = {}) {
|
|
|
32
35
|
setIsRecording(true);
|
|
33
36
|
return new Promise<Blob>((resolve) => { resolveBlob = resolve; });
|
|
34
37
|
} catch (err) {
|
|
38
|
+
// getUserMedia may have already succeeded (stream() is live) even
|
|
39
|
+
// though something after it threw, e.g. an unsupported mimeType
|
|
40
|
+
// rejected by `new MediaRecorder(...)`. Leaving that stream open would
|
|
41
|
+
// keep the microphone live with no indication anything is recording.
|
|
42
|
+
const liveStream = stream();
|
|
43
|
+
if (liveStream) {
|
|
44
|
+
liveStream.getTracks().forEach((t) => t.stop());
|
|
45
|
+
setStream(undefined);
|
|
46
|
+
}
|
|
35
47
|
setError(err instanceof Error ? err.message : 'Microphone access denied');
|
|
36
48
|
setIsRecording(false);
|
|
37
49
|
throw err;
|
|
@@ -46,5 +58,5 @@ export function useVoiceRecorder(options: UseVoiceRecorderOptions = {}) {
|
|
|
46
58
|
|
|
47
59
|
onCleanup(() => stop());
|
|
48
60
|
|
|
49
|
-
return { isRecording, error, start, stop };
|
|
61
|
+
return { isRecording, error, stream, start, stop };
|
|
50
62
|
}
|