Skip to content

parseAudioMetadata

Parses audio format parameters out of a container header.

function parseAudioMetadata(buffer, format?): ParsedAudioMetadata | null;

Defined in: src/utils/audioFormat.ts:509

Parses audio format parameters out of a container header.

Parameters

ParameterTypeDescription
bufferArrayBufferThe audio data buffer to parse, starting at the first byte of the stream.
format?DetectedAudioFormatThe already-detected format, if known. Skips a redundant detectAudioFormat call.

Returns

ParsedAudioMetadata | null

The parsed parameters, or null if the format is unknown or the buffer does not yet reach the parameters.

Remarks

Where detectAudioFormat answers “which container is this?”, this function answers “what audio is inside it?” — enough to fill in AudioMetadata without the caller declaring the format.

Coverage:

FormatSample rateChannelsBit depthEncoding
WAVlinear16 / mulaw / alaw / mp3
OGGopus (Vorbis: none)
MP3mp3
FLAC
Others

Returns null when more bytes are needed. Container parameters can sit well past MIN_SNIFF_BYTES — behind a WAV LIST chunk or an ID3v2 tag, for instance — so a null result on a buffer whose format is detectable means “accumulate more data and call again”. Callers should stop accumulating at MAX_SNIFF_BYTES and fall back to the container format alone. null is also returned when no format is detected at all.

Example

import { parseAudioMetadata } from 'composite-voice';
import { readFileSync } from 'node:fs';

const wav = readFileSync('speech.wav');
parseAudioMetadata(wav.buffer);
// => { format: 'wav', mimeType: 'audio/wav', sampleRate: 16000,
//      channels: 1, bitDepth: 16, encoding: 'linear16' }

See

© 2026 CompositeVoice. All rights reserved.

Font size
Contrast
Motion
Transparency