What is audio-type?
The 'audio-type' npm package is used to detect the file type of a given audio buffer. It supports various audio formats and provides a simple interface to determine the type of audio data.
What are audio-type's main functionalities?
Detect Audio Type
This feature allows you to detect the type of an audio file by reading its buffer. The code sample demonstrates how to read an audio file into a buffer and then use the 'audio-type' package to determine its type.
const audioType = require('audio-type');
const fs = require('fs');
const buffer = fs.readFileSync('path/to/audio/file');
const type = audioType(buffer);
console.log(type); // e.g., 'mp3', 'wav', etc.
Other packages similar to audio-type
file-type
The 'file-type' package is a more general-purpose library that can detect the file type of various file formats, including audio, video, images, and more. It provides a broader range of file type detection compared to 'audio-type', which is specialized for audio files.
music-metadata
The 'music-metadata' package is used to parse audio files and extract metadata such as format, duration, and tags. While it provides more detailed information about audio files, including metadata, it also includes functionality to detect the file type, making it a more comprehensive tool compared to 'audio-type'.
audio-type
Detect the audio type of a Buffer/Uint8Array
Install
$ npm install --save audio-type
$ bower install --save audio-type
$ component install hemanth/audio-type
Usage
Node.js
var readChunk = require('read-chunk');
var audioType = require('audio-type');
var buffer = readChunk.sync('meow.wav', 0, 12);
audioType(buffer);
Browser
var xhr = new XMLHttpRequest();
xhr.open('GET', 'meow.flac');
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
audioType(new Uint8Array(this.response));
};
xhr.send();
API
audioType(buffer)
Returns: mp3
, oga
, flac
, wav
, m4a
, false
buffer
Type: buffer
(Node.js), uint8array
It only needs the first 12 bytes.
CLI
$ npm install --global audio-type
$ audio-type --help
Usage
$ cat <filename> | audio-type
$ audio-type <filename>
Example
$ cat meow.mp3 | audio-type
mp3
License
MIT © Hemanth.HM