New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

audio-type

Package Overview
Dependencies
Maintainers
3
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

audio-type

Detect the audio type of a Buffer/Uint8Array

latest
Source
npmnpm
Version
2.8.0
Version published
Weekly downloads
69K
-74.32%
Maintainers
3
Weekly downloads
 
Created
Source

audio-type test stable npm license

Detect the audio type of a ArrayBuffer/Uint8Array

Install

$ npm i audio-type

Usage

Node.js
import readChunk from 'read-chunk'; // npm install read-chunk
import audioType from 'audio-type';
var buffer = readChunk.sync('meow.wav', 0, 64);

audioType(buffer);
//=> wav
Browser
import audioType from './audio-type.js'

var xhr = new XMLHttpRequest();
xhr.open('GET', 'meow.flac');
xhr.responseType = 'arraybuffer';

xhr.onload = function () {
	audioType(this.response);
	//=> flac
};

xhr.send();

API

audioType(buffer)

Returns one of the keys below, or undefined if the format isn't recognized.

KeyFormatMagicOffset
wavWAVERIFF…WAVE0, 8
aiffAIFF/AIFCFORM…AIFF/AIFC0, 8
mp3MPEG audioMPEG sync (0xFF Ex) or TAG (ID3v1 trailer)0
aacAAC (ADTS)0xFFF sync, layer 000
flacFLAC, native or in OggfLaC, or OggS…\x7FFLAC0, or 0 and 28
ttaTrue AudioTTA10
m4aMPEG-4 audioftyp or M4A 4 or 0
opusOpus (in Ogg)OggS…OpusHead0, 28
ogaOggOggS0
qoaQuite OK Audioqoaf0
midMIDIMThd0
cafCore Audio Formatcaff0
wmaASF/WMAASF header GUID0
amrAMR#!AMR0
wvWavPackwvpk0
mpcMusepackMP+ (SV7) or MPCK (SV8)0
apeMonkey's AudioMAC 0
dsfDSD Stream FileDSD 0
dffDSDIFFFRM8…DSD 0, 12
eac3E-AC-3 (Dolby Digital Plus)0x0B77 sync, bsid 11–160
ac3AC-3 (Dolby Digital)0x0B77 sync, bsid ≤ 80
dtsDTS0x7FFE8001 (or its bit-reordered variants)0
itImpulse TrackerIMPM0
s3mScream Tracker 3SCRM44
xmExtended ModuleExtended Module: 0
modProTracker & friendsM.K., M!K!, xCHN, xxCH, FLTx, TDZx, CD81, OKTA1080
mkvMatroskaEBML header, DocType matroska0
webmWebMEBML header, DocType webm0
aviAVIRIFF…AVI 0, 8

Note: OpenMPT's .mptm format is IT-derived and reuses the IMPM magic verbatim — it is indistinguishable from .it by magic bytes alone and also detects as it.

buffer

Type: buffer (Node.js), arrayBuffer, uint8array

The first 64 bytes are enough for every format except mod, whose tag sits at offset 1080 (past the sample header table) — pass at least the first 1084 bytes if you need to detect trackers.

ID3v2 tags

mp3, flac, tta and aac files may carry a leading ID3v2 tag. audioType() skips it and inspects what follows: mp3 is only returned once a real MPEG sync is found after the tag — unless the tag's declared size runs past the end of the buffer you gave it, in which case mp3 is assumed (the overwhelming majority of ID3v2-tagged audio in the wild is MP3, and a truncated probe buffer — the common case — can't prove otherwise). dsf's optional ID3v2 tag lives at the end of the file, not the start, so it never enters into this.

License

MIT • ॐ

Keywords

audio

FAQs

Package last updated on 27 Sep 2026

Related posts