# audio-type

> Detect the audio type of a Buffer/Uint8Array

Latest version **2.7.0** (published 2026-08-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install audio-type
pnpm add audio-type
yarn add audio-type
bun add audio-type
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.7.0 |
| Published | 2026-08-28 |
| First published | 2014-04-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=14 |
| Dependencies | 0 |
| Unpacked size | 15.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 26 |
| Author | Hemanth.HM |
| Maintainers | dfcreative, hemanth, dy |
| Keywords | audio, type, detect, format, wav, mp3, aac, flac, ogg, opus, m4a, aiff, midi, webm, amr, wma, caf, qoa, avi, mkv, matroska, ac3, eac3, dts, wv, wavpack, tta, mpc, musepack, ape, monkeysaudio, dsf, dff, dsd, mod, xm, s3m, it, tracker |

## Links

- npm: https://www.npmjs.com/package/audio-type
- Repository: https://github.com/audiojs/audio-type
- Homepage: https://github.com/audiojs/audio-type#readme
- Issues: https://github.com/audiojs/audio-type/issues
- Funding: https://github.com/sponsors/audiojs
- npm.io page: https://npm.io/package/audio-type

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 2.7.0 (latest) — 2026-08-28
- 2.6.0 — 2026-08-27
- 2.5.0 — 2026-08-27
- 2.4.2 — 2026-07-11
- 2.4.1 — 2026-04-07
- 2.4.0 — 2026-03-14
- 2.2.1 — 2023-03-03
- 2.2.0 — 2023-03-03
- 2.1.1 — 2023-03-03
- 2.1.0 — 2023-03-03
- 2.0.0 — 2023-03-02
- 1.0.2 — 2016-04-23
- 1.0.0 — 2015-01-13
- 0.3.0 — 2014-11-22
- 0.1.4 — 2014-05-08
- … 4 more at https://npm.io/package/audio-type/versions

## README

# audio-type [![test](https://github.com/audiojs/audio-type/actions/workflows/test.js.yml/badge.svg)](https://github.com/audiojs/audio-type/actions/workflows/test.js.yml) [![stable](https://img.shields.io/badge/stability-stable-brightgreen.svg)](http://github.com/badges/stability-badges) [![npm](https://img.shields.io/npm/v/audio-type.svg)](https://www.npmjs.com/package/audio-type) [![license](https://img.shields.io/npm/l/audio.svg)](https://www.npmjs.com/package/audio-type)

> Detect the audio type of a ArrayBuffer/Uint8Array

## Install

```sh
$ npm i audio-type
```

## Usage

##### Node.js

```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

```js
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.

| Key | Format | Magic | Offset |
| --- | --- | --- | --- |
| `wav` | WAVE | `RIFF`…`WAVE` | 0, 8 |
| `aiff` | AIFF/AIFC | `FORM`…`AIFF`/`AIFC` | 0, 8 |
| `mp3` | MPEG audio | MPEG sync (`0xFF Ex`) or `TAG` (ID3v1 trailer) | 0 |
| `aac` | AAC (ADTS) | `0xFFF` sync, layer 00 | 0 |
| `flac` | FLAC | `fLaC` | 0 |
| `tta` | True Audio | `TTA1` | 0 |
| `m4a` | MPEG-4 audio | `ftyp` or `M4A ` | 4 or 0 |
| `opus` | Opus (in Ogg) | `OggS`…`OpusHead` | 0, 28 |
| `oga` | Ogg | `OggS` | 0 |
| `qoa` | Quite OK Audio | `qoaf` | 0 |
| `mid` | MIDI | `MThd` | 0 |
| `caf` | Core Audio Format | `caff` | 0 |
| `wma` | ASF/WMA | ASF header GUID | 0 |
| `amr` | AMR | `#!AMR` | 0 |
| `wv` | WavPack | `wvpk` | 0 |
| `mpc` | Musepack | `MP+` (SV7) or `MPCK` (SV8) | 0 |
| `ape` | Monkey's Audio | `MAC ` | 0 |
| `dsf` | DSD Stream File | `DSD ` | 0 |
| `dff` | DSDIFF | `FRM8`…`DSD ` | 0, 12 |
| `eac3` | E-AC-3 (Dolby Digital Plus) | `0x0B77` sync, bsid 11–16 | 0 |
| `ac3` | AC-3 (Dolby Digital) | `0x0B77` sync, bsid ≤ 8 | 0 |
| `dts` | DTS | `0x7FFE8001` (or its bit-reordered variants) | 0 |
| `it` | Impulse Tracker | `IMPM` | 0 |
| `s3m` | Scream Tracker 3 | `SCRM` | 44 |
| `xm` | Extended Module | `Extended Module: ` | 0 |
| `mod` | ProTracker & friends | `M.K.`, `M!K!`, `xCHN`, `xxCH`, `FLTx`, `TDZx`, `CD81`, `OKTA` | 1080 |
| `mkv` | Matroska | EBML header, DocType `matroska` | 0 |
| `webm` | WebM | EBML header, DocType `webm` | 0 |
| `avi` | AVI | `RIFF`…`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 • <a href="https://github.com/krishnized/license/">ॐ</a>

---
_Source: https://npm.io/package/audio-type · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
