Skip to content

Latest commit

 

History

History
90 lines (62 loc) · 2.51 KB

File metadata and controls

90 lines (62 loc) · 2.51 KB

libsonare

CI npm PyPI License

Fast, dependency-free audio analysis library for browser and Node.js via WebAssembly. A librosa-like API for music information retrieval -- tens of times faster than Python.

Installation

npm install @libraz/libsonare

Usage

import { init, detectBpm, detectKey, analyze, Audio } from '@libraz/libsonare';

await init();

// Function API
const bpm = detectBpm(samples, sampleRate);
const key = detectKey(samples, sampleRate);
const result = analyze(samples, sampleRate);
console.log(`BPM: ${result.bpm}, Key: ${result.key.name}`);

// Audio class API
const audio = Audio.fromBuffer(samples, sampleRate);
console.log(`BPM: ${audio.detectBpm()}`);
console.log(`Key: ${audio.detectKey().name}`);

Browser (CDN)

<script type="module">
  import { init, analyze } from 'https://esm.sh/@libraz/libsonare';

  await init();
  // ... use with Web Audio API
</script>

Bundlers (Vite, webpack, Next.js, etc.)

If your bundler doesn't automatically resolve the .wasm file, specify its path:

import wasmUrl from '@libraz/libsonare/wasm?url'; // Vite
import { init } from '@libraz/libsonare';

await init({ wasmPath: wasmUrl });

Real-time Streaming

import { init, StreamAnalyzer } from '@libraz/libsonare';

await init();

const analyzer = new StreamAnalyzer({ sampleRate: 44100 });

// In audio processing callback
analyzer.process(audioChunk);

const stats = analyzer.stats();
console.log(`BPM: ${stats.estimate.bpm}, Key: ${stats.estimate.key}`);

Features

  • Detection: BPM, key, beats, onsets, chords, sections
  • Effects: HPSS, time stretch, pitch shift, normalize, trim
  • Features: STFT, mel spectrogram, MFCC, chroma, CQT/VQT, spectral features
  • Pitch: YIN, pYIN algorithms
  • Streaming: Real-time analysis with progressive estimates
  • Conversions: Hz/mel/MIDI/note, frames/time, resample

Also available

pip install libsonare  # Python bindings with CLI

License

Apache License 2.0