@libraz/libsonare 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/README.npm.md +24 -0
- package/dist/sonare.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
|
|
8
8
|
Fast, dependency-free audio analysis library for browser and Node.js via WebAssembly.
|
|
9
9
|
|
|
10
|
+
> **Audio input:** This package expects already-decoded `Float32Array` mono
|
|
11
|
+
> samples (it does not bundle a file decoder). Use the Web Audio API in the
|
|
12
|
+
> browser or `node:wasi` / a JS audio decoder in Node to obtain samples.
|
|
13
|
+
> If you need to read WAV/MP3/M4A files directly in Node, use the native
|
|
14
|
+
> N-API package [`@libraz/libsonare-native`](https://github.com/libraz/libsonare/tree/main/bindings/node) instead.
|
|
15
|
+
|
|
10
16
|
## Installation
|
|
11
17
|
|
|
12
18
|
```bash
|
|
@@ -32,6 +38,24 @@ console.log(`BPM: ${audio.detectBpm()}`);
|
|
|
32
38
|
console.log(`Key: ${audio.detectKey().name}`);
|
|
33
39
|
```
|
|
34
40
|
|
|
41
|
+
### Decoding files in the browser
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { init, analyze } from '@libraz/libsonare';
|
|
45
|
+
|
|
46
|
+
await init();
|
|
47
|
+
|
|
48
|
+
const arrayBuffer = await fetch('song.m4a').then((r) => r.arrayBuffer());
|
|
49
|
+
const audioCtx = new AudioContext();
|
|
50
|
+
const decoded = await audioCtx.decodeAudioData(arrayBuffer);
|
|
51
|
+
// Mono downmix for libsonare:
|
|
52
|
+
const samples = decoded.getChannelData(0);
|
|
53
|
+
const result = analyze(samples, decoded.sampleRate);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Web Audio's `decodeAudioData` handles whatever codecs the browser ships with
|
|
57
|
+
(WAV/MP3/M4A/AAC/Opus/FLAC on most modern browsers).
|
|
58
|
+
|
|
35
59
|
### Browser (CDN)
|
|
36
60
|
|
|
37
61
|
```html
|
package/README.npm.md
CHANGED
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
|
|
8
8
|
Fast, dependency-free audio analysis library for browser and Node.js via WebAssembly.
|
|
9
9
|
|
|
10
|
+
> **Audio input:** This package expects already-decoded `Float32Array` mono
|
|
11
|
+
> samples (it does not bundle a file decoder). Use the Web Audio API in the
|
|
12
|
+
> browser or `node:wasi` / a JS audio decoder in Node to obtain samples.
|
|
13
|
+
> If you need to read WAV/MP3/M4A files directly in Node, use the native
|
|
14
|
+
> N-API package [`@libraz/libsonare-native`](https://github.com/libraz/libsonare/tree/main/bindings/node) instead.
|
|
15
|
+
|
|
10
16
|
## Installation
|
|
11
17
|
|
|
12
18
|
```bash
|
|
@@ -32,6 +38,24 @@ console.log(`BPM: ${audio.detectBpm()}`);
|
|
|
32
38
|
console.log(`Key: ${audio.detectKey().name}`);
|
|
33
39
|
```
|
|
34
40
|
|
|
41
|
+
### Decoding files in the browser
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { init, analyze } from '@libraz/libsonare';
|
|
45
|
+
|
|
46
|
+
await init();
|
|
47
|
+
|
|
48
|
+
const arrayBuffer = await fetch('song.m4a').then((r) => r.arrayBuffer());
|
|
49
|
+
const audioCtx = new AudioContext();
|
|
50
|
+
const decoded = await audioCtx.decodeAudioData(arrayBuffer);
|
|
51
|
+
// Mono downmix for libsonare:
|
|
52
|
+
const samples = decoded.getChannelData(0);
|
|
53
|
+
const result = analyze(samples, decoded.sampleRate);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Web Audio's `decodeAudioData` handles whatever codecs the browser ships with
|
|
57
|
+
(WAV/MP3/M4A/AAC/Opus/FLAC on most modern browsers).
|
|
58
|
+
|
|
35
59
|
### Browser (CDN)
|
|
36
60
|
|
|
37
61
|
```html
|
package/dist/sonare.wasm
CHANGED
|
Binary file
|