@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.
- package/dist/api.js +8 -8
- package/dist/{channel-DA2BAIo5.js → channel-BbtRTgNk.js} +1 -1
- package/dist/channel-plugin-api.js +1 -1
- package/dist/{channel.runtime-Q1LZDB5s.js → channel.runtime-Cf2UgrhZ.js} +3 -3
- package/dist/{channel.setup-DHXOo4h5.js → channel.setup-DaIyWos-.js} +1 -1
- package/dist/{connection-controller-Bnm4INld.js → connection-controller-B07CNCkw.js} +1 -1
- package/dist/{login-2fuBM7Je.js → login-CRtqboZq.js} +2 -2
- package/dist/{login-qr-B1o7GFy8.js → login-qr-B27eAPhh.js} +8 -4
- package/dist/login-qr-runtime.js +5 -5
- package/dist/{monitor-BVRq04Dt.js → monitor-CnioHf5V.js} +34 -28
- package/dist/runtime-api.js +3 -3
- package/dist/{session-DyGWNClj.js → session-mBuvPUCy.js} +27 -18
- package/dist/{setup-core-OvPMaAsx.js → setup-core-C3XZ2KBH.js} +5 -5
- package/dist/{setup-finalize-Dk23pfKc.js → setup-finalize-B7FVDzwJ.js} +2 -2
- package/dist/setup-plugin-api.js +1 -1
- package/dist/{setup-surface-F-jVrH8u.js → setup-surface-CGTWO_-E.js} +1 -1
- package/node_modules/audio-buffer/.eslintrc.json +44 -0
- package/node_modules/audio-buffer/.github/workflows/node.js.yml +31 -0
- package/node_modules/audio-buffer/.travis.yml +7 -0
- package/node_modules/{@audio/decode-opus → audio-buffer}/LICENSE +2 -5
- package/node_modules/audio-buffer/index.js +76 -0
- package/node_modules/audio-buffer/package.json +37 -0
- package/node_modules/audio-buffer/readme.md +56 -0
- package/node_modules/audio-decode/.eslintrc.json +43 -0
- package/node_modules/audio-decode/.github/workflows/test.js.yml +20 -11
- package/node_modules/audio-decode/.travis.yml +13 -0
- package/node_modules/audio-decode/audio-decode.d.ts +10 -48
- package/node_modules/audio-decode/audio-decode.js +77 -193
- package/node_modules/audio-decode/package.json +21 -49
- package/node_modules/audio-decode/readme.md +29 -129
- package/node_modules/audio-decode/tea.yaml +6 -0
- package/node_modules/audio-decode/test-case.js +11 -0
- package/node_modules/audio-decode/test.html +10 -29
- package/node_modules/audio-decode/test.js +107 -0
- package/node_modules/node-wav/README.md +35 -0
- package/node_modules/node-wav/file.wav +0 -0
- package/node_modules/node-wav/index.js +291 -0
- package/node_modules/node-wav/package.json +29 -0
- package/node_modules/node-wav/tests/file1.wav +0 -0
- package/node_modules/node-wav/tests/test.js +66 -0
- package/node_modules/node-wav/x.js +12 -0
- package/node_modules/node-wav/x.json +86702 -0
- package/node_modules/node-wav/x.js~ +13 -0
- package/npm-shrinkwrap.json +32 -149
- package/package.json +5 -5
- package/node_modules/@audio/decode-aac/LICENSE +0 -9
- package/node_modules/@audio/decode-aac/README.md +0 -60
- package/node_modules/@audio/decode-aac/decode-aac.d.ts +0 -16
- package/node_modules/@audio/decode-aac/decode-aac.js +0 -391
- package/node_modules/@audio/decode-aac/package.json +0 -47
- package/node_modules/@audio/decode-aac/src/aac.wasm.cjs +0 -0
- package/node_modules/@audio/decode-aiff/LICENSE +0 -21
- package/node_modules/@audio/decode-aiff/README.md +0 -53
- package/node_modules/@audio/decode-aiff/decode-aiff.d.ts +0 -16
- package/node_modules/@audio/decode-aiff/decode-aiff.js +0 -583
- package/node_modules/@audio/decode-aiff/package.json +0 -42
- package/node_modules/@audio/decode-amr/LICENSE +0 -191
- package/node_modules/@audio/decode-amr/README.md +0 -65
- package/node_modules/@audio/decode-amr/decode-amr.d.ts +0 -16
- package/node_modules/@audio/decode-amr/decode-amr.js +0 -159
- package/node_modules/@audio/decode-amr/package.json +0 -48
- package/node_modules/@audio/decode-amr/src/amr.wasm.cjs +0 -0
- package/node_modules/@audio/decode-caf/LICENSE +0 -21
- package/node_modules/@audio/decode-caf/README.md +0 -55
- package/node_modules/@audio/decode-caf/decode-caf.d.ts +0 -16
- package/node_modules/@audio/decode-caf/decode-caf.js +0 -190
- package/node_modules/@audio/decode-caf/package.json +0 -43
- package/node_modules/@audio/decode-flac/LICENSE +0 -25
- package/node_modules/@audio/decode-flac/README.md +0 -23
- package/node_modules/@audio/decode-flac/decode-flac.d.ts +0 -16
- package/node_modules/@audio/decode-flac/decode-flac.js +0 -2994
- package/node_modules/@audio/decode-flac/meta.js +0 -115
- package/node_modules/@audio/decode-flac/package.json +0 -49
- package/node_modules/@audio/decode-mp3/LICENSE +0 -25
- package/node_modules/@audio/decode-mp3/README.md +0 -23
- package/node_modules/@audio/decode-mp3/decode-mp3.d.ts +0 -16
- package/node_modules/@audio/decode-mp3/decode-mp3.js +0 -868
- package/node_modules/@audio/decode-mp3/meta.js +0 -143
- package/node_modules/@audio/decode-mp3/package.json +0 -50
- package/node_modules/@audio/decode-opus/README.md +0 -23
- package/node_modules/@audio/decode-opus/decode-opus.d.ts +0 -16
- package/node_modules/@audio/decode-opus/decode-opus.js +0 -3179
- package/node_modules/@audio/decode-opus/package.json +0 -47
- package/node_modules/@audio/decode-qoa/LICENSE +0 -25
- package/node_modules/@audio/decode-qoa/README.md +0 -21
- package/node_modules/@audio/decode-qoa/decode-qoa.d.ts +0 -16
- package/node_modules/@audio/decode-qoa/decode-qoa.js +0 -278
- package/node_modules/@audio/decode-qoa/package.json +0 -46
- package/node_modules/@audio/decode-vorbis/LICENSE +0 -25
- package/node_modules/@audio/decode-vorbis/README.md +0 -23
- package/node_modules/@audio/decode-vorbis/decode-vorbis.d.ts +0 -16
- package/node_modules/@audio/decode-vorbis/decode-vorbis.js +0 -2984
- package/node_modules/@audio/decode-vorbis/package.json +0 -47
- package/node_modules/@audio/decode-wav/decode-wav.js +0 -104
- package/node_modules/@audio/decode-wav/meta.js +0 -114
- package/node_modules/@audio/decode-wav/package.json +0 -27
- package/node_modules/@audio/decode-webm/LICENSE +0 -21
- package/node_modules/@audio/decode-webm/README.md +0 -57
- package/node_modules/@audio/decode-webm/decode-webm.d.ts +0 -16
- package/node_modules/@audio/decode-webm/decode-webm.js +0 -3964
- package/node_modules/@audio/decode-webm/package.json +0 -51
- package/node_modules/@audio/decode-wma/LICENSE +0 -12
- package/node_modules/@audio/decode-wma/README.md +0 -76
- package/node_modules/@audio/decode-wma/decode-wma.d.ts +0 -33
- package/node_modules/@audio/decode-wma/decode-wma.js +0 -525
- package/node_modules/@audio/decode-wma/package.json +0 -47
- package/node_modules/@audio/decode-wma/src/wma.wasm.cjs +0 -0
- package/node_modules/audio-decode/.claude/settings.json +0 -204
- package/node_modules/audio-decode/.gitmodules +0 -9
- package/node_modules/audio-decode/meta.js +0 -11
- package/node_modules/audio-decode/stream.d.ts +0 -15
- 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 [](https://github.com/audiojs/audio-buffer/actions/workflows/node.js.yml) [](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
|
+
[](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
|
-
|
|
13
|
+
build:
|
|
14
|
+
|
|
11
15
|
runs-on: ubuntu-latest
|
|
16
|
+
|
|
12
17
|
strategy:
|
|
13
18
|
matrix:
|
|
14
|
-
node-version: [
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
@@ -1,52 +1,14 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
3
|
+
export default function audioDecode(buf: ArrayBuffer | Uint8Array): Promise<AudioBuffer>;
|
|
16
4
|
|
|
17
|
-
interface
|
|
18
|
-
|
|
19
|
-
(
|
|
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
|
-
|
|
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
|
|
3
|
-
* @module
|
|
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
|
|
9
|
+
const AudioBuffer = globalThis.AudioBuffer || AudioBufferShim;
|
|
17
10
|
|
|
18
11
|
/**
|
|
19
|
-
* Decode audio.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
52
|
-
if (!
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
+
"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/
|
|
24
|
-
"@audio/
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
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
|
|
21
|
+
"audio-lena": "^2.3.0",
|
|
39
22
|
"base64-arraybuffer": "^1.0.2",
|
|
40
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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",
|