@pomle/audio-ident

Ultrafast zero-dependency JavaScript library for identifying WAVE and FLAC files in the browser.

Usage no npm install needed!

<script type="module">
  import pomleAudioIdent from 'https://cdn.skypack.dev/@pomle/audio-ident';
</script>

README

audio-ident

Ultrafast zero-dependency JavaScript library for identifying WAVE and FLAC files in the browser.

Useful when you expect a user to upload big WAVE or FLAC files and want to ensure they comply with a specific format before the user have started sending data to your server.

Usage

  1. Install
npm install @pomle/audio-ident
  1. Import
import { identifyFile } from "@pomle/audio-ident";
  1. Call identifyFile with a File object from a DragEvent for example.
const handleDrop = async event => {
  event.preventDefault();
  const files = event.dataTransfer.files;
  for (const file of files) {
    const fileInfo = await identifyFile(file);
    console.log(fileInfo);
  }
}

fileInfo will contain an object like the following.

{
  type: "WAVE", 
  format: 1, /* A WAVE file may use compression. Format contains 1 if PCM (Uncompressed). */
  sampleRate: 44100, 
  channels: 2, 
  bitDepth: 16
}

Examples

Vanilla JS