@qvac/decoder-audio 0.5.0 → 0.6.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/constants.d.ts +2 -3
- package/constants.js +20 -25
- package/index.d.ts +106 -54
- package/index.js +324 -391
- package/package.json +31 -15
- package/test/mobile/integration-runtime.cjs +24 -0
- package/utils/createStreamAccumulator.d.ts +24 -0
- package/utils/createStreamAccumulator.js +44 -57
- package/utils/error.d.ts +19 -0
- package/utils/error.js +75 -79
package/constants.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Audio formats that require decoding before processing
|
|
3
3
|
*/
|
|
4
|
-
export const FORMATS_NEEDING_DECODE: readonly string[]
|
|
5
|
-
|
|
4
|
+
export declare const FORMATS_NEEDING_DECODE: readonly string[];
|
|
6
5
|
/**
|
|
7
6
|
* All supported audio formats (including raw)
|
|
8
7
|
*/
|
|
9
|
-
export const SUPPORTED_AUDIO_FORMATS: readonly string[]
|
|
8
|
+
export declare const SUPPORTED_AUDIO_FORMATS: readonly string[];
|
package/constants.js
CHANGED
|
@@ -1,31 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SUPPORTED_AUDIO_FORMATS = exports.FORMATS_NEEDING_DECODE = void 0;
|
|
3
4
|
/**
|
|
4
5
|
* Audio formats that require decoding before processing
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
]
|
|
14
|
-
|
|
7
|
+
exports.FORMATS_NEEDING_DECODE = [
|
|
8
|
+
".mp3",
|
|
9
|
+
".m4a",
|
|
10
|
+
".ogg",
|
|
11
|
+
".flac",
|
|
12
|
+
".aac",
|
|
13
|
+
".wav",
|
|
14
|
+
];
|
|
15
15
|
/**
|
|
16
16
|
* All supported audio formats (including raw)
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
]
|
|
27
|
-
|
|
28
|
-
module.exports = {
|
|
29
|
-
FORMATS_NEEDING_DECODE,
|
|
30
|
-
SUPPORTED_AUDIO_FORMATS
|
|
31
|
-
}
|
|
18
|
+
exports.SUPPORTED_AUDIO_FORMATS = [
|
|
19
|
+
".mp3",
|
|
20
|
+
".m4a",
|
|
21
|
+
".ogg",
|
|
22
|
+
".wav",
|
|
23
|
+
".flac",
|
|
24
|
+
".aac",
|
|
25
|
+
".raw",
|
|
26
|
+
];
|
package/index.d.ts
CHANGED
|
@@ -1,56 +1,108 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import QvacLogger = require("@qvac/logging");
|
|
2
|
+
import { type QvacResponse } from "@qvac/infer-base";
|
|
3
|
+
/** Output sample formats this decoder can resample to. */
|
|
4
|
+
export type AudioFormatName = "s16le" | "f32le";
|
|
5
|
+
export interface AudioFormatConfig {
|
|
6
|
+
/** FFmpeg sample format id. Null until `load()` resolves it from `ffmpeg.constants`. */
|
|
7
|
+
format: number | null;
|
|
8
|
+
byteLength: number;
|
|
9
|
+
}
|
|
10
|
+
export interface SupportedAudioFormats {
|
|
11
|
+
s16le: AudioFormatConfig;
|
|
12
|
+
f32le: AudioFormatConfig;
|
|
13
|
+
}
|
|
14
|
+
export interface FFmpegDecoderConfig {
|
|
15
|
+
/** Index of the stream to decode (default: 0) */
|
|
16
|
+
streamIndex?: number;
|
|
17
|
+
/** Input audio bitrate (default: 192000) */
|
|
18
|
+
inputBitrate?: number;
|
|
19
|
+
/** Output audio format (default: 's16le') */
|
|
20
|
+
audioFormat?: AudioFormatName;
|
|
21
|
+
/** Output sample rate (default: 16000) */
|
|
22
|
+
sampleRate?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface FFmpegDecoderConstructorParams {
|
|
25
|
+
config?: FFmpegDecoderConfig;
|
|
26
|
+
logger?: QvacLogger.LoggerInterface | null;
|
|
27
|
+
streamIndex?: number;
|
|
28
|
+
inputBitrate?: number;
|
|
29
|
+
audioFormat?: AudioFormatName;
|
|
30
|
+
}
|
|
28
31
|
export interface DecoderOutput {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
interface RuntimeStats {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
32
|
+
/** Raw interleaved PCM in the configured output format. */
|
|
33
|
+
outputArray: Buffer;
|
|
34
|
+
}
|
|
35
|
+
export interface RuntimeStats {
|
|
36
|
+
decodeTimeMs: number;
|
|
37
|
+
inputBytes: number;
|
|
38
|
+
outputBytes: number;
|
|
39
|
+
samplesDecoded: number;
|
|
40
|
+
codecName: string | null;
|
|
41
|
+
inputSampleRate: number;
|
|
42
|
+
outputSampleRate: number;
|
|
43
|
+
audioFormat: AudioFormatName;
|
|
44
|
+
}
|
|
45
|
+
/** Constructor arguments after defaults have been applied. */
|
|
46
|
+
interface ResolvedConfig {
|
|
47
|
+
streamIndex: number;
|
|
48
|
+
inputBitrate: number;
|
|
49
|
+
audioFormat: AudioFormatName;
|
|
50
|
+
sampleRate: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* FFmpeg-based audio decoder (single-threaded)
|
|
54
|
+
*/
|
|
43
55
|
declare class FFmpegDecoder {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
SUPPORTED_AUDIO_FORMATS: SupportedAudioFormats;
|
|
57
|
+
OUTPUT_CHANNEL_LAYOUT: number | null;
|
|
58
|
+
config: ResolvedConfig;
|
|
59
|
+
logger: QvacLogger;
|
|
60
|
+
isLoaded: boolean;
|
|
61
|
+
samplesSkipped: number;
|
|
62
|
+
totalSkipSamples: number;
|
|
63
|
+
private _cancelled;
|
|
64
|
+
private readonly _job;
|
|
65
|
+
private _runtimeStats;
|
|
66
|
+
/**
|
|
67
|
+
* Creates an instance of FFmpegDecoder.
|
|
68
|
+
* @param params - Configuration options. Top-level `streamIndex`, `inputBitrate`
|
|
69
|
+
* and `audioFormat` act as fallbacks for the matching `config` fields.
|
|
70
|
+
*/
|
|
71
|
+
constructor({ config, logger, streamIndex, inputBitrate, audioFormat, }?: FFmpegDecoderConstructorParams);
|
|
72
|
+
/**
|
|
73
|
+
* Resets the runtime stats
|
|
74
|
+
*/
|
|
75
|
+
private _resetStats;
|
|
76
|
+
/**
|
|
77
|
+
* Get the current runtime stats
|
|
78
|
+
* @returns Current runtime stats
|
|
79
|
+
*/
|
|
80
|
+
runtimeStats(): RuntimeStats;
|
|
81
|
+
/**
|
|
82
|
+
* Load and initialize the decoder
|
|
83
|
+
*/
|
|
84
|
+
load(): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Unload the decoder and clean up resources
|
|
87
|
+
*/
|
|
88
|
+
unload(): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Run the decoder on an audio stream
|
|
91
|
+
* @param audioStream - Input audio stream
|
|
92
|
+
* @returns Response with decoded audio
|
|
93
|
+
*/
|
|
94
|
+
run(audioStream: AsyncIterable<Buffer>): QvacResponse<DecoderOutput>;
|
|
95
|
+
private _cancelCurrent;
|
|
96
|
+
private _getBufferSize;
|
|
97
|
+
/**
|
|
98
|
+
* Resolves the output constants populated by `load()`. Unreachable before
|
|
99
|
+
* `load()` succeeds, since every caller sits behind the `isLoaded` guard.
|
|
100
|
+
*/
|
|
101
|
+
private _resolveOutputFormat;
|
|
102
|
+
private _processFrame;
|
|
103
|
+
private _processPacket;
|
|
104
|
+
private _processFFmpegStream;
|
|
105
|
+
private _collectStreamData;
|
|
106
|
+
private _processStream;
|
|
107
|
+
}
|
|
108
|
+
export { FFmpegDecoder };
|