Detect the audio type of a ArrayBuffer/Uint8Array
$ npm i audio-type
import readChunk from 'read-chunk'; // npm install read-chunk
import audioType from 'audio-type';
var buffer = readChunk.sync('meow.wav', 0, 12);
audioType(buffer);
//=> wav
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();
Returns: 'mp3'
, 'oga'
, 'flac'
, 'wav'
, 'm4a'
, 'opus'
, 'qoa'
Type: buffer
(Node.js), arrayBuffer
, uint8array
It only needs the first 12 bytes.
MIT • ॐ