@audio/decode 3.12.0 → 3.14.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 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-aac'), true)
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,10 @@ 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)
148
+ reg('ac3', () => import('@audio/decode-ac3'))
149
+ reg('dts', () => import('@audio/decode-dts'))
143
150
  reg('amr', () => import('@audio/decode-amr'))
144
151
  reg('wma', () => import('@audio/decode-wma'), true)
145
152
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@audio/decode",
3
- "version": "3.12.0",
3
+ "version": "3.14.0",
4
4
  "description": "Decode audio data in node or browser",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -28,19 +28,23 @@
28
28
  "packages/*"
29
29
  ],
30
30
  "dependencies": {
31
- "@audio/decode-aac": "^1.4.0",
31
+ "@audio/decode-aac": "^1.5.0",
32
+ "@audio/decode-ac3": "^1.0.0",
32
33
  "@audio/decode-aiff": "^1.3.0",
33
34
  "@audio/decode-amr": "^1.3.0",
35
+ "@audio/decode-avi": "^1.1.0",
34
36
  "@audio/decode-caf": "^1.4.0",
37
+ "@audio/decode-dts": "^1.0.0",
35
38
  "@audio/decode-flac": "^1.3.0",
36
39
  "@audio/decode-mp3": "^1.3.0",
40
+ "@audio/decode-mp4": "^1.1.0",
37
41
  "@audio/decode-opus": "^1.3.0",
38
42
  "@audio/decode-qoa": "^1.2.0",
39
43
  "@audio/decode-vorbis": "^1.3.0",
40
44
  "@audio/decode-wav": "^1.5.0",
41
- "@audio/decode-webm": "^1.4.0",
45
+ "@audio/decode-webm": "^1.6.0",
42
46
  "@audio/decode-wma": "^1.3.0",
43
- "audio-type": "^2.4.0"
47
+ "audio-type": "^2.6.0"
44
48
  },
45
49
  "devDependencies": {
46
50
  "audio-lena": "^3.0.0",
@@ -79,7 +83,15 @@
79
83
  "amr",
80
84
  "wma",
81
85
  "pcm",
82
- "streaming"
86
+ "streaming",
87
+ "mp4",
88
+ "mov",
89
+ "mkv",
90
+ "avi",
91
+ "video",
92
+ "extract",
93
+ "ac3",
94
+ "dts"
83
95
  ],
84
96
  "author": "Dmitry Iv. <dfcreative@gmail.com>",
85
97
  "license": "MIT",
package/readme.md CHANGED
@@ -22,10 +22,14 @@ 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 |
31
+ | AC-3 | [@audio/decode-ac3](./packages/decode-ac3) | 43 KB | WASM |
32
+ | DTS | [@audio/decode-dts](./packages/decode-dts) | 200 KB | WASM |
29
33
  | AMR | [@audio/decode-amr](./packages/decode-amr) | 241 KB | WASM |
30
34
  | WMA | [@audio/decode-wma](./packages/decode-wma) | 91 KB | WASM |
31
35
 
@@ -42,28 +46,6 @@ let fromFile = await decode(fileInput.files[0]) // File
42
46
  let fromUrl = await decode(await fetch(url)) // Response
43
47
  ```
44
48
 
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
49
  ### Chunked
68
50
 
69
51
  ```js
@@ -85,7 +67,23 @@ for await (let { channelData, sampleRate } of decode.mp3(response.body)) {
85
67
 
86
68
  Works with `ReadableStream`, `fetch` body, Node stream, or any async iterable.
87
69
 
88
- Formats: `mp3`, `flac`, `opus`, `oga`, `m4a`, `wav`, `qoa`, `aac`, `aiff`, `caf`, `webm`, `amr`, `wma`.
70
+ Formats: `mp3`, `flac`, `opus`, `oga`, `m4a`, `mp4`, `mov`, `wav`, `qoa`, `aac`, `aiff`, `caf`, `webm`, `mkv`, `avi`, `ac3`, `dts`, `amr`, `wma`.
71
+
72
+ ### Video files
73
+
74
+ Video containers decode straight to their audio track — the video stream is skipped, no ffmpeg involved:
75
+
76
+ ```js
77
+ let { channelData, sampleRate } = await decode(await fetch('trailer.mp4'))
78
+ ```
79
+
80
+ | Container | Package | Audio codecs |
81
+ |---|---|---|
82
+ | MP4, MOV, M4V, 3GP | [@audio/decode-mp4](./packages/decode-mp4) | AAC, ALAC, MP3, FLAC, Opus, AC-3, DTS, AMR, PCM, G.711 |
83
+ | WebM, MKV | [@audio/decode-webm](./packages/decode-webm) | Opus, Vorbis, AAC, ALAC, MP3, FLAC, AC-3, DTS, PCM |
84
+ | AVI | [@audio/decode-avi](./packages/decode-avi) | PCM, MP3, AAC, AC-3, DTS, G.711 |
85
+
86
+ Surround tracks keep their layout (up to 5.1, WAV channel order). E-AC-3 and TrueHD tracks throw an error naming the codec.
89
87
 
90
88
  ### Browser
91
89
 
@@ -100,6 +98,32 @@ Works from a CDN without a bundler. Codecs load on demand via dynamic import, on
100
98
 
101
99
  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
100
 
101
+ 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.
102
+
103
+ Initialize WASM before rendering. Decoding runs on the worklet thread and can interrupt audio output.
104
+
105
+ ### Synchronous codecs
106
+
107
+ The umbrella remains async for detection, lazy imports, and `Blob`/`Response` inputs.
108
+ Import a codec package directly for synchronous calls.
109
+
110
+ `wav`, `qoa`, `aiff`, and `caf` are synchronous:
111
+
112
+ ```js
113
+ import decode from '@audio/decode-wav'
114
+ let pcm = decode(wavBytes)
115
+ ```
116
+
117
+ WASM codecs initialize asynchronously, then decode synchronously:
118
+
119
+ ```js
120
+ import { decoder } from '@audio/decode-flac'
121
+ let dec = await decoder()
122
+ let pcm = dec.decode(bytes)
123
+ let tail = dec.flush()
124
+ dec.free()
125
+ ```
126
+
103
127
  ### Metadata
104
128
 
105
129
  Read tags, pictures, markers and regions without decoding samples. Available for
@@ -151,6 +175,8 @@ worker.onmessage = ({ data }) => { /* { channelData, sampleRate } */ }
151
175
  * [ffmpeg.wasm](https://github.com/ffmpegwasm/ffmpeg.wasm) – full encoding/decoding library.
152
176
  -->
153
177
 
154
- <p align="center">Licensing: 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.</p>
178
+ ## Licensing
179
+
180
+ The umbrella and most codec packages are MIT. Five 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>, <a href="./packages/decode-ac3">@audio/decode-ac3</a> and <a href="./packages/decode-dts">@audio/decode-dts</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
181
 
156
182
  <p align="center"><a href="https://github.com/krishnized/license/">ॐ</a> · <a href="./LICENSE">MIT</a>
package/test.html CHANGED
@@ -32,6 +32,11 @@
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",
38
+ "@audio/decode-ac3": "./packages/decode-ac3/decode-ac3.js",
39
+ "@audio/decode-dts": "./packages/decode-dts/decode-dts.js",
35
40
  "@audio/decode-amr": "./packages/decode-amr/decode-amr.js",
36
41
  "@audio/decode-wma": "./packages/decode-wma/decode-wma.js"
37
42
  }