pnpm dlx shadcn@latest add @audio-ui/audio-export
import { DEFAULT_EXPORT_SETTINGS, exportSound } from "@/lib/audio-export";| Files | lib/audio-export.ts |
|---|---|
| Depends on | Nothing |
| npm | @audio-ui/engine |
| Used by | block-audio-editor, export-dialog, export-dialog-demo |
| Export | Kind | What it is |
|---|---|---|
ExportNormalize | type | How 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. |
ExportSettings | interface | |
DEFAULT_EXPORT_SETTINGS | const | A 24-bit WAV, left at its level; an MP3 at 320 kbps once picked. |
ExportStage | type | What an export is doing, for a progress readout. |
ExportedSound | interface | |
exportSound | function | Turns 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.