https://github.com/audiojs/audio-type
Detect the audio type of a Buffer/Uint8Array
https://github.com/audiojs/audio-type
Last synced: 8 months ago
JSON representation
Detect the audio type of a Buffer/Uint8Array
- Host: GitHub
- URL: https://github.com/audiojs/audio-type
- Owner: audiojs
- License: mit
- Created: 2014-04-27T10:46:49.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T20:02:45.000Z (about 3 years ago)
- Last Synced: 2025-09-27T21:28:54.780Z (8 months ago)
- Language: JavaScript
- Size: 859 KB
- Stars: 25
- Watchers: 6
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# audio-type [](https://github.com/audiojs/audio-type/actions/workflows/test.js.yml) [](http://github.com/badges/stability-badges) [](https://www.npmjs.com/package/audio-type) [](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, 12);
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: `'mp3'`, `'oga'`, `'flac'`, `'wav'`, `'m4a'`, `'opus'`, `'qoa'`
#### buffer
Type: `buffer` *(Node.js)*, `arrayBuffer`, `uint8array`
It only needs the first 12 bytes.
## License
MIT • ॐ