Lab

audio-export

Exporting rendered sound to a file: the settings an export picks (format, bit depth or bitrate, a level left as it is, brought to its peak or to a loudness target) and exportSound, which measures, normalizes and encodes, saying how far it is

pnpm dlx shadcn@latest add @audio-ui/audio-export
import { DEFAULT_EXPORT_SETTINGS, exportSound } from "@/lib/audio-export";
Fileslib/audio-export.ts
Depends onNothing
npm@audio-ui/engine
Used byblock-audio-editor, export-dialog, export-dialog-demo
ExportKindWhat it is
ExportNormalizetypeHow an export is brought to a level: left as it is, its loudest sample to 0 dBFS, or to a loudness in LUFS with its true peak at -1 dBTP at most.
ExportSettingsinterface
DEFAULT_EXPORT_SETTINGSconstA 24-bit WAV, left at its level; an MP3 at 320 kbps once picked.
ExportStagetypeWhat an export is doing, for a progress readout.
ExportedSoundinterface
exportSoundfunctionTurns rendered channels into a file of settings, saying how far it is through onProgress: first measured (the page waits about half a second a minute of stereo), then encoded in chunks.

Usage

An export in one call: it measures the sound's loudness, normalizes it if asked (to its peak, or to -14, -16 or -23 LUFS with the true peak kept under -1 dBTP), encodes it, and says how loud the file came out.

import { DEFAULT_EXPORT_SETTINGS, exportSound } from "@/lib/audio-export";

const exported = await exportSound(
  channels,
  sampleRate,
  { ...DEFAULT_EXPORT_SETTINGS, normalize: -14 }, // "off", "peak", or a target in LUFS
  (stage, done) => setProgress(stage, done)
);

The Export dialog holds its settings; the measuring is loudness and the encoding audio-encode.

Built by Ouest Labs, the source code is available on GitHub.
RSS