@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 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
- 'use strict'
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
- const FORMATS_NEEDING_DECODE = [
7
- '.mp3',
8
- '.m4a',
9
- '.ogg',
10
- '.flac',
11
- '.aac',
12
- '.wav'
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
- const SUPPORTED_AUDIO_FORMATS = [
19
- '.mp3',
20
- '.m4a',
21
- '.ogg',
22
- '.wav',
23
- '.flac',
24
- '.aac',
25
- '.raw'
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 { QvacResponse } from '@qvac/infer-base'
2
-
3
- interface AudioFormatConfig {
4
- format: number | null
5
- byteLength: number
6
- }
7
-
8
- interface SupportedAudioFormats {
9
- s16le: AudioFormatConfig
10
- f32le: AudioFormatConfig
11
- }
12
-
13
- interface FFmpegDecoderConfig {
14
- streamIndex?: number
15
- inputBitrate?: number
16
- audioFormat?: 's16le' | 'f32le'
17
- sampleRate?: number
18
- }
19
-
20
- interface FFmpegDecoderConstructorParams {
21
- config?: FFmpegDecoderConfig
22
- logger?: any
23
- streamIndex?: number
24
- inputBitrate?: number
25
- audioFormat?: 's16le' | 'f32le'
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
- outputArray: ArrayBuffer
30
- }
31
-
32
- interface RuntimeStats {
33
- decodeTimeMs: number
34
- inputBytes: number
35
- outputBytes: number
36
- samplesDecoded: number
37
- codecName: string | null
38
- inputSampleRate: number
39
- outputSampleRate: number
40
- audioFormat: 's16le' | 'f32le'
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
- SUPPORTED_AUDIO_FORMATS: SupportedAudioFormats
45
- OUTPUT_CHANNEL_LAYOUT: number | null
46
-
47
- constructor(params?: FFmpegDecoderConstructorParams)
48
-
49
- load(): Promise<void>
50
- unload(): Promise<void>
51
- run(audioStream: AsyncIterable<Buffer>): QvacResponse<DecoderOutput>
52
-
53
- runtimeStats(): RuntimeStats
54
- }
55
-
56
- export { FFmpegDecoder, RuntimeStats, DecoderOutput }
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 };