@waveform-playlist/recording 14.0.0-next.2 → 14.0.0-next.20
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/README.md +10 -9
- package/dist/index.d.mts +42 -26
- package/dist/index.d.ts +42 -26
- package/dist/index.js +174 -76
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +175 -77
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Audio recording support for waveform-playlist using AudioWorklet — mic capture
|
|
|
9
9
|
- **Sample-accurate VU metering** — a dedicated meter worklet measures peak/RMS on every sample, not just once per animation frame
|
|
10
10
|
- **Multi-channel recording** — auto-detects the microphone's actual channel count from the `MediaStream`
|
|
11
11
|
- **Overdub with latency compensation** — record against existing playback; the finalized clip's timeline position accounts for output latency and Tone.js scheduling lookahead, with an optional manual override
|
|
12
|
-
- **Device selection & hot-plug** — enumerate microphones, switch devices between takes (refused while actively recording — a mid-recording switch would silently record silence),
|
|
12
|
+
- **Device selection & hot-plug** — enumerate microphones, switch devices between takes (refused while actively recording — a mid-recording switch would silently record silence), no microphone is opened by the hooks themselves: when the open one is unplugged, `stream` is cleared and the app asks again
|
|
13
13
|
- **Pause/resume** — pauses the worklet itself, not just the UI
|
|
14
14
|
- **Hooks only** — no bundled UI components; wire the state into your own controls or `@waveform-playlist/ui-components`'s `SegmentedVUMeter`
|
|
15
15
|
|
|
@@ -24,6 +24,7 @@ npm install @waveform-playlist/recording
|
|
|
24
24
|
| Package | Purpose |
|
|
25
25
|
|---------|---------|
|
|
26
26
|
| `react` | ^19.0.0 |
|
|
27
|
+
| `react-dom` | ^19.0.0 — required transitively by `@waveform-playlist/ui-components` |
|
|
27
28
|
| `styled-components` | ^6.0.0 — required transitively by `@waveform-playlist/ui-components` |
|
|
28
29
|
| `tone` | ^15.0.0 — recording shares the global AudioContext with `@waveform-playlist/playout` |
|
|
29
30
|
|
|
@@ -41,14 +42,14 @@ import {
|
|
|
41
42
|
} from '@waveform-playlist/recording';
|
|
42
43
|
|
|
43
44
|
function RecordButton() {
|
|
44
|
-
const { stream,
|
|
45
|
+
const { stream, requestAccess } = useMicrophoneAccess();
|
|
45
46
|
const { isRecording, progress, startRecording, stopRecording } = useRecording(stream);
|
|
46
47
|
// `progress` is a source ({ duration, peaks }), not state: useRecording does
|
|
47
48
|
// not re-render as the take grows. This reads it 10 times a second.
|
|
48
49
|
const { duration } = useRecordingProgress(progress);
|
|
49
50
|
|
|
50
51
|
const handleRecord = async () => {
|
|
51
|
-
if (!
|
|
52
|
+
if (!stream) {
|
|
52
53
|
await requestAccess();
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
@@ -163,9 +164,9 @@ Stopping adds a new `AudioClip` to the track that was selected when the take STA
|
|
|
163
164
|
Manages microphone permission, device enumeration, and hot-plug detection.
|
|
164
165
|
|
|
165
166
|
**Returns (`UseMicrophoneAccessReturn`):**
|
|
166
|
-
- `stream: MediaStream | null`
|
|
167
|
+
- `stream: MediaStream | null` — the open microphone, `null` while none is open (before a grant, while a request opens one, after `stopStream()`, a failed request, an unplug or a hide); `stream !== null` says a microphone is open
|
|
167
168
|
- `devices: MicrophoneDevice[]` — `{ deviceId, label, groupId }`
|
|
168
|
-
- `
|
|
169
|
+
- `hasLabels: boolean` — `devices` names the real microphones. Browsers hide them until microphone permission is granted (usually one entry with an empty `deviceId`). In our runs (headless, fake devices) Chromium holding the permission named them before any stream was open, so a picker can offer them and `requestAccess(deviceId)` opens only the one chosen; Firefox and WebKit named them only once a stream was open
|
|
169
170
|
- `isLoading: boolean`
|
|
170
171
|
- `requestAccess: (deviceId?: string, audioConstraints?: MediaTrackConstraints) => Promise<void>`
|
|
171
172
|
- `stopStream: () => void`
|
|
@@ -187,7 +188,7 @@ The core AudioWorklet-based recording hook.
|
|
|
187
188
|
**Returns (`UseRecordingReturn`):**
|
|
188
189
|
- `isRecording: boolean`, `isPaused: boolean`
|
|
189
190
|
- `progress: RecordingProgressSource` — a source of `{ duration: number; peaks: (Int8Array | Int16Array)[] }` (seconds elapsed; one peaks entry per channel, growing live). Published once per animation frame while recording; the hook does not re-render for it. After a stop, `duration` is the recorded buffer's length
|
|
190
|
-
- `audioBuffer: AudioBuffer | null` — set after `stopRecording()` resolves
|
|
191
|
+
- `audioBuffer: AudioBuffer | null` — set after `stopRecording()` resolves, and when a take ends by itself (microphone unplugged, component hidden mid-take)
|
|
191
192
|
- `startRecording: () => Promise<boolean>` — resolves `true` when the capture pipeline actually started (`false`: no stream, already recording, worklet failure); check it before starting synchronized playback
|
|
192
193
|
- `stopRecording: () => Promise<AudioBuffer | null>` — awaits the worklet's final flush before resolving, so the last samples are never dropped
|
|
193
194
|
- `pauseRecording: () => void`, `resumeRecording: () => void` — pause/resume the worklet itself, not just the UI
|
|
@@ -225,13 +226,13 @@ Batteries-included hook: wires `useMicrophoneAccess` + `useMicrophoneLevel` + `u
|
|
|
225
226
|
- `samplesPerPixel?: number` (default: `1024`)
|
|
226
227
|
- `latencyOffset?: number` — seconds; overrides the auto-computed `outputLatency + lookAhead` compensation applied to the clip's start. `0` disables compensation; omit to auto-compute
|
|
227
228
|
|
|
228
|
-
**Returns (`UseIntegratedRecordingReturn`):** recording state (`isRecording`, `isPaused`, `recordingTrackId`: the track the running take was started on, `null` when none is running), the two live sources (`meter`: microphone levels; `progress`: the take's elapsed time and per-channel preview peaks), microphone state (`stream`, `devices`, `
|
|
229
|
+
**Returns (`UseIntegratedRecordingReturn`):** recording state (`isRecording`, `isPaused`, `recordingTrackId`: the track the running take was started on, `null` when none is running), the two live sources (`meter`: microphone levels; `progress`: the take's elapsed time and per-channel preview peaks), microphone state (`stream`, `null` while no microphone is open, `devices`, `hasLabels`, and `selectedDevice`: the id the open stream reports, `null` while no microphone is open; `'default'` in Chromium for the default microphone), controls (`startRecording` — resolves `true` when capture actually started, `false` with `error` set when the take is refused, `stopRecording`, `pauseRecording`, `resumeRecording`, `requestMicAccess`, `changeDevice`), and a combined `error`.
|
|
229
230
|
|
|
230
|
-
**Recording into a `@waveform-playlist/browser` playlist:** call `useRecordingSession({ isRecording, trackId: recordingTrackId })` (from `@waveform-playlist/browser`) in the component that calls `useIntegratedRecording`; the view's `<WaveformRecordingPreview>` only draws the take. For an overdub, also call `useEditorControls().setRecordingActive(true, trackId)` *before* `play()` — while the session is active the end-of-timeline auto-stop is suppressed (the take can run past existing audio) and the recorded-over track
|
|
231
|
+
**Recording into a `@waveform-playlist/browser` playlist:** call `useRecordingSession({ isRecording, trackId: recordingTrackId })` (from `@waveform-playlist/browser`) in the component that calls `useIntegratedRecording`; the view's `<WaveformRecordingPreview>` only draws the take. For an overdub, also call `useEditorControls().setRecordingActive(true, trackId)` *before* `play()` — while the session is active the end-of-timeline auto-stop is suppressed (the take can run past existing audio) and the recorded-over track plays muted for the take (punch-in replaces what it holds; `arrangement.setTrackRecording`, which leaves the track's own mute in the arrangement's mix alone): the mixer and the track's Mute button show it, the built-in `<TrackMuteButton />` is disabled, and `useTrack().isRecording` is true for it. A mute set on the track during the take stays after it. Both reset automatically when the recording ends; check `startRecording()`'s boolean and release the session on `false`. `play()` does nothing before the playlist's first ready, so a take started during the first load records without playback.
|
|
231
232
|
|
|
232
233
|
### Types
|
|
233
234
|
|
|
234
|
-
`
|
|
235
|
+
`MicrophoneDevice`, `RecordingOptions`, `UseRecordingReturn`, `UseMicrophoneAccessReturn` are all exported from the package root for consumers building their own UI around these hooks.
|
|
235
236
|
|
|
236
237
|
## Architecture
|
|
237
238
|
|
package/dist/index.d.mts
CHANGED
|
@@ -6,17 +6,6 @@ import { UseThrottledValueOptions } from '@waveform-playlist/ui-components';
|
|
|
6
6
|
* Types for the recording package
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
interface RecordingState {
|
|
10
|
-
isRecording: boolean;
|
|
11
|
-
isPaused: boolean;
|
|
12
|
-
duration: number;
|
|
13
|
-
sampleRate: number;
|
|
14
|
-
}
|
|
15
|
-
interface RecordingData {
|
|
16
|
-
buffer: AudioBuffer | null;
|
|
17
|
-
peaks: (Int8Array | Int16Array)[];
|
|
18
|
-
duration: number;
|
|
19
|
-
}
|
|
20
9
|
interface MicrophoneDevice {
|
|
21
10
|
deviceId: string;
|
|
22
11
|
label: string;
|
|
@@ -41,16 +30,6 @@ interface RecordingOptions {
|
|
|
41
30
|
* Default: 16
|
|
42
31
|
*/
|
|
43
32
|
bits?: 8 | 16;
|
|
44
|
-
/**
|
|
45
|
-
* Specific device ID to use for recording
|
|
46
|
-
*/
|
|
47
|
-
deviceId?: string;
|
|
48
|
-
/**
|
|
49
|
-
* MediaTrackConstraints for audio recording
|
|
50
|
-
* Use this to customize echo cancellation, noise suppression, auto gain control, latency, etc.
|
|
51
|
-
* Default: Recording-optimized settings (all processing disabled, latency: 0 for low latency)
|
|
52
|
-
*/
|
|
53
|
-
audioConstraints?: MediaTrackConstraints;
|
|
54
33
|
}
|
|
55
34
|
interface UseRecordingReturn {
|
|
56
35
|
isRecording: boolean;
|
|
@@ -77,9 +56,26 @@ interface UseRecordingReturn {
|
|
|
77
56
|
error: Error | null;
|
|
78
57
|
}
|
|
79
58
|
interface UseMicrophoneAccessReturn {
|
|
59
|
+
/**
|
|
60
|
+
* The open microphone, `null` while none is open: before the first grant,
|
|
61
|
+
* while a request is opening one (it stops the previous stream first),
|
|
62
|
+
* after `stopStream()`, a failed request, an unplug, or a hide. Test
|
|
63
|
+
* `stream !== null` to know whether a microphone is open (#947 removed
|
|
64
|
+
* `hasPermission`, a second copy of that).
|
|
65
|
+
*/
|
|
80
66
|
stream: MediaStream | null;
|
|
81
67
|
devices: MicrophoneDevice[];
|
|
82
|
-
|
|
68
|
+
/**
|
|
69
|
+
* True when `devices` names the real microphones, with their ids and
|
|
70
|
+
* labels. Browsers hide them until microphone permission is granted (the
|
|
71
|
+
* list is then usually one entry with an empty `deviceId`). Chromium holding
|
|
72
|
+
* the permission listed them before any stream was open (headless runs with
|
|
73
|
+
* fake devices), so a picker can offer them and open only the one chosen,
|
|
74
|
+
* with `requestAccess(deviceId)`; Firefox and WebKit listed them only once a
|
|
75
|
+
* stream was open. Changes only when the list is read again (mount,
|
|
76
|
+
* `devicechange`, a grant), and not when an enumeration fails.
|
|
77
|
+
*/
|
|
78
|
+
hasLabels: boolean;
|
|
83
79
|
isLoading: boolean;
|
|
84
80
|
requestAccess: (deviceId?: string, audioConstraints?: MediaTrackConstraints) => Promise<void>;
|
|
85
81
|
stopStream: () => void;
|
|
@@ -219,9 +215,24 @@ interface UseIntegratedRecordingReturn {
|
|
|
219
215
|
*/
|
|
220
216
|
progress: RecordingProgressSource;
|
|
221
217
|
error: Error | null;
|
|
218
|
+
/** `useMicrophoneAccess`'s `stream`: the open microphone, `null` while none
|
|
219
|
+
* is open. A microphone is open when `stream !== null`. */
|
|
222
220
|
stream: MediaStream | null;
|
|
223
221
|
devices: MicrophoneDevice[];
|
|
224
|
-
|
|
222
|
+
/** `useMicrophoneAccess`'s `hasLabels`: `devices` names the real
|
|
223
|
+
* microphones, so a picker can offer them before one is open and open only
|
|
224
|
+
* the one chosen, with `changeDevice(id)`. */
|
|
225
|
+
hasLabels: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* The id of the microphone that is open: the device the stream's track
|
|
228
|
+
* reports (`getSettings().deviceId`), `null` while no stream is open (also
|
|
229
|
+
* while a request is opening one: it closes the open stream first). It is
|
|
230
|
+
* read from the stream, so it names the microphone that records; a picker
|
|
231
|
+
* shows it only when `devices` holds it. For a stream opened without an id
|
|
232
|
+
* (`requestMicAccess()`), Chromium reported `'default'`, the id of its list's
|
|
233
|
+
* default entry, and Firefox and WebKit the device's own id (headless runs
|
|
234
|
+
* with fake devices).
|
|
235
|
+
*/
|
|
225
236
|
selectedDevice: string | null;
|
|
226
237
|
/** Start capturing on the selected track. Resolves `true` when the capture
|
|
227
238
|
* pipeline actually started — callers that synchronize playback with
|
|
@@ -232,8 +243,13 @@ interface UseIntegratedRecordingReturn {
|
|
|
232
243
|
* (still loading, failed to load, or a clip that cannot be made from it). */
|
|
233
244
|
startRecording: () => Promise<boolean>;
|
|
234
245
|
/** Stop the take and add it to the track it was started on, with one
|
|
235
|
-
* `arrangement.updateTrack()`: one undo step.
|
|
236
|
-
|
|
246
|
+
* `arrangement.updateTrack()`: one undo step. Resolves when the take is on
|
|
247
|
+
* its track (or was refused, with `error` set); it never rejects.
|
|
248
|
+
*
|
|
249
|
+
* A take that ends without this call is added the same way: when the
|
|
250
|
+
* microphone is unplugged (`error` then says so), and when the component
|
|
251
|
+
* using the hook unmounts or is hidden mid-take. */
|
|
252
|
+
stopRecording: () => Promise<void>;
|
|
237
253
|
pauseRecording: () => void;
|
|
238
254
|
resumeRecording: () => void;
|
|
239
255
|
requestMicAccess: () => Promise<void>;
|
|
@@ -255,4 +271,4 @@ declare function useIntegratedRecording(arrangement: Arrangement, selectedTrackI
|
|
|
255
271
|
*/
|
|
256
272
|
declare function useRecordingProgress(progress: RecordingProgressSource, options?: UseThrottledValueOptions): RecordingProgress;
|
|
257
273
|
|
|
258
|
-
export { type IntegratedRecordingOptions, type MicrophoneDevice, type
|
|
274
|
+
export { type IntegratedRecordingOptions, type MicrophoneDevice, type RecordingOptions, type UseIntegratedRecordingReturn, type UseMicrophoneAccessReturn, type UseMicrophoneLevelOptions, type UseMicrophoneLevelReturn, type UseRecordingReturn, useIntegratedRecording, useMicrophoneAccess, useMicrophoneLevel, useRecording, useRecordingProgress };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,17 +6,6 @@ import { UseThrottledValueOptions } from '@waveform-playlist/ui-components';
|
|
|
6
6
|
* Types for the recording package
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
interface RecordingState {
|
|
10
|
-
isRecording: boolean;
|
|
11
|
-
isPaused: boolean;
|
|
12
|
-
duration: number;
|
|
13
|
-
sampleRate: number;
|
|
14
|
-
}
|
|
15
|
-
interface RecordingData {
|
|
16
|
-
buffer: AudioBuffer | null;
|
|
17
|
-
peaks: (Int8Array | Int16Array)[];
|
|
18
|
-
duration: number;
|
|
19
|
-
}
|
|
20
9
|
interface MicrophoneDevice {
|
|
21
10
|
deviceId: string;
|
|
22
11
|
label: string;
|
|
@@ -41,16 +30,6 @@ interface RecordingOptions {
|
|
|
41
30
|
* Default: 16
|
|
42
31
|
*/
|
|
43
32
|
bits?: 8 | 16;
|
|
44
|
-
/**
|
|
45
|
-
* Specific device ID to use for recording
|
|
46
|
-
*/
|
|
47
|
-
deviceId?: string;
|
|
48
|
-
/**
|
|
49
|
-
* MediaTrackConstraints for audio recording
|
|
50
|
-
* Use this to customize echo cancellation, noise suppression, auto gain control, latency, etc.
|
|
51
|
-
* Default: Recording-optimized settings (all processing disabled, latency: 0 for low latency)
|
|
52
|
-
*/
|
|
53
|
-
audioConstraints?: MediaTrackConstraints;
|
|
54
33
|
}
|
|
55
34
|
interface UseRecordingReturn {
|
|
56
35
|
isRecording: boolean;
|
|
@@ -77,9 +56,26 @@ interface UseRecordingReturn {
|
|
|
77
56
|
error: Error | null;
|
|
78
57
|
}
|
|
79
58
|
interface UseMicrophoneAccessReturn {
|
|
59
|
+
/**
|
|
60
|
+
* The open microphone, `null` while none is open: before the first grant,
|
|
61
|
+
* while a request is opening one (it stops the previous stream first),
|
|
62
|
+
* after `stopStream()`, a failed request, an unplug, or a hide. Test
|
|
63
|
+
* `stream !== null` to know whether a microphone is open (#947 removed
|
|
64
|
+
* `hasPermission`, a second copy of that).
|
|
65
|
+
*/
|
|
80
66
|
stream: MediaStream | null;
|
|
81
67
|
devices: MicrophoneDevice[];
|
|
82
|
-
|
|
68
|
+
/**
|
|
69
|
+
* True when `devices` names the real microphones, with their ids and
|
|
70
|
+
* labels. Browsers hide them until microphone permission is granted (the
|
|
71
|
+
* list is then usually one entry with an empty `deviceId`). Chromium holding
|
|
72
|
+
* the permission listed them before any stream was open (headless runs with
|
|
73
|
+
* fake devices), so a picker can offer them and open only the one chosen,
|
|
74
|
+
* with `requestAccess(deviceId)`; Firefox and WebKit listed them only once a
|
|
75
|
+
* stream was open. Changes only when the list is read again (mount,
|
|
76
|
+
* `devicechange`, a grant), and not when an enumeration fails.
|
|
77
|
+
*/
|
|
78
|
+
hasLabels: boolean;
|
|
83
79
|
isLoading: boolean;
|
|
84
80
|
requestAccess: (deviceId?: string, audioConstraints?: MediaTrackConstraints) => Promise<void>;
|
|
85
81
|
stopStream: () => void;
|
|
@@ -219,9 +215,24 @@ interface UseIntegratedRecordingReturn {
|
|
|
219
215
|
*/
|
|
220
216
|
progress: RecordingProgressSource;
|
|
221
217
|
error: Error | null;
|
|
218
|
+
/** `useMicrophoneAccess`'s `stream`: the open microphone, `null` while none
|
|
219
|
+
* is open. A microphone is open when `stream !== null`. */
|
|
222
220
|
stream: MediaStream | null;
|
|
223
221
|
devices: MicrophoneDevice[];
|
|
224
|
-
|
|
222
|
+
/** `useMicrophoneAccess`'s `hasLabels`: `devices` names the real
|
|
223
|
+
* microphones, so a picker can offer them before one is open and open only
|
|
224
|
+
* the one chosen, with `changeDevice(id)`. */
|
|
225
|
+
hasLabels: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* The id of the microphone that is open: the device the stream's track
|
|
228
|
+
* reports (`getSettings().deviceId`), `null` while no stream is open (also
|
|
229
|
+
* while a request is opening one: it closes the open stream first). It is
|
|
230
|
+
* read from the stream, so it names the microphone that records; a picker
|
|
231
|
+
* shows it only when `devices` holds it. For a stream opened without an id
|
|
232
|
+
* (`requestMicAccess()`), Chromium reported `'default'`, the id of its list's
|
|
233
|
+
* default entry, and Firefox and WebKit the device's own id (headless runs
|
|
234
|
+
* with fake devices).
|
|
235
|
+
*/
|
|
225
236
|
selectedDevice: string | null;
|
|
226
237
|
/** Start capturing on the selected track. Resolves `true` when the capture
|
|
227
238
|
* pipeline actually started — callers that synchronize playback with
|
|
@@ -232,8 +243,13 @@ interface UseIntegratedRecordingReturn {
|
|
|
232
243
|
* (still loading, failed to load, or a clip that cannot be made from it). */
|
|
233
244
|
startRecording: () => Promise<boolean>;
|
|
234
245
|
/** Stop the take and add it to the track it was started on, with one
|
|
235
|
-
* `arrangement.updateTrack()`: one undo step.
|
|
236
|
-
|
|
246
|
+
* `arrangement.updateTrack()`: one undo step. Resolves when the take is on
|
|
247
|
+
* its track (or was refused, with `error` set); it never rejects.
|
|
248
|
+
*
|
|
249
|
+
* A take that ends without this call is added the same way: when the
|
|
250
|
+
* microphone is unplugged (`error` then says so), and when the component
|
|
251
|
+
* using the hook unmounts or is hidden mid-take. */
|
|
252
|
+
stopRecording: () => Promise<void>;
|
|
237
253
|
pauseRecording: () => void;
|
|
238
254
|
resumeRecording: () => void;
|
|
239
255
|
requestMicAccess: () => Promise<void>;
|
|
@@ -255,4 +271,4 @@ declare function useIntegratedRecording(arrangement: Arrangement, selectedTrackI
|
|
|
255
271
|
*/
|
|
256
272
|
declare function useRecordingProgress(progress: RecordingProgressSource, options?: UseThrottledValueOptions): RecordingProgress;
|
|
257
273
|
|
|
258
|
-
export { type IntegratedRecordingOptions, type MicrophoneDevice, type
|
|
274
|
+
export { type IntegratedRecordingOptions, type MicrophoneDevice, type RecordingOptions, type UseIntegratedRecordingReturn, type UseMicrophoneAccessReturn, type UseMicrophoneLevelOptions, type UseMicrophoneLevelReturn, type UseRecordingReturn, useIntegratedRecording, useMicrophoneAccess, useMicrophoneLevel, useRecording, useRecordingProgress };
|