audio_capture.svelte.ts view source
100 import {AUDIO_CAPTURE_TICK_INTERVAL} from '@fuzdev/zzz/audio_capture.svelte.js'; How often AudioCapture.duration and AudioCapture.level update while the
microphone is open, in milliseconds.
Microphone capture in the browser, handing each recorded chunk to a sink — knowing nothing about where the chunks go or what the app does with them.
11 declarations
audio_capture.svelte.ts view source
100 import {AUDIO_CAPTURE_TICK_INTERVAL} from '@fuzdev/zzz/audio_capture.svelte.js'; How often AudioCapture.duration and AudioCapture.level update while the
microphone is open, in milliseconds.
audio_capture.svelte.ts view source
import {AudioCapture} from '@fuzdev/zzz/audio_capture.svelte.js'; Captures the microphone with MediaRecorder, handing each chunk to a sink
as it's recorded, with pause and resume, the duration so far, and a level.
Capture starts only in start, and only during a user gesture. active is
true the whole time the microphone may be open, for an indicator.
depstype AudioCaptureDeps
statustype AudioCaptureStatus
durationHow long the current capture is so far, in milliseconds, not counting paused time. Updates every AUDIO_CAPTURE_TICK_INTERVAL while recording, and keeps its last value once the capture ends.
type number
levelHow loud the microphone is right now, 0 to 1 — for a level meter. Updates every AUDIO_CAPTURE_TICK_INTERVAL while the microphone is open (paused included), and is 0 otherwise or where it can't be measured.
type number
activeWhether the microphone may be open: any status but idle.
type boolean
constructortype new (options?: AudioCaptureOptions): AudioCapture
options{}startOpens the microphone and the sink, and starts recording. Must be called from a user gesture (a click handler).
type <TSink extends AudioCaptureSink>(options: AudioCaptureStartOptions<TSink>): Promise<TSink | null>
optionsAudioCaptureStartOptions<TSink>Promise<TSink | null>the opened sink once recording, or null when the capture was
stopped or disposed before it got there
throws
Error - when one is already under way (leaving it untouched), or
when there's no user gesture, the browser can't record, the microphone
can't be opened, or the sink can't be opened — each of those after
closing whatever the start openedpausePauses a capture: the microphone stays open, nothing is recorded.
type (): void
voidresumeResumes a paused capture.
type (): void
voidstopStops the capture: hands the last chunk to the sink, closes the microphone, and closes the sink. A capture still starting is abandoned.
type (): Promise<AudioCaptureStopResult | null>
Promise<AudioCaptureStopResult | null>how closing the sink went, or null when nothing was being
recorded, or the capture failed or was disposed while stopping
disposeEnds the capture without closing the sink. The last chunk the browser hands over as it stops is still written to it.
type (): void
voidaudio_capture.svelte.ts view source
AudioCaptureDeps import type {AudioCaptureDeps} from '@fuzdev/zzz/audio_capture.svelte.js'; The browser a capture runs in — everything it touches outside itself, so a test can stand in for the microphone and the clock.
get_user_medianavigator.mediaDevices.getUserMedia.
type (constraints: MediaStreamConstraints): Promise<MediaStream>
constraintsMediaStreamConstraintsPromise<MediaStream>create_media_recordernew MediaRecorder(stream, options).
type (stream: MediaStream, options: MediaRecorderOptions): MediaRecorder
streamMediaStreamoptionsMediaRecorderOptionsMediaRecorderis_type_supportedMediaRecorder.isTypeSupported — false where there's no MediaRecorder.
type (mime_type: string): boolean
mime_typestringbooleancreate_level_meterA meter on stream (Web Audio), or null where it can't be made.
type (stream: MediaStream): LevelMeter | null
streamMediaStreamLevelMeter | nullhas_user_activationWhether a user gesture is in effect (navigator.userActivation.isActive)
— true in a browser that can't say.
type (): boolean
booleannowDate.now.
type (): number
numberaudio_capture.svelte.ts view source
AudioCaptureOptions import type {AudioCaptureOptions} from '@fuzdev/zzz/audio_capture.svelte.js'; deps?The browser to capture with (default create_audio_capture_deps()).
type AudioCaptureDeps
audio_capture.svelte.ts view source
AudioCaptureSink import type {AudioCaptureSink} from '@fuzdev/zzz/audio_capture.svelte.js'; Where a capture's chunks go — a file on a backend, local storage, anywhere.
writeTakes the next chunk, after every chunk written before it.
type (chunk: Blob): void
chunkBlobvoidcloseWaits for every written chunk to land.
type (): Promise<void>
Promise<void>throws
Error - when they didn'taudio_capture.svelte.ts view source
AudioCaptureStartOptions<TSink> import type {AudioCaptureStartOptions} from '@fuzdev/zzz/audio_capture.svelte.js'; AudioCaptureStartOptions<TSink extends AudioCaptureSink = AudioCaptureSink>TSinkchunk_durationHow often the browser hands over a chunk, in milliseconds — the most a sink can lose when the tab crashes.
type number
open_sinkOpens the sink for a capture in format, once the microphone is open.
fail ends the capture with a reason, for a sink that breaks while
chunks are still arriving; it's ignored once the capture has ended.
type (format: RecordingFormat, fail: (message: string) => void): Promise<TSink>
formatfail(message: string) => voidPromise<TSink>throws
Error - when the sink can't be opened, which ends the starton_failCalled when a capture under way breaks and has ended, with why.
type (message: string): void
messagestringvoidon_input_endedCalled when the microphone's track ends on its own — the device was unplugged, or the browser revoked the permission. Typically stops the capture the way its owner normally does.
type (): void
voidaudio_capture.svelte.ts view source
AudioCaptureStatus type "idle" | "starting" | "recording" | "paused" | "stopping"
import type {AudioCaptureStatus} from '@fuzdev/zzz/audio_capture.svelte.js'; Where a capture is: starting while the microphone opens and the sink
opens, stopping while the last chunk is handed over and the sink closes.
audio_capture.svelte.ts view source
AudioCaptureStopResult type ({ ok: true; } & object) | ({ ok: false; } & { message: string; })
import type {AudioCaptureStopResult} from '@fuzdev/zzz/audio_capture.svelte.js'; What a stop got from the sink: ok, or why closing it failed.
audio_capture.svelte.ts view source
(): AudioCaptureDeps import {create_audio_capture_deps} from '@fuzdev/zzz/audio_capture.svelte.js'; AudioCaptureDeps over the real browser, each global read when it's called.
AudioCaptureDeps audio_capture.svelte.ts view source
(stream: MediaStream): LevelMeter | null import {create_level_meter} from '@fuzdev/zzz/audio_capture.svelte.js'; A LevelMeter over Web Audio: an AnalyserNode on the stream, read as the
peak of its latest samples. It only listens — nothing is routed to the
speakers. null where there's no AudioContext.
streamMediaStreamLevelMeter | null
audio_capture.svelte.ts view source
LevelMeter import type {LevelMeter} from '@fuzdev/zzz/audio_capture.svelte.js'; Reads how loud a live stream is right now.
readThe current peak level, 0 (silence) to 1 (full scale).
type (): number
numbercloseReleases what the meter holds.
type (): void
void