For AI agents: the complete documentation index is available at https://anyformat.swc.rs/llms.txt, the full documentation bundle is available at https://anyformat.swc.rs/llms-full.txt, and this page is available as Markdown at https://anyformat.swc.rs/api/audio.md.

Audio

The audio family identifies audio formats from the leading bytes of a file.

LanguagePackageModule
Node.js@swc/anyformat-audio@swc/anyformat-audio
Pythonanyformat-audioanyformat_audio

Supported formats

IdentifierMIME typeFormat
mp3audio/mpegMPEG-1/2 Audio Layer III
aacaudio/aacAdvanced Audio Coding in an ADTS stream
m4aaudio/mp4MPEG-4 audio (.m4a, .m4b)
flacaudio/flacFree Lossless Audio Codec
wavaudio/wavWaveform Audio File Format
aiffaudio/aiffAudio Interchange File Format, including AIFF-C
opusaudio/opusOpus in an Ogg container
oggaudio/oggOgg with a codec other than Opus, usually Vorbis
midiaudio/midiStandard MIDI File
amraudio/amrAdaptive Multi-Rate audio

detect

Identifies the audio format of data from its leading bytes. Returns null in Node.js and None in Python when the format is not recognized.

detect skips a leading ID3v2 tag. Give it the whole tag and a few bytes of the audio stream after the tag.

Node.js

function detect(data: Uint8Array): DetectedFormat | null
import { readFile } from 'node:fs/promises'
import { detect } from '@swc/anyformat-audio'

detect(await readFile('song.flac'))
// => { format: 'flac', mimeType: 'audio/flac' }

Python

def detect(data: bytes) -> DetectedFormat | None
from pathlib import Path

import anyformat_audio

anyformat_audio.detect(Path("song.flac").read_bytes())
# => DetectedFormat(format='flac', mime_type='audio/flac')

DetectedFormat

A format identified by detect.

Node.jsPythonTypeDescription
formatformatstringThe stable lowercase identifier of the format, for example "mp3".
mimeTypemime_typestringThe most common MIME type of the format.

In Python, DetectedFormat is a final class with read-only properties, and the type of each property is str.

supportedFormats

Returns the identifier of each format that detect can return.

Node.js

function supportedFormats(): string[]
import { supportedFormats } from '@swc/anyformat-audio'

supportedFormats()
// => ['mp3', 'aac', 'm4a', 'flac', 'wav', 'aiff', 'opus', 'ogg', 'midi', 'amr']

Python

def supported_formats() -> list[str]
import anyformat_audio

anyformat_audio.supported_formats()
# => ['mp3', 'aac', 'm4a', 'flac', 'wav', 'aiff', 'opus', 'ogg', 'midi', 'amr']