@zsherman/sound 0.0.0-stage → 0.1.1

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE +373 -0
  3. package/README.md +16 -2
  4. package/dist/dom/engine/cues.js +69 -0
  5. package/dist/dom/engine/engine.js +104 -0
  6. package/dist/dom/engine/index.js +4 -0
  7. package/dist/dom/engine/synth.js +172 -0
  8. package/dist/dom/engine/types.js +0 -0
  9. package/dist/dom/index.js +9 -0
  10. package/dist/dom/sound-provider/index.js +1 -0
  11. package/dist/dom/sound-provider/sound-provider.js +75 -0
  12. package/dist/dom/themes/glass.js +47 -0
  13. package/dist/dom/themes/index.js +5 -0
  14. package/dist/dom/themes/mechanical.js +46 -0
  15. package/dist/dom/themes/score.js +210 -0
  16. package/dist/dom/themes/soft.js +28 -0
  17. package/dist/solid/engine/cues.jsx +69 -0
  18. package/dist/solid/engine/engine.jsx +104 -0
  19. package/dist/solid/engine/index.jsx +4 -0
  20. package/dist/solid/engine/synth.jsx +172 -0
  21. package/dist/solid/engine/types.jsx +0 -0
  22. package/dist/solid/index.jsx +9 -0
  23. package/dist/solid/sound-provider/index.jsx +1 -0
  24. package/dist/solid/sound-provider/sound-provider.jsx +66 -0
  25. package/dist/solid/themes/glass.jsx +47 -0
  26. package/dist/solid/themes/index.jsx +5 -0
  27. package/dist/solid/themes/mechanical.jsx +46 -0
  28. package/dist/solid/themes/score.jsx +210 -0
  29. package/dist/solid/themes/soft.jsx +28 -0
  30. package/dist/types/engine/cues.d.ts +21 -0
  31. package/dist/types/engine/engine.d.ts +42 -0
  32. package/dist/types/engine/index.d.ts +6 -0
  33. package/dist/types/engine/synth.d.ts +28 -0
  34. package/dist/types/engine/types.d.ts +65 -0
  35. package/dist/types/index.d.ts +3 -0
  36. package/dist/types/sound-provider/index.d.ts +2 -0
  37. package/dist/types/sound-provider/sound-provider.d.ts +55 -0
  38. package/dist/types/themes/glass.d.ts +7 -0
  39. package/dist/types/themes/index.d.ts +5 -0
  40. package/dist/types/themes/mechanical.d.ts +7 -0
  41. package/dist/types/themes/score.d.ts +14 -0
  42. package/dist/types/themes/soft.d.ts +6 -0
  43. package/docs/api.json +55 -0
  44. package/docs/llms.txt +39 -0
  45. package/docs/search-index.json +25 -0
  46. package/docs/sound-provider.md +152 -0
  47. package/docs/sounds.md +203 -0
  48. package/package.json +56 -4
package/docs/sounds.md ADDED
@@ -0,0 +1,203 @@
1
+ # Sounds
2
+
3
+ <!-- search: sound, sounds, audio, sfx, sound effects, ui sounds, interface sounds, click sound, feedback sound, chime, beep, haptic, earcon, web audio, notification sound, success sound, error sound -->
4
+
5
+ 40 short interface sounds, called cues, in seven families (six for any interface, one for video calls). Each is built from Web Audio oscillators and filtered noise at the moment it plays: there are no audio files to load, cache or license, and a cue can follow the moment (a slider's tick rises with its value; `back` turns a sweep around). Three themes play the same gestures in different materials, matched in loudness so switching one never makes the interface louder.
6
+
7
+ ```tsx
8
+ import { useSound } from "@zsherman/sound/sound-provider";
9
+
10
+ const sound = useSound();
11
+ <Button onClick={() => { send(); sound.play("send"); }}>Send</Button>;
12
+ ```
13
+
14
+ Sound reinforces what the person sees; it never replaces it. Every cue the kit plays accompanies a visible change, and the interface must work the same with sound off.
15
+
16
+ ## Usage guidelines
17
+
18
+ - Turn sounds on with a `SoundProvider` at the root, and give the person a mute they control ([sound-provider.md](./sound-provider.md)). The kit's components then play their own cues.
19
+ - Play a cue yourself only for an outcome the kit can't see (a message sent, an upload finished), from the handler, once the change is on screen.
20
+ - Play the outcome, not every step: one cue per action, and none for what your code changes on its own (see When not to play).
21
+ - Pick the cue by what happened, not by how it sounds: the families below are meanings, and a theme changes how all of them sound at once.
22
+
23
+ ## Anatomy
24
+
25
+ ```tsx
26
+ <SoundProvider muted theme volume cues> // @zsherman/sound/sound-provider, once at the root
27
+ <App /> // kit components inside play their own cues
28
+ </SoundProvider>
29
+
30
+ const sound = useSound(); // in your component, for outcomes the kit can't see
31
+ sound.play(cue, { emphasis, value, direction, volume, pitch });
32
+ ```
33
+
34
+ ## Cues
35
+
36
+ | Family | Cue | When | Kit components that play it |
37
+ | --- | --- | --- | --- |
38
+ | Input | `tap` | A press that should be heard: a primary action, a key on a pad | `Button sound="tap"` |
39
+ | | `type` | A keystroke in a field that wants a typing sound (a terminal, a game) | — |
40
+ | | `tick` | A step of a value: a slider, a stepper, a dial. Pass `value` (0 to 1) to re-pitch it | `Slider` |
41
+ | | `drag` | A drag starts (an item lifts) | — |
42
+ | | `drop` | It lands | — |
43
+ | Selection | `toggle-on` / `toggle-off` | A switch turns on or off: siblings, a rising and a falling fifth | `Switch` |
44
+ | | `check` / `uncheck` | A checkbox | `Checkbox` |
45
+ | | `select` | One choice among several | `RadioGroup`, `SegmentedControl`, `Select`, `Combobox`, `Rating` (pitched by the score) |
46
+ | Navigation | `open` / `close` | A modal surface opens or closes | `Dialog`, `Sheet`, `AlertDialog` |
47
+ | | `expand` / `collapse` | Content shows or hides in place | `Accordion`, `Collapsible` |
48
+ | | `navigate` | A tab or a step; `direction: "back"` for a previous one | `Tabs` (direction from the tabs' order) |
49
+ | Feedback | `success` | An action finished well, after the fact (not on the press) | `success` toasts |
50
+ | | `warning` | Something needs attention but nothing failed | `warning` toasts |
51
+ | | `error` | An action failed | `error` toasts, `CopyButton` when copying fails |
52
+ | | `denied` | An action that can't happen now (a shortcut with nothing to act on) | — |
53
+ | Communication | `notify` | Something arrived for the person: a mention, a reminder | `info` and plain toasts |
54
+ | | `send` | The person sent something | `Button sound="send"` |
55
+ | | `receive` | A message arrived in an open conversation | — |
56
+ | Editing | `copy` | Copied to the clipboard | `CopyButton` |
57
+ | | `delete` | Something was deleted (after it is, not on the confirm dialog's open) | `Button sound="delete"` |
58
+ | | `complete` | A long task or a whole flow finished: an upload, an onboarding | — |
59
+ | Call | `mute` / `unmute` | Your own microphone turns off or on | `CallControlsDevice kind="microphone"` |
60
+ | | `muted-speaking` | You're talking while muted. Your app detects the voice; play it at most every 30 s or so | — |
61
+ | | `participant-join` / `participant-leave` | Someone else comes or goes. One per burst (1.5 s apart at most), and silent in calls over eight people | `TileLayout` (`presenceSounds`) |
62
+ | | `call-join` / `call-leave` | You're in the call, or out of it | `CallControlButton sound="call-leave"` |
63
+ | | `knock` | Someone is waiting in the lobby (play it for the hosts) | — |
64
+ | | `hand-raise` | A hand goes up (play it for the hosts or the presenter) | — |
65
+ | | `recording-start` / `recording-stop` | A recording or transcript has started or stopped, for everyone in the call, and on joining a call that's being captured | `CallControlsRecordingIndicator` |
66
+ | | `share-start` / `share-stop` | A screen share appears or ends | `TileLayout` (a tile with `isScreenShare`) |
67
+ | | `reconnecting` / `reconnected` | The connection dropped, or it's back | — |
68
+
69
+ Call cues play over people talking, so they sit lower (about 400 to 1,200 Hz), stay short and are quieter than the outcome cues. Recording has its own rhythm (two even pulses, then a held note) so it can't be mistaken for anything else. The call parts that play them are in `@zsherman/meeting`'s docs (call-controls.md and tile-layout.md, under "Sounds").
70
+
71
+ Every cue also takes `emphasis`: `subtle` drops its ornaments and most of its room (for something that happens often), `strong` adds them (for a moment worth marking). Emphasis is not a volume knob: use `volume` for that.
72
+
73
+ ```tsx
74
+ sound.play("success", { emphasis: "strong" });
75
+ sound.play("tick", { value: 0.8 }); // higher: near the end of the range
76
+ sound.play("navigate", { direction: "back" });
77
+ ```
78
+
79
+ ## When not to play
80
+
81
+ Silence is the default. A sound earns its place when it tells the person something they'd otherwise miss or wait for.
82
+
83
+ - One cue per action. Don't stack `tap`, `select` and `success` on one press: play the outcome.
84
+ - No hover sounds, no sounds on scroll, focus, or a layout change the person didn't cause.
85
+ - Nothing for changes made in code: the kit plays cues only for what the person did (a press, a key, a drag, a swipe), never when your code sets a value. An outcome (`success`, a toast) is the exception, because it reports something the person started.
86
+ - Not per item in a list that updates (a feed, streamed tokens, every row of an import): one cue when it settles.
87
+ - Not in password fields, and not for every keystroke unless typing sound is the point.
88
+ - `success` only after it succeeded, `delete` only after the deletion happened.
89
+ - Menus, popovers and tooltips are silent in the kit: they open too often to be heard each time.
90
+
91
+ ## Accessibility
92
+
93
+ - Never the only channel: every cue pairs with a visible change, and nothing depends on hearing it.
94
+ - Offer a mute the person controls, and remember it (see [sound-provider.md](./sound-provider.md)). A mute in settings is the minimum; a Sound switch near where sounds happen is better.
95
+ - No sound before the person interacts: browsers block audio until the first tap, click or key press, and the engine drops (not queues) cues until then, so a toast on page load is silent.
96
+ - Cues sit well below speech: they're short (most under a quarter of a second, keys and ticks 50 ms or less), peak below −5 dBFS before your volume, and frequent cues are the quietest, so they don't bury a screen reader.
97
+ - Sound is a separate preference from motion: `prefers-reduced-motion` doesn't mute it.
98
+
99
+ ## Themes
100
+
101
+ | Theme | Sound | For |
102
+ | --- | --- | --- |
103
+ | `soft` (default) | Warm mallets in a small room | Most products |
104
+ | `mechanical` | Dry keycaps and switches: a contact click over a short body, almost no room | Tools, terminals, dense and fast UI |
105
+ | `glass` | Bright struck bars that ring, a larger room | Calm, airy products; moments that should feel light |
106
+
107
+ ```tsx
108
+ import { glass } from "@zsherman/sound/themes";
109
+
110
+ <SoundProvider theme={glass}>…</SoundProvider>;
111
+ ```
112
+
113
+ A theme is data: per cue, a list of layers (at most 12), each an oscillator or filtered noise under an envelope.
114
+
115
+ ```ts
116
+ interface SoundTheme {
117
+ name: string;
118
+ room: number; // 0 (dry) to 1: how much reaches the shared room
119
+ gain: number; // level trim, so themes play equally loud
120
+ cues: Record<Cue, readonly Layer[]>;
121
+ }
122
+
123
+ type Layer = ToneLayer | NoiseLayer;
124
+ interface ToneLayer {
125
+ kind: "tone";
126
+ wave: "sine" | "triangle" | "square" | "sawtooth";
127
+ f: number; // Hz
128
+ to?: number; // Hz it sweeps to
129
+ glide?: number; // seconds the sweep takes
130
+ at?: number; // seconds after the cue starts
131
+ a?: number; // attack, seconds (default 0.002)
132
+ d: number; // decay to silence, seconds
133
+ peak: number; // 0 to 0.5
134
+ accent?: boolean; // dropped at emphasis "subtle", louder at "strong"
135
+ }
136
+ interface NoiseLayer {
137
+ kind: "noise";
138
+ filter: "bandpass" | "lowpass" | "highpass";
139
+ q?: number;
140
+ f: number;
141
+ to?: number;
142
+ glide?: number;
143
+ at?: number;
144
+ a?: number;
145
+ d: number;
146
+ peak: number;
147
+ accent?: boolean;
148
+ }
149
+ ```
150
+
151
+ Change a few cues of a built-in theme by spreading it:
152
+
153
+ ```ts
154
+ import type { SoundTheme } from "@zsherman/sound/engine";
155
+ import { soft } from "@zsherman/sound/themes";
156
+
157
+ const branded: SoundTheme = {
158
+ ...soft,
159
+ name: "branded",
160
+ cues: {
161
+ ...soft.cues,
162
+ notify: [
163
+ { kind: "tone", wave: "sine", f: 880, d: 0.2, peak: 0.2 },
164
+ { kind: "tone", wave: "sine", f: 1320, at: 0.09, d: 0.3, peak: 0.18 },
165
+ ],
166
+ },
167
+ };
168
+ ```
169
+
170
+ Or give the shared score (`score`: every cue's notes, rhythm and sweeps) a new voice with `defineTheme(name, room, gain, voice)`, where `voice` turns each layer of the score into your layers. The built-in themes are made this way, so a cue keeps its meaning (on rises, error falls) in every theme:
171
+
172
+ ```ts
173
+ import { defineTheme } from "@zsherman/sound/themes";
174
+
175
+ const muted = defineTheme("muted", 0.1, 1.2, (layer) =>
176
+ layer.kind === "tone" ? [{ ...layer, wave: "triangle", f: layer.f / 2, to: layer.to && layer.to / 2 }] : [],
177
+ );
178
+ ```
179
+
180
+ Keep a custom theme's peaks under about −3 dBFS and its loudness near the built-in themes': render cues with `renderCue` and measure them.
181
+
182
+ ## Engine
183
+
184
+ The provider runs on a framework-free engine. Use it directly outside Solid, or pass one to `SoundProvider engine={…}` to share it.
185
+
186
+ ```ts
187
+ import { createSoundEngine } from "@zsherman/sound/engine";
188
+
189
+ const sound = createSoundEngine({ volume: 0.6 }); // theme: soft, humanize: true
190
+ sound.play("success"); // false when muted, inside the cooldown, or audio isn't allowed yet
191
+ sound.set({ muted: true });
192
+ const stop = sound.subscribe(({ cue, theme, sounded }) => console.log(cue, theme, sounded));
193
+ ```
194
+
195
+ - `play(cue, options?)` plays now and returns whether it was accepted. A repeat of one cue within 60 ms (40 ms for `type` and `tick`) is dropped, so a held key or a fast drag doesn't machine-gun. Each play varies by up to ±15 cents and ±5 % level, so repeats don't sound stamped (`humanize: false` turns it off).
196
+ - `unlock()` starts audio from a gesture's handler ("Turn sound on") and resolves `true` once it runs, `false` if the browser doesn't allow it yet; it never rejects. Plays from a handler start audio themselves.
197
+ - `set({ theme, volume, muted, humanize })`, `get()`.
198
+ - `subscribe(listener)` reports every accepted cue (`sounded: false` when it was dropped because audio wasn't allowed yet or the page was hidden). Returns the unsubscribe.
199
+ - `dispose()` closes the audio context.
200
+
201
+ The engine is safe to create on the server: nothing touches the browser until the first play. Its audio context starts at the first play the browser allows and is suspended a few seconds after the last cue ends. Everything goes through a limiter, so cues that overlap don't clip.
202
+
203
+ `renderCue(theme, cue, options?)` renders a cue to an `AudioBuffer` with an `OfflineAudioContext` (no speaker, no humanizing, the same every time): for tests, a waveform, or exporting a file. `cueDuration(theme, cue)` is how long its layers ring, in seconds. `cueNames` lists every cue; `cueFamilies` groups them as the table above does.
package/package.json CHANGED
@@ -1,6 +1,58 @@
1
1
  {
2
2
  "name": "@zsherman/sound",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Interface sounds for @zsherman/kit: 40 cues (interface and video-call) synthesized with Web Audio when they play (no audio files), three themes, and a provider that lets the kit's components play them.",
5
+ "license": "MPL-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/zsherman/solid-ui.git",
9
+ "directory": "packages/sound"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "docs",
14
+ "README.md",
15
+ "LICENSE",
16
+ "CHANGELOG.md"
17
+ ],
18
+ "type": "module",
19
+ "sideEffects": false,
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/types/index.d.ts",
23
+ "solid": "./dist/solid/index.jsx",
24
+ "default": "./dist/dom/index.js"
25
+ },
26
+ "./engine": {
27
+ "types": "./dist/types/engine/index.d.ts",
28
+ "solid": "./dist/solid/engine/index.jsx",
29
+ "default": "./dist/dom/engine/index.js"
30
+ },
31
+ "./themes": {
32
+ "types": "./dist/types/themes/index.d.ts",
33
+ "solid": "./dist/solid/themes/index.jsx",
34
+ "default": "./dist/dom/themes/index.js"
35
+ },
36
+ "./sound-provider": {
37
+ "types": "./dist/types/sound-provider/index.d.ts",
38
+ "solid": "./dist/solid/sound-provider/index.jsx",
39
+ "default": "./dist/dom/sound-provider/index.js"
40
+ },
41
+ "./package.json": "./package.json"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "scripts": {
47
+ "build": "rm -rf dist && vp pack && tsrs -p tsconfig.build.json && node ../../tooling/dts-extensions.ts dist/types",
48
+ "typecheck": "tsrs -p tsconfig.json"
49
+ },
50
+ "devDependencies": {
51
+ "@zsherman/kit": "0.1.1"
52
+ },
53
+ "peerDependencies": {
54
+ "@solidjs/web": "^2.0.3",
55
+ "@zsherman/kit": "^0.1.1",
56
+ "solid-js": "^2.0.3"
57
+ }
58
+ }