@audio/decode 3.12.0 → 3.13.0
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/audio-decode.js +7 -2
- package/package.json +13 -5
- package/readme.md +49 -25
- package/test.html +3 -0
package/audio-decode.js
CHANGED
|
@@ -124,14 +124,17 @@ function fmt(name, init) {
|
|
|
124
124
|
|
|
125
125
|
// --- codecs ---
|
|
126
126
|
// dedupe (3rd arg): decoder upmixes mono sources to duplicate stereo (verified for mp3;
|
|
127
|
-
// aac/wma flagged conservatively — same lossy-wasm family). Exact containers never dedupe
|
|
127
|
+
// aac/wma flagged conservatively — same lossy-wasm family). Exact containers never dedupe;
|
|
128
|
+
// video containers that may carry AAC or MP3 (mp4/mov, mkv, avi) do.
|
|
128
129
|
|
|
129
130
|
reg('mp3', () => import('@audio/decode-mp3'), true)
|
|
130
131
|
reg('flac', () => import('@audio/decode-flac'))
|
|
131
132
|
reg('opus', () => import('@audio/decode-opus'))
|
|
132
133
|
reg('oga', () => import('@audio/decode-vorbis'))
|
|
133
134
|
|
|
134
|
-
reg('m4a', () => import('@audio/decode-
|
|
135
|
+
reg('m4a', () => import('@audio/decode-mp4'), true)
|
|
136
|
+
reg('mp4', () => import('@audio/decode-mp4'), true)
|
|
137
|
+
reg('mov', () => import('@audio/decode-mp4'), true)
|
|
135
138
|
|
|
136
139
|
reg('wav', () => import('@audio/decode-wav'))
|
|
137
140
|
reg('qoa', () => import('@audio/decode-qoa'))
|
|
@@ -140,6 +143,8 @@ reg('aac', () => import('@audio/decode-aac'), true)
|
|
|
140
143
|
reg('aiff', () => import('@audio/decode-aiff'))
|
|
141
144
|
reg('caf', () => import('@audio/decode-caf'))
|
|
142
145
|
reg('webm', () => import('@audio/decode-webm'))
|
|
146
|
+
reg('mkv', () => import('@audio/decode-webm'), true)
|
|
147
|
+
reg('avi', () => import('@audio/decode-avi'), true)
|
|
143
148
|
reg('amr', () => import('@audio/decode-amr'))
|
|
144
149
|
reg('wma', () => import('@audio/decode-wma'), true)
|
|
145
150
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audio/decode",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.13.0",
|
|
4
4
|
"description": "Decode audio data in node or browser",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -28,19 +28,21 @@
|
|
|
28
28
|
"packages/*"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@audio/decode-aac": "^1.
|
|
31
|
+
"@audio/decode-aac": "^1.5.0",
|
|
32
32
|
"@audio/decode-aiff": "^1.3.0",
|
|
33
33
|
"@audio/decode-amr": "^1.3.0",
|
|
34
|
+
"@audio/decode-avi": "^1.0.0",
|
|
34
35
|
"@audio/decode-caf": "^1.4.0",
|
|
35
36
|
"@audio/decode-flac": "^1.3.0",
|
|
36
37
|
"@audio/decode-mp3": "^1.3.0",
|
|
38
|
+
"@audio/decode-mp4": "^1.0.0",
|
|
37
39
|
"@audio/decode-opus": "^1.3.0",
|
|
38
40
|
"@audio/decode-qoa": "^1.2.0",
|
|
39
41
|
"@audio/decode-vorbis": "^1.3.0",
|
|
40
42
|
"@audio/decode-wav": "^1.5.0",
|
|
41
|
-
"@audio/decode-webm": "^1.
|
|
43
|
+
"@audio/decode-webm": "^1.5.0",
|
|
42
44
|
"@audio/decode-wma": "^1.3.0",
|
|
43
|
-
"audio-type": "^2.
|
|
45
|
+
"audio-type": "^2.5.0"
|
|
44
46
|
},
|
|
45
47
|
"devDependencies": {
|
|
46
48
|
"audio-lena": "^3.0.0",
|
|
@@ -79,7 +81,13 @@
|
|
|
79
81
|
"amr",
|
|
80
82
|
"wma",
|
|
81
83
|
"pcm",
|
|
82
|
-
"streaming"
|
|
84
|
+
"streaming",
|
|
85
|
+
"mp4",
|
|
86
|
+
"mov",
|
|
87
|
+
"mkv",
|
|
88
|
+
"avi",
|
|
89
|
+
"video",
|
|
90
|
+
"extract"
|
|
83
91
|
],
|
|
84
92
|
"author": "Dmitry Iv. <dfcreative@gmail.com>",
|
|
85
93
|
"license": "MIT",
|
package/readme.md
CHANGED
|
@@ -22,10 +22,12 @@ const { channelData, sampleRate } = await decode(anyAudioBuffer);
|
|
|
22
22
|
| FLAC | [@audio/decode-flac](./packages/decode-flac) | 135 KB | WASM |
|
|
23
23
|
| Opus | [@audio/decode-opus](./packages/decode-opus) | 166 KB | WASM |
|
|
24
24
|
| M4A / AAC / ALAC | [@audio/decode-aac](./packages/decode-aac) | 368 KB | WASM + JS |
|
|
25
|
+
| MP4 / MOV / M4V / 3GP video | [@audio/decode-mp4](./packages/decode-mp4) | 12 KB + codec | JS demux |
|
|
25
26
|
| QOA | [@audio/decode-qoa](./packages/decode-qoa) | 8 KB | JS |
|
|
26
27
|
| AIFF | [@audio/decode-aiff](./packages/decode-aiff) | 20 KB | JS |
|
|
27
28
|
| CAF | [@audio/decode-caf](./packages/decode-caf) | 9 KB | JS |
|
|
28
|
-
| WebM | [@audio/decode-webm](./packages/decode-webm) | 250 KB | WASM |
|
|
29
|
+
| WebM / MKV video | [@audio/decode-webm](./packages/decode-webm) | 250 KB | WASM |
|
|
30
|
+
| AVI video | [@audio/decode-avi](./packages/decode-avi) | 8 KB + codec | JS demux |
|
|
29
31
|
| AMR | [@audio/decode-amr](./packages/decode-amr) | 241 KB | WASM |
|
|
30
32
|
| WMA | [@audio/decode-wma](./packages/decode-wma) | 91 KB | WASM |
|
|
31
33
|
|
|
@@ -42,28 +44,6 @@ let fromFile = await decode(fileInput.files[0]) // File
|
|
|
42
44
|
let fromUrl = await decode(await fetch(url)) // Response
|
|
43
45
|
```
|
|
44
46
|
|
|
45
|
-
### Synchronous codecs
|
|
46
|
-
|
|
47
|
-
The umbrella remains async for detection, lazy imports, and `Blob`/`Response` inputs.
|
|
48
|
-
Import a codec package directly for synchronous calls.
|
|
49
|
-
|
|
50
|
-
`wav`, `qoa`, `aiff`, and `caf` are synchronous:
|
|
51
|
-
|
|
52
|
-
```js
|
|
53
|
-
import decode from '@audio/decode-wav'
|
|
54
|
-
let pcm = decode(wavBytes)
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
WASM codecs initialize asynchronously, then decode synchronously:
|
|
58
|
-
|
|
59
|
-
```js
|
|
60
|
-
import { decoder } from '@audio/decode-flac'
|
|
61
|
-
let dec = await decoder()
|
|
62
|
-
let pcm = dec.decode(bytes)
|
|
63
|
-
let tail = dec.flush()
|
|
64
|
-
dec.free()
|
|
65
|
-
```
|
|
66
|
-
|
|
67
47
|
### Chunked
|
|
68
48
|
|
|
69
49
|
```js
|
|
@@ -85,7 +65,23 @@ for await (let { channelData, sampleRate } of decode.mp3(response.body)) {
|
|
|
85
65
|
|
|
86
66
|
Works with `ReadableStream`, `fetch` body, Node stream, or any async iterable.
|
|
87
67
|
|
|
88
|
-
Formats: `mp3`, `flac`, `opus`, `oga`, `m4a`, `wav`, `qoa`, `aac`, `aiff`, `caf`, `webm`, `amr`, `wma`.
|
|
68
|
+
Formats: `mp3`, `flac`, `opus`, `oga`, `m4a`, `mp4`, `mov`, `wav`, `qoa`, `aac`, `aiff`, `caf`, `webm`, `mkv`, `avi`, `amr`, `wma`.
|
|
69
|
+
|
|
70
|
+
### Video files
|
|
71
|
+
|
|
72
|
+
Video containers decode straight to their audio track — the video stream is skipped, no ffmpeg involved:
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
let { channelData, sampleRate } = await decode(await fetch('trailer.mp4'))
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
| Container | Package | Audio codecs |
|
|
79
|
+
|---|---|---|
|
|
80
|
+
| MP4, MOV, M4V, 3GP | [@audio/decode-mp4](./packages/decode-mp4) | AAC, ALAC, MP3, FLAC, Opus, AMR, PCM, G.711 |
|
|
81
|
+
| WebM, MKV | [@audio/decode-webm](./packages/decode-webm) | Opus, Vorbis, AAC, ALAC, MP3, FLAC, PCM |
|
|
82
|
+
| AVI | [@audio/decode-avi](./packages/decode-avi) | PCM, MP3, AAC, G.711 |
|
|
83
|
+
|
|
84
|
+
AC-3, E-AC-3 and DTS tracks throw an error naming the codec.
|
|
89
85
|
|
|
90
86
|
### Browser
|
|
91
87
|
|
|
@@ -100,6 +96,32 @@ Works from a CDN without a bundler. Codecs load on demand via dynamic import, on
|
|
|
100
96
|
|
|
101
97
|
For self-hosting, use an import map to point `@audio/decode` and each needed `@audio/decode-*` package to local files. Codec-internal files load by relative path.
|
|
102
98
|
|
|
99
|
+
Each codec package's main export works in an `AudioWorklet` without `Blob`, `TextDecoder`, `Worker`, or `fetch`. Import codec packages directly because `@audio/decode` uses dynamic imports.
|
|
100
|
+
|
|
101
|
+
Initialize WASM before rendering. Decoding runs on the worklet thread and can interrupt audio output.
|
|
102
|
+
|
|
103
|
+
### Synchronous codecs
|
|
104
|
+
|
|
105
|
+
The umbrella remains async for detection, lazy imports, and `Blob`/`Response` inputs.
|
|
106
|
+
Import a codec package directly for synchronous calls.
|
|
107
|
+
|
|
108
|
+
`wav`, `qoa`, `aiff`, and `caf` are synchronous:
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
import decode from '@audio/decode-wav'
|
|
112
|
+
let pcm = decode(wavBytes)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
WASM codecs initialize asynchronously, then decode synchronously:
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
import { decoder } from '@audio/decode-flac'
|
|
119
|
+
let dec = await decoder()
|
|
120
|
+
let pcm = dec.decode(bytes)
|
|
121
|
+
let tail = dec.flush()
|
|
122
|
+
dec.free()
|
|
123
|
+
```
|
|
124
|
+
|
|
103
125
|
### Metadata
|
|
104
126
|
|
|
105
127
|
Read tags, pictures, markers and regions without decoding samples. Available for
|
|
@@ -151,6 +173,8 @@ worker.onmessage = ({ data }) => { /* { channelData, sampleRate } */ }
|
|
|
151
173
|
* [ffmpeg.wasm](https://github.com/ffmpegwasm/ffmpeg.wasm) – full encoding/decoding library.
|
|
152
174
|
-->
|
|
153
175
|
|
|
154
|
-
|
|
176
|
+
## Licensing
|
|
177
|
+
|
|
178
|
+
The umbrella and most codec packages are MIT. Three codecs use another license: <a href="./packages/decode-aac">@audio/decode-aac</a> GPL-2.0, <a href="./packages/decode-wma">@audio/decode-wma</a> GPL-2.0-or-later, and <a href="./packages/decode-amr">@audio/decode-amr</a> Apache-2.0. Install only the codecs whose licenses fit your project. The umbrella loads them on demand.
|
|
155
179
|
|
|
156
180
|
<p align="center"><a href="https://github.com/krishnized/license/">ॐ</a> · <a href="./LICENSE">MIT</a>
|
package/test.html
CHANGED
|
@@ -32,6 +32,9 @@
|
|
|
32
32
|
"@audio/decode-aiff": "./packages/decode-aiff/decode-aiff.js",
|
|
33
33
|
"@audio/decode-caf": "./packages/decode-caf/decode-caf.js",
|
|
34
34
|
"@audio/decode-webm": "./packages/decode-webm/decode-webm.js",
|
|
35
|
+
"@audio/decode-mp4": "./packages/decode-mp4/decode-mp4.js",
|
|
36
|
+
"@audio/decode-avi": "./packages/decode-avi/decode-avi.js",
|
|
37
|
+
"@audio/decode-opus/core": "./packages/decode-opus/core.js",
|
|
35
38
|
"@audio/decode-amr": "./packages/decode-amr/decode-amr.js",
|
|
36
39
|
"@audio/decode-wma": "./packages/decode-wma/decode-wma.js"
|
|
37
40
|
}
|