audio-type

Detect the audio type of a Buffer/Uint8Array

audio-type

Detect the audio type of a Buffer/Uint8Array

$ npm install --save audio-type
$ bower install --save audio-type
$ component install hemanth/audio-type
var readChunk = require('read-chunk'); // npm install read-chunk 
var audioType = require('audio-type');
var buffer = readChunk.sync('meow.wav', 0, 12);
 
audioType(buffer);
//=> wav 
var xhr = new XMLHttpRequest();
xhr.open('GET', 'meow.flac');
xhr.responseType = 'arraybuffer';
 
xhr.onload = function () {
    audioType(new Uint8Array(this.response));
    //=> flac 
};
 
xhr.send();

Returns: mp3, oga, flac, wav, m4a, false

Type: buffer (Node.js), uint8array

It only needs the first 12 bytes.

$ npm install --global audio-type
$ audio-type --help
 
Usage
  $ cat <filename> | audio-type
  $ audio-type <filename>
 
Example
  $ cat meow.mp3 | audio-type
  mp3

MIT © Hemanth.HM