recorder.svelte.ts

view source

Declarations
#

6 declarations

create_recorder_deps
#

recorder.svelte.ts view source

(): RecorderDeps import {create_recorder_deps} from '@fuzdev/zzz/recorder.svelte.js';

RecorderDeps over the real browser, each global read when it's called.

returns

RecorderDeps

Recorder
#

recorder.svelte.ts view source

import {Recorder} from '@fuzdev/zzz/recorder.svelte.js';

Records the microphone to a file on disk, uploading it as it's recorded.

App-level, so a recording carries on across route changes. capture owns the microphone; this owns where the chunks go and what happens after. The file is created under its final name and grows as chunks arrive (ChunkUpload over the backend's byte routes), so a crashed tab loses at most the last chunk; stopping uploads the rest and finalizes the file (media_finalize) so it has a duration and seeks, then — with transcribe_on_stop — queues its transcription.

Capture starts only in start, and only during a user gesture — nothing the backend sends can open the microphone. active is true the whole time it may be open and until the recording is saved, for the indicator every page shows.

inheritance

extends: Cell<typeof RecorderJson>

chunk_duration

type number

$state.raw

transcribe_on_stop

type boolean

$state.raw

capture

type AudioCapture

readonly

path

The file being recorded to — set once it's created, cleared when the recording ends.

type DiskfilePath | null

$state.raw

last_path

The last recording that stopped normally, whether or not it finalized.

type DiskfilePath | null

$state.raw

error

Why the last start, recording, or stop failed — cleared by the next start.

type string | null

$state.raw

uploaded_bytes

Bytes of the current recording the backend has confirmed.

type number

$state.raw

status

Where the recording is: the capture's status, and stopping until the file is saved.

type AudioCaptureStatus

readonly $derived.by

active

Whether the microphone may be open or the recording is still being saved.

type boolean

readonly $derived

constructor

type new (options: RecorderOptions): Recorder

options

start

Starts recording to a new file in dir, named for the current local time. Must be called from a user gesture (a click handler).

type (dir: string & $brand<"DiskfilePath"> & $brand<"DiskfileDirectoryPath">): Promise<void>

dir

the directory to create the recording in

returns Promise<void>

throws

  • Error - when one is already under way (leaving it and `error` untouched), or when there's no backend to record to, no user gesture, the browser can't record, the microphone can't be opened, or the file can't be created — each of those also left in `error`

pause

Pauses a recording: the microphone stays open, nothing is recorded.

type (): void

returns void

resume

Resumes a paused recording.

type (): void

returns void

stop

Stops the recording: closes the microphone, uploads what's left, and finalizes the file. A failure to upload or finalize is left in error — the file is still there, as far as it got.

type (): Promise<(string & $brand<"DiskfilePath">) | null>

returns Promise<DiskfilePath | null>

the recording's path, or null when nothing was being recorded or the upload failed

dispose

Ends the recording without finalizing — the session is gone. Chunks the uploader already holds, and the last one the browser hands over as it stops, are still sent.

type (): void

returns void

duration

How long the current recording is so far — see AudioCapture.duration.

type number

getter

level

How loud the microphone is right now — see AudioCapture.level.

type number

getter

deps

type RecorderDeps

gettersetter

RecorderDeps
#

recorder.svelte.ts view source

RecorderDeps import type {RecorderDeps} from '@fuzdev/zzz/recorder.svelte.js';

The browser the recorder runs in — the microphone, and fetch for the upload — so a test can stand in for both.

inheritance

fetch

type (input: string, init?: RequestInit | undefined): Promise<Response>

input

type string

init?

type RequestInit
optional
returns Promise<Response>

RecorderJson
#

recorder.svelte.ts view source

value + type

{ id: string & $brand<"Uuid">; created: string & $brand<"Datetime">; updated: string & $brand<"Datetime">; chunk_duration: number; transcribe_on_stop: boolean; } import {RecorderJson} from '@fuzdev/zzz/recorder.svelte.js';

id

type string & $brand<"Uuid">

created

type string & $brand<"Datetime">

updated

Required and initially equal to created.

type string & $brand<"Datetime">

chunk_duration

How often the browser hands over a chunk to upload, in milliseconds — the most audio a crashed tab can lose.

type number

transcribe_on_stop

Whether a recording is transcribed, by the local model, once it's saved.

type boolean

RecorderJsonInput
#

recorder.svelte.ts view source

{ id?: string | undefined; created?: string | undefined; updated?: string | undefined; chunk_duration?: number | undefined; transcribe_on_stop?: boolean | undefined; } import type {RecorderJsonInput} from '@fuzdev/zzz/recorder.svelte.js';

id?

type string

created?

type string

updated?

Required and initially equal to created.

type string

chunk_duration?

How often the browser hands over a chunk to upload, in milliseconds — the most audio a crashed tab can lose.

type number

transcribe_on_stop?

Whether a recording is transcribed, by the local model, once it's saved.

type boolean

RecorderOptions
#

recorder.svelte.ts view source

RecorderOptions import type {RecorderOptions} from '@fuzdev/zzz/recorder.svelte.js';

inheritance

extends: CellOptions<typeof RecorderJson>

deps?

The browser to record with (default create_recorder_deps()).

type RecorderDeps

Depends on
#

Imported by
#