@openclaw/whatsapp 2026.5.31-beta.2 → 2026.5.31-beta.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.
Files changed (112) hide show
  1. package/dist/api.js +8 -8
  2. package/dist/{channel-DA2BAIo5.js → channel-BbtRTgNk.js} +1 -1
  3. package/dist/channel-plugin-api.js +1 -1
  4. package/dist/{channel.runtime-Q1LZDB5s.js → channel.runtime-Cf2UgrhZ.js} +3 -3
  5. package/dist/{channel.setup-DHXOo4h5.js → channel.setup-DaIyWos-.js} +1 -1
  6. package/dist/{connection-controller-Bnm4INld.js → connection-controller-B07CNCkw.js} +1 -1
  7. package/dist/{login-2fuBM7Je.js → login-CRtqboZq.js} +2 -2
  8. package/dist/{login-qr-B1o7GFy8.js → login-qr-B27eAPhh.js} +8 -4
  9. package/dist/login-qr-runtime.js +5 -5
  10. package/dist/{monitor-BVRq04Dt.js → monitor-CnioHf5V.js} +34 -28
  11. package/dist/runtime-api.js +3 -3
  12. package/dist/{session-DyGWNClj.js → session-mBuvPUCy.js} +27 -18
  13. package/dist/{setup-core-OvPMaAsx.js → setup-core-C3XZ2KBH.js} +5 -5
  14. package/dist/{setup-finalize-Dk23pfKc.js → setup-finalize-B7FVDzwJ.js} +2 -2
  15. package/dist/setup-plugin-api.js +1 -1
  16. package/dist/{setup-surface-F-jVrH8u.js → setup-surface-CGTWO_-E.js} +1 -1
  17. package/node_modules/audio-buffer/.eslintrc.json +44 -0
  18. package/node_modules/audio-buffer/.github/workflows/node.js.yml +31 -0
  19. package/node_modules/audio-buffer/.travis.yml +7 -0
  20. package/node_modules/{@audio/decode-opus → audio-buffer}/LICENSE +2 -5
  21. package/node_modules/audio-buffer/index.js +76 -0
  22. package/node_modules/audio-buffer/package.json +37 -0
  23. package/node_modules/audio-buffer/readme.md +56 -0
  24. package/node_modules/audio-decode/.eslintrc.json +43 -0
  25. package/node_modules/audio-decode/.github/workflows/test.js.yml +20 -11
  26. package/node_modules/audio-decode/.travis.yml +13 -0
  27. package/node_modules/audio-decode/audio-decode.d.ts +10 -48
  28. package/node_modules/audio-decode/audio-decode.js +77 -193
  29. package/node_modules/audio-decode/package.json +21 -49
  30. package/node_modules/audio-decode/readme.md +29 -129
  31. package/node_modules/audio-decode/tea.yaml +6 -0
  32. package/node_modules/audio-decode/test-case.js +11 -0
  33. package/node_modules/audio-decode/test.html +10 -29
  34. package/node_modules/audio-decode/test.js +107 -0
  35. package/node_modules/node-wav/README.md +35 -0
  36. package/node_modules/node-wav/file.wav +0 -0
  37. package/node_modules/node-wav/index.js +291 -0
  38. package/node_modules/node-wav/package.json +29 -0
  39. package/node_modules/node-wav/tests/file1.wav +0 -0
  40. package/node_modules/node-wav/tests/test.js +66 -0
  41. package/node_modules/node-wav/x.js +12 -0
  42. package/node_modules/node-wav/x.json +86702 -0
  43. package/node_modules/node-wav/x.js~ +13 -0
  44. package/npm-shrinkwrap.json +32 -149
  45. package/package.json +5 -5
  46. package/node_modules/@audio/decode-aac/LICENSE +0 -9
  47. package/node_modules/@audio/decode-aac/README.md +0 -60
  48. package/node_modules/@audio/decode-aac/decode-aac.d.ts +0 -16
  49. package/node_modules/@audio/decode-aac/decode-aac.js +0 -391
  50. package/node_modules/@audio/decode-aac/package.json +0 -47
  51. package/node_modules/@audio/decode-aac/src/aac.wasm.cjs +0 -0
  52. package/node_modules/@audio/decode-aiff/LICENSE +0 -21
  53. package/node_modules/@audio/decode-aiff/README.md +0 -53
  54. package/node_modules/@audio/decode-aiff/decode-aiff.d.ts +0 -16
  55. package/node_modules/@audio/decode-aiff/decode-aiff.js +0 -583
  56. package/node_modules/@audio/decode-aiff/package.json +0 -42
  57. package/node_modules/@audio/decode-amr/LICENSE +0 -191
  58. package/node_modules/@audio/decode-amr/README.md +0 -65
  59. package/node_modules/@audio/decode-amr/decode-amr.d.ts +0 -16
  60. package/node_modules/@audio/decode-amr/decode-amr.js +0 -159
  61. package/node_modules/@audio/decode-amr/package.json +0 -48
  62. package/node_modules/@audio/decode-amr/src/amr.wasm.cjs +0 -0
  63. package/node_modules/@audio/decode-caf/LICENSE +0 -21
  64. package/node_modules/@audio/decode-caf/README.md +0 -55
  65. package/node_modules/@audio/decode-caf/decode-caf.d.ts +0 -16
  66. package/node_modules/@audio/decode-caf/decode-caf.js +0 -190
  67. package/node_modules/@audio/decode-caf/package.json +0 -43
  68. package/node_modules/@audio/decode-flac/LICENSE +0 -25
  69. package/node_modules/@audio/decode-flac/README.md +0 -23
  70. package/node_modules/@audio/decode-flac/decode-flac.d.ts +0 -16
  71. package/node_modules/@audio/decode-flac/decode-flac.js +0 -2994
  72. package/node_modules/@audio/decode-flac/meta.js +0 -115
  73. package/node_modules/@audio/decode-flac/package.json +0 -49
  74. package/node_modules/@audio/decode-mp3/LICENSE +0 -25
  75. package/node_modules/@audio/decode-mp3/README.md +0 -23
  76. package/node_modules/@audio/decode-mp3/decode-mp3.d.ts +0 -16
  77. package/node_modules/@audio/decode-mp3/decode-mp3.js +0 -868
  78. package/node_modules/@audio/decode-mp3/meta.js +0 -143
  79. package/node_modules/@audio/decode-mp3/package.json +0 -50
  80. package/node_modules/@audio/decode-opus/README.md +0 -23
  81. package/node_modules/@audio/decode-opus/decode-opus.d.ts +0 -16
  82. package/node_modules/@audio/decode-opus/decode-opus.js +0 -3179
  83. package/node_modules/@audio/decode-opus/package.json +0 -47
  84. package/node_modules/@audio/decode-qoa/LICENSE +0 -25
  85. package/node_modules/@audio/decode-qoa/README.md +0 -21
  86. package/node_modules/@audio/decode-qoa/decode-qoa.d.ts +0 -16
  87. package/node_modules/@audio/decode-qoa/decode-qoa.js +0 -278
  88. package/node_modules/@audio/decode-qoa/package.json +0 -46
  89. package/node_modules/@audio/decode-vorbis/LICENSE +0 -25
  90. package/node_modules/@audio/decode-vorbis/README.md +0 -23
  91. package/node_modules/@audio/decode-vorbis/decode-vorbis.d.ts +0 -16
  92. package/node_modules/@audio/decode-vorbis/decode-vorbis.js +0 -2984
  93. package/node_modules/@audio/decode-vorbis/package.json +0 -47
  94. package/node_modules/@audio/decode-wav/decode-wav.js +0 -104
  95. package/node_modules/@audio/decode-wav/meta.js +0 -114
  96. package/node_modules/@audio/decode-wav/package.json +0 -27
  97. package/node_modules/@audio/decode-webm/LICENSE +0 -21
  98. package/node_modules/@audio/decode-webm/README.md +0 -57
  99. package/node_modules/@audio/decode-webm/decode-webm.d.ts +0 -16
  100. package/node_modules/@audio/decode-webm/decode-webm.js +0 -3964
  101. package/node_modules/@audio/decode-webm/package.json +0 -51
  102. package/node_modules/@audio/decode-wma/LICENSE +0 -12
  103. package/node_modules/@audio/decode-wma/README.md +0 -76
  104. package/node_modules/@audio/decode-wma/decode-wma.d.ts +0 -33
  105. package/node_modules/@audio/decode-wma/decode-wma.js +0 -525
  106. package/node_modules/@audio/decode-wma/package.json +0 -47
  107. package/node_modules/@audio/decode-wma/src/wma.wasm.cjs +0 -0
  108. package/node_modules/audio-decode/.claude/settings.json +0 -204
  109. package/node_modules/audio-decode/.gitmodules +0 -9
  110. package/node_modules/audio-decode/meta.js +0 -11
  111. package/node_modules/audio-decode/stream.d.ts +0 -15
  112. package/node_modules/audio-decode/stream.js +0 -1
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "audio-buffer",
3
+ "version": "5.0.0",
4
+ "description": "AudioBuffer class for node/browser",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/audiojs/audio-buffer"
10
+ },
11
+ "scripts": {
12
+ "test": "node test"
13
+ },
14
+ "keywords": [
15
+ "audio",
16
+ "audiojs",
17
+ "pcm",
18
+ "dsp",
19
+ "sound",
20
+ "processing",
21
+ "ndsamples",
22
+ "ponyfill",
23
+ "audio-buffer",
24
+ "web-audio",
25
+ "waa",
26
+ "audiodata"
27
+ ],
28
+ "author": "Dmitry Iv <df.creative@gmail.com>",
29
+ "license": "MIT",
30
+ "bugs": {
31
+ "url": "https://github.com/audiojs/audio-buffer/issues"
32
+ },
33
+ "homepage": "https://github.com/audiojs/audio-buffer",
34
+ "devDependencies": {
35
+ "tape": "^5.6.3"
36
+ }
37
+ }
@@ -0,0 +1,56 @@
1
+ # audio-buffer [![test](https://github.com/audiojs/audio-buffer/actions/workflows/node.js.yml/badge.svg)](https://github.com/audiojs/audio-buffer/actions/workflows/node.js.yml) [![stable](https://img.shields.io/badge/stability-stable-brightgreen.svg)](http://github.com/badges/stability-badges)
2
+
3
+ _AudioBuffer_ - basic audio data container class.
4
+ Useful instead of _Buffer_ in audio streams, [**@audiojs**](https://github.com/audiojs) components, in webworkers, nodejs, other environments without audio context.
5
+
6
+ Implementation is compatible with [Web Audio API AudioBuffer](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer), can be used as ponyfill.
7
+
8
+ ## Usage
9
+
10
+ [![npm install audio-buffer](https://nodei.co/npm/audio-buffer.png?mini=true)](https://npmjs.org/package/audio-buffer/)
11
+
12
+ ### new AudioBuffer(options)
13
+
14
+ Create audio buffer from `options`.
15
+
16
+ * `options.length` — number of samples, minimum is 1.
17
+ * `options.sampleRate` — default sample rate is 44100.
18
+ * `options.numberOfChannels` — default number of channels is 1.
19
+
20
+ ### buffer.duration
21
+
22
+ Duration of the underlying audio data, in seconds.
23
+
24
+ ### buffer.length
25
+
26
+ Number of samples per channel.
27
+
28
+ ### buffer.sampleRate
29
+
30
+ Default sample rate is 44100.
31
+
32
+ ### buffer.numberOfChannels
33
+
34
+ Default number of channels is 1.
35
+
36
+ ### buffer.getChannelData(channel)
37
+
38
+ Get array containing the data for the channel (not copied).
39
+
40
+ ### buffer.copyFromChannel(destination, channelNumber, startInChannel=0)
41
+
42
+ Place data from channel to destination Float32Array.
43
+
44
+ ### buffer.copyToChannel(source, channelNumber, startInChannel=0)
45
+
46
+ Place data from source Float32Array to the channel.
47
+
48
+
49
+ ## Similar
50
+
51
+ * [ndsamples](https://github.com/livejs/ndsamples) — audio-wrapper for ndarrays. A somewhat alternative approach to wrap audio data, based on ndarrays, used by some modules in [livejs](https://github.com/livejs).
52
+ * [1](https://www.npmjs.com/package/audiobuffer), [2](https://www.npmjs.com/package/audio-buffer), [3](https://github.com/sebpiq/node-web-audio-api/blob/master/lib/AudioBuffer.js), [4](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer) — other AudioBuffer implementations.
53
+ * [audiodata](https://www.npmjs.com/package/audiodata) alternative data holder from @mohayonao.
54
+
55
+
56
+ <p align=center><a href="https://github.com/krishnized/license/">🕉</a></p>
@@ -0,0 +1,43 @@
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "node": true,
5
+ "commonjs": true,
6
+ "es6": true
7
+ },
8
+ "extends": "eslint:recommended",
9
+ "rules": {
10
+ "strict": 2,
11
+ "indent": 0,
12
+ "linebreak-style": 0,
13
+ "quotes": 0,
14
+ "semi": 0,
15
+ "no-cond-assign": 1,
16
+ "no-constant-condition": 1,
17
+ "no-duplicate-case": 1,
18
+ "no-empty": 1,
19
+ "no-ex-assign": 1,
20
+ "no-extra-boolean-cast": 1,
21
+ "no-extra-semi": 1,
22
+ "no-fallthrough": 1,
23
+ "no-func-assign": 1,
24
+ "no-global-assign": 1,
25
+ "no-implicit-globals": 2,
26
+ "no-inner-declarations": ["error", "functions"],
27
+ "no-irregular-whitespace": 2,
28
+ "no-loop-func": 1,
29
+ "no-multi-str": 1,
30
+ "no-mixed-spaces-and-tabs": 1,
31
+ "no-proto": 1,
32
+ "no-sequences": 1,
33
+ "no-throw-literal": 1,
34
+ "no-unmodified-loop-condition": 1,
35
+ "no-useless-call": 1,
36
+ "no-void": 1,
37
+ "no-with": 2,
38
+ "wrap-iife": 1,
39
+ "no-redeclare": 1,
40
+ "no-unused-vars": ["error", { "vars": "all", "args": "none" }],
41
+ "no-sparse-arrays": 1
42
+ }
43
+ }
@@ -1,22 +1,31 @@
1
+ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
+
1
4
  name: test
2
5
 
3
6
  on:
4
7
  push:
5
- branches: [master]
8
+ branches: [ "master" ]
6
9
  pull_request:
7
- branches: [master]
10
+ branches: [ "master" ]
8
11
 
9
12
  jobs:
10
- test:
13
+ build:
14
+
11
15
  runs-on: ubuntu-latest
16
+
12
17
  strategy:
13
18
  matrix:
14
- node-version: [20.x, 22.x]
19
+ node-version: [14.x, 16.x, 18.x]
20
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21
+
15
22
  steps:
16
- - uses: actions/checkout@v4
17
- - uses: actions/setup-node@v4
18
- with:
19
- node-version: ${{ matrix.node-version }}
20
- cache: npm
21
- - run: npm ci
22
- - run: npm test
23
+ - uses: actions/checkout@v3
24
+ - name: Use Node.js ${{ matrix.node-version }}
25
+ uses: actions/setup-node@v3
26
+ with:
27
+ node-version: ${{ matrix.node-version }}
28
+ cache: 'npm'
29
+ - run: npm ci
30
+ - run: npm run build --if-present
31
+ - run: npm test
@@ -0,0 +1,13 @@
1
+ sudo: false
2
+ language: node_js
3
+ node_js:
4
+ - 'node'
5
+ - '6'
6
+ - '5'
7
+ - '4'
8
+ matrix:
9
+ fast_finish: true
10
+ allow_failures:
11
+ - node_js: "4"
12
+ - node_js: "5"
13
+
@@ -1,52 +1,14 @@
1
- export interface AudioData {
2
- channelData: Float32Array[];
3
- sampleRate: number;
4
- }
5
-
6
- export interface StreamDecoder {
7
- /** Feed a chunk of encoded audio data, or call empty to flush + free. */
8
- (chunk?: Uint8Array): Promise<AudioData>;
9
- /** Flush without freeing. */
10
- flush(): Promise<AudioData>;
11
- /** Free resources without flushing. */
12
- free(): void;
13
- }
1
+ // audio-decode.d.ts
14
2
 
15
- type Format = 'mp3' | 'flac' | 'opus' | 'oga' | 'm4a' | 'wav' | 'qoa' | 'aac' | 'aiff' | 'caf' | 'webm' | 'amr' | 'wma';
3
+ export default function audioDecode(buf: ArrayBuffer | Uint8Array): Promise<AudioBuffer>;
16
4
 
17
- interface FormatDecoder {
18
- /** Create a decoder instance. */
19
- (): Promise<StreamDecoder>;
5
+ export interface Decoders {
6
+ oga: (buf: Uint8Array) => Promise<AudioBuffer>;
7
+ mp3: (buf: Uint8Array) => Promise<AudioBuffer>;
8
+ flac: (buf: Uint8Array) => Promise<AudioBuffer>;
9
+ opus: (buf: Uint8Array) => Promise<AudioBuffer>;
10
+ wav: (buf: Uint8Array) => Promise<AudioBuffer>;
11
+ qoa: (buf: Uint8Array) => Promise<AudioBuffer>;
20
12
  }
21
13
 
22
- /** Whole-file decode: auto-detects format. */
23
- declare function decode(buf: ArrayBuffer | Uint8Array): Promise<AudioData>;
24
- /** Chunked decode from stream or async iterable. */
25
- declare function decode(
26
- source: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>,
27
- format: Format
28
- ): AsyncGenerator<AudioData>;
29
-
30
- declare namespace decode {
31
- export const mp3: FormatDecoder;
32
- export const flac: FormatDecoder;
33
- export const opus: FormatDecoder;
34
- export const oga: FormatDecoder;
35
- export const m4a: FormatDecoder;
36
- export const wav: FormatDecoder;
37
- export const qoa: FormatDecoder;
38
- export const aac: FormatDecoder;
39
- export const aiff: FormatDecoder;
40
- export const caf: FormatDecoder;
41
- export const webm: FormatDecoder;
42
- export const amr: FormatDecoder;
43
- export const wma: FormatDecoder;
44
- }
45
-
46
- export default decode;
47
-
48
- /** Chunked decode from stream or async iterable. */
49
- export function decodeChunked(
50
- source: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>,
51
- format: Format
52
- ): AsyncGenerator<AudioData>;
14
+ export const decoders: Decoders;
@@ -1,208 +1,92 @@
1
1
  /**
2
- * Audio decoder: whole-file, streaming, chunked
3
- * @module audio-decode
4
- *
5
- * let { channelData, sampleRate } = await decode(buf)
6
- *
7
- * for await (let pcm of decode.mp3(source)) { ... }
8
- *
9
- * let dec = await decode.mp3()
10
- * let { channelData, sampleRate } = await dec(chunk)
11
- * await dec() // close
2
+ * Web-Audio-API decoder
3
+ * @module audio-decode
12
4
  */
13
5
 
14
6
  import getType from 'audio-type';
7
+ import AudioBufferShim from 'audio-buffer';
15
8
 
16
- const EMPTY = Object.freeze({ channelData: Object.freeze([]), sampleRate: 0 })
9
+ const AudioBuffer = globalThis.AudioBuffer || AudioBufferShim;
17
10
 
18
11
  /**
19
- * Decode audio.
20
- * 1 arg: whole-file — auto-detects format, returns Promise<AudioData>
21
- * 2 args: chunked streams from ReadableStream/AsyncIterable, returns AsyncGenerator<AudioData>
22
- */
23
- export default function decode(src, format) {
24
- if (format) return decodeChunked(src, format)
25
- return decodeWhole(src)
26
- }
27
-
28
- async function decodeWhole(src) {
29
- if (!src || typeof src === 'string' || !(src.buffer || src.byteLength || src.length))
30
- throw TypeError('Expected ArrayBuffer or Uint8Array')
31
- let buf = new Uint8Array(src)
32
-
33
- let type = getType(buf)
34
- if (!type) throw Error('Unknown audio format')
35
- if (!decode[type]) throw Error('No decoder for ' + type)
36
-
37
- let dec = await decode[type]()
38
- try {
39
- let result = await dec(buf)
40
- let flushed = await dec()
41
- return merge(result, flushed)
42
- } catch (e) { dec.free(); throw e }
43
- }
44
-
45
- /**
46
- * Decode a ReadableStream or async iterable of encoded audio chunks.
47
- * @param {ReadableStream|AsyncIterable} source
48
- * @param {string} format - codec name
49
- * @returns {AsyncGenerator<{channelData: Float32Array[], sampleRate: number}>}
12
+ * Decode an audio buffer.
13
+ *
14
+ * @param {ArrayBuffer | Uint8Array} buf - The audio data to decode.
15
+ * @returns {Promise<AudioBuffer>} A promise that resolves to the decoded audio buffer.
16
+ * @throws {Error} Throws an error if the decode target is invalid or if the audio format is not supported.
50
17
  */
51
- export async function* decodeChunked(source, format) {
52
- if (!decode[format]) throw Error('No decoder for ' + format)
53
- let dec = await decode[format]()
54
- try {
55
- if (source.getReader) {
56
- let reader = source.getReader()
57
- while (true) {
58
- let { done, value } = await reader.read()
59
- if (done) break
60
- let result = await dec(value instanceof Uint8Array ? value : new Uint8Array(value))
61
- if (result.channelData.length) yield result
62
- }
63
- } else {
64
- for await (let chunk of source) {
65
- let result = await dec(chunk instanceof Uint8Array ? chunk : new Uint8Array(chunk))
66
- if (result.channelData.length) yield result
67
- }
18
+ export default async function audioDecode(buf) {
19
+ if (!buf && !(buf.length || buf.buffer)) throw Error('Bad decode target')
20
+ buf = new Uint8Array(buf.buffer || buf)
21
+
22
+ let type = getType(buf);
23
+
24
+ if (!type) throw Error('Cannot detect audio format');
25
+
26
+ if (!decoders[type]) throw Error('Missing decoder for ' + type + ' format')
27
+
28
+ return decoders[type](buf)
29
+ };
30
+
31
+ export const decoders = {
32
+ async oga(buf) {
33
+ let { decoder } = decoders.oga
34
+ if (!decoder) {
35
+ let { OggVorbisDecoder } = await import('@wasm-audio-decoders/ogg-vorbis')
36
+ await (decoders.oga.decoder = decoder = new OggVorbisDecoder()).ready;
37
+ } else await decoder.reset()
38
+ return buf && createBuffer(await decoder.decodeFile(buf))
39
+ },
40
+ async mp3(buf) {
41
+ let { decoder } = decoders.mp3
42
+ if (!decoder) {
43
+ const { MPEGDecoder } = await import('mpg123-decoder')
44
+ await (decoders.mp3.decoder = decoder = new MPEGDecoder()).ready;
68
45
  }
69
- let flushed = await dec()
70
- if (flushed.channelData.length) yield flushed
71
- } finally {
72
- dec.free()
73
- }
74
- }
75
-
76
- // --- format registration ---
77
-
78
- function reg(name, load) {
79
- decode[name] = fmt(name, async () => {
80
- let mod = await load()
81
- // @audio/* packages export { decoder, default }
82
- if (mod.decoder) {
83
- let codec = await mod.decoder()
84
- return streamDecoder(
85
- chunk => codec.decode(chunk),
86
- codec.flush ? () => codec.flush() : null,
87
- codec.free ? () => codec.free() : null
88
- )
46
+ else await decoder.reset()
47
+ return buf && createBuffer(await decoder.decode(buf))
48
+ },
49
+ async flac(buf) {
50
+ let { decoder } = decoders.flac
51
+ if (!decoder) {
52
+ const { FLACDecoder } = await import('@wasm-audio-decoders/flac')
53
+ await (decoders.flac.decoder = decoder = new FLACDecoder()).ready
89
54
  }
90
- // wasm-audio-decoders export class with .ready
91
- let init = mod.default || mod
92
- let codec = typeof init === 'function' ? await init() : init
93
- if (codec.ready) await codec.ready
94
- return streamDecoder(
95
- chunk => codec.decode(chunk),
96
- codec.flush ? () => codec.flush() : null,
97
- codec.free ? () => codec.free() : null
98
- )
99
- })
100
- }
101
-
102
- function fmt(name, init) {
103
- let fn = (src) => {
104
- if (!src) return init()
105
- // async iterable / ReadableStream → streaming decode
106
- if (src[Symbol.asyncIterator] || src.getReader) return decodeChunked(src, name)
107
- // buffer → whole-file decode
108
- console.warn('decode.' + name + '(data) is deprecated, use decode(data)')
109
- return (async () => {
110
- let dec = await init()
111
- try {
112
- let result = await dec(src instanceof Uint8Array ? src : new Uint8Array(src.buffer || src))
113
- let flushed = await dec()
114
- return merge(result, flushed)
115
- } catch (e) { dec.free(); throw e }
116
- })()
117
- }
118
- return fn
119
- }
120
-
121
- // --- codecs ---
122
-
123
- reg('mp3', () => import('@audio/decode-mp3'))
124
- reg('flac', () => import('@audio/decode-flac'))
125
- reg('opus', () => import('@audio/decode-opus'))
126
- reg('oga', () => import('@audio/decode-vorbis'))
127
-
128
- reg('m4a', () => import('@audio/decode-aac'))
129
-
130
- reg('wav', () => import('@audio/decode-wav'))
131
- reg('qoa', () => import('@audio/decode-qoa'))
132
-
133
- reg('aac', () => import('@audio/decode-aac'))
134
- reg('aiff', () => import('@audio/decode-aiff'))
135
- reg('caf', () => import('@audio/decode-caf'))
136
- reg('webm', () => import('@audio/decode-webm'))
137
- reg('amr', () => import('@audio/decode-amr'))
138
- reg('wma', () => import('@audio/decode-wma'))
139
-
140
- /**
141
- * StreamDecoder — a callable function:
142
- * dec(chunk) — decode data, returns { channelData, sampleRate }
143
- * dec() — end of stream: flush remaining samples + free resources
144
- * dec.flush() — flush without freeing
145
- * dec.free() — release resources without flushing
146
- */
147
- function streamDecoder(onDecode, onFlush, onFree) {
148
- let done = false
149
- let fn = async (chunk) => {
150
- if (chunk) {
151
- if (done) throw Error('Decoder already freed')
152
- try { return norm(await onDecode(chunk instanceof Uint8Array ? chunk : new Uint8Array(chunk))) }
153
- catch (e) { done = true; onFree?.(); throw e }
55
+ else await decoder.reset()
56
+ return buf && createBuffer(await decoder.decode(buf))
57
+ },
58
+ async opus(buf) {
59
+ let { decoder } = decoders.opus
60
+ if (!decoder) {
61
+ const { OggOpusDecoder } = await import('ogg-opus-decoder')
62
+ await (decoders.opus.decoder = decoder = new OggOpusDecoder()).ready
154
63
  }
155
- // null/undefined = end of stream
156
- if (done) return EMPTY
157
- done = true
158
- try {
159
- let result = onFlush ? norm(await onFlush()) : EMPTY
160
- onFree?.()
161
- return result
162
- } catch (e) { onFree?.(); throw e }
163
- }
164
- fn.flush = async () => {
165
- if (done) return EMPTY
166
- return onFlush ? norm(await onFlush()) : EMPTY
167
- }
168
- fn.free = () => {
169
- if (done) return
170
- done = true
171
- onFree?.()
172
- }
173
- return fn
174
- }
175
-
176
- // extract { channelData, sampleRate } from codec result
177
- function norm(r) {
178
- if (!r?.channelData?.length) return EMPTY
179
- let { channelData, sampleRate, samplesDecoded } = r
180
- if (samplesDecoded != null && samplesDecoded < channelData[0].length)
181
- channelData = channelData.map(ch => ch.subarray(0, samplesDecoded))
182
- if (!channelData[0]?.length) return EMPTY
183
- // collapse duplicate stereo to mono (some decoders always output 2ch for mono sources)
184
- if (channelData.length === 2) {
185
- let a = channelData[0], b = channelData[1], same = true
186
- for (let i = 0; i < a.length; i += 37) { if (a[i] !== b[i]) { same = false; break } }
187
- if (same) channelData = [a]
64
+ else await decoder.reset()
65
+ return buf && createBuffer(await decoder.decodeFile(buf))
66
+ },
67
+ async wav(buf) {
68
+ let { decode } = decoders.wav
69
+ if (!decode) {
70
+ let module = await import('node-wav')
71
+ decode = decoders.wav.decode = module.default.decode
72
+ }
73
+ return buf && createBuffer(await decode(buf))
74
+ },
75
+ async qoa(buf) {
76
+ let { decode } = decoders.qoa
77
+ if (!decode) {
78
+ decoders.qoa.decode = decode = (await import('qoa-format')).decode
79
+ }
80
+ return buf && createBuffer(await decode(buf))
188
81
  }
189
- return { channelData, sampleRate }
190
82
  }
191
83
 
192
- // merge two decode results
193
- function merge(a, b) {
194
- if (!b?.channelData?.length) return a
195
- if (!a?.channelData?.length) return b
196
- let ach = a.channelData.length, bch = b.channelData.length
197
- let ch = Math.max(ach, bch)
198
- return {
199
- channelData: Array.from({ length: ch }, (_, i) => {
200
- let ac = a.channelData[i % ach], bc = b.channelData[i % bch]
201
- let merged = new Float32Array(ac.length + bc.length)
202
- merged.set(ac)
203
- merged.set(bc, ac.length)
204
- return merged
205
- }),
206
- sampleRate: a.sampleRate
207
- }
84
+ function createBuffer({ channelData, sampleRate }) {
85
+ let audioBuffer = new AudioBuffer({
86
+ sampleRate,
87
+ length: channelData[0].length,
88
+ numberOfChannels: channelData.length
89
+ })
90
+ for (let ch = 0; ch < channelData.length; ch++) audioBuffer.getChannelData(ch).set(channelData[ch])
91
+ return audioBuffer
208
92
  }
@@ -1,77 +1,49 @@
1
1
  {
2
2
  "name": "audio-decode",
3
- "version": "3.10.1",
3
+ "version": "2.2.3",
4
4
  "description": "Decode audio data in node or browser",
5
- "type": "module",
6
- "sideEffects": false,
7
5
  "main": "audio-decode.js",
6
+ "module": "audio-decode.js",
7
+ "browser": "audio-decode.js",
8
+ "type": "module",
8
9
  "types": "audio-decode.d.ts",
9
- "exports": {
10
- ".": {
11
- "browser": "./audio-decode.js",
12
- "node": "./audio-decode.js",
13
- "default": "./audio-decode.js"
14
- },
15
- "./stream": "./stream.js",
16
- "./meta": "./meta.js",
17
- "./package.json": "./package.json"
18
- },
19
- "workspaces": [
20
- "packages/*"
21
- ],
22
10
  "dependencies": {
23
- "@audio/decode-aac": "^1.0.2",
24
- "@audio/decode-aiff": "^1.0.0",
25
- "@audio/decode-amr": "^1.0.0",
26
- "@audio/decode-caf": "^1.0.0",
27
- "@audio/decode-flac": "^1.1.0",
28
- "@audio/decode-mp3": "^1.1.0",
29
- "@audio/decode-opus": "^1.0.0",
30
- "@audio/decode-qoa": "^1.0.0",
31
- "@audio/decode-vorbis": "^1.0.0",
32
- "@audio/decode-wav": "^1.2.0",
33
- "@audio/decode-webm": "^1.0.0",
34
- "@audio/decode-wma": "^1.0.0",
35
- "audio-type": "^2.4.0"
11
+ "@wasm-audio-decoders/flac": "^0.2.4",
12
+ "@wasm-audio-decoders/ogg-vorbis": "^0.1.15",
13
+ "audio-buffer": "^5.0.0",
14
+ "audio-type": "^2.2.1",
15
+ "mpg123-decoder": "^1.0.0",
16
+ "node-wav": "^0.0.2",
17
+ "ogg-opus-decoder": "^1.6.12",
18
+ "qoa-format": "^1.0.1"
36
19
  },
37
20
  "devDependencies": {
38
- "audio-lena": "^3.0.0",
21
+ "audio-lena": "^2.3.0",
39
22
  "base64-arraybuffer": "^1.0.2",
40
- "esbuild": "^0.28.0",
41
- "playwright": "^1.58.0",
42
- "tst": "^9.2.2"
23
+ "tst": "^7.3.0"
43
24
  },
44
25
  "scripts": {
45
- "test": "node test.js",
46
- "test:browser": "node test.browser.js",
47
- "test:all": "node test.js && node test.browser.js",
48
- "publish:all": "npm publish --workspaces && npm publish"
26
+ "test": "node test.js"
49
27
  },
50
28
  "repository": {
51
29
  "type": "git",
52
30
  "url": "git+https://github.com/audiojs/audio-decode.git"
53
31
  },
54
32
  "keywords": [
33
+ "audiojs",
55
34
  "audio",
35
+ "dsp",
56
36
  "decode",
57
- "decoder",
37
+ "audio decode",
38
+ "audio decoder",
39
+ "web audio decoder",
58
40
  "codec",
59
41
  "mp3",
60
42
  "wav",
61
43
  "ogg",
62
44
  "vorbis",
63
45
  "opus",
64
- "flac",
65
- "aac",
66
- "m4a",
67
- "qoa",
68
- "aiff",
69
- "caf",
70
- "webm",
71
- "amr",
72
- "wma",
73
- "pcm",
74
- "streaming"
46
+ "web-audio"
75
47
  ],
76
48
  "author": "ΔY <dfcreative@gmail.com>",
77
49
  "license": "MIT",