node-av 4.0.0 → 5.0.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.
Files changed (104) hide show
  1. package/README.md +23 -0
  2. package/binding.gyp +19 -11
  3. package/dist/api/bitstream-filter.d.ts +13 -12
  4. package/dist/api/bitstream-filter.js +33 -29
  5. package/dist/api/bitstream-filter.js.map +1 -1
  6. package/dist/api/decoder.d.ts +211 -96
  7. package/dist/api/decoder.js +396 -375
  8. package/dist/api/decoder.js.map +1 -1
  9. package/dist/api/demuxer.d.ts +10 -10
  10. package/dist/api/demuxer.js +7 -10
  11. package/dist/api/demuxer.js.map +1 -1
  12. package/dist/api/encoder.d.ts +155 -122
  13. package/dist/api/encoder.js +368 -541
  14. package/dist/api/encoder.js.map +1 -1
  15. package/dist/api/filter-complex.d.ts +769 -0
  16. package/dist/api/filter-complex.js +1596 -0
  17. package/dist/api/filter-complex.js.map +1 -0
  18. package/dist/api/filter-presets.d.ts +68 -0
  19. package/dist/api/filter-presets.js +96 -0
  20. package/dist/api/filter-presets.js.map +1 -1
  21. package/dist/api/filter.d.ts +183 -113
  22. package/dist/api/filter.js +347 -365
  23. package/dist/api/filter.js.map +1 -1
  24. package/dist/api/fmp4-stream.d.ts +2 -2
  25. package/dist/api/fmp4-stream.js.map +1 -1
  26. package/dist/api/index.d.ts +2 -0
  27. package/dist/api/index.js +3 -0
  28. package/dist/api/index.js.map +1 -1
  29. package/dist/api/io-stream.d.ts +3 -3
  30. package/dist/api/io-stream.js.map +1 -1
  31. package/dist/api/muxer.d.ts +10 -10
  32. package/dist/api/muxer.js +6 -6
  33. package/dist/api/muxer.js.map +1 -1
  34. package/dist/api/pipeline.d.ts +2 -2
  35. package/dist/api/pipeline.js +22 -22
  36. package/dist/api/pipeline.js.map +1 -1
  37. package/dist/api/rtp-stream.d.ts +2 -2
  38. package/dist/api/rtp-stream.js.map +1 -1
  39. package/dist/api/types.d.ts +63 -7
  40. package/dist/api/utilities/audio-sample.d.ts +10 -0
  41. package/dist/api/utilities/audio-sample.js +10 -0
  42. package/dist/api/utilities/audio-sample.js.map +1 -1
  43. package/dist/api/utilities/channel-layout.d.ts +1 -0
  44. package/dist/api/utilities/channel-layout.js +1 -0
  45. package/dist/api/utilities/channel-layout.js.map +1 -1
  46. package/dist/api/utilities/image.d.ts +38 -0
  47. package/dist/api/utilities/image.js +38 -0
  48. package/dist/api/utilities/image.js.map +1 -1
  49. package/dist/api/utilities/index.d.ts +1 -0
  50. package/dist/api/utilities/index.js +2 -0
  51. package/dist/api/utilities/index.js.map +1 -1
  52. package/dist/api/utilities/media-type.d.ts +1 -0
  53. package/dist/api/utilities/media-type.js +1 -0
  54. package/dist/api/utilities/media-type.js.map +1 -1
  55. package/dist/api/utilities/pixel-format.d.ts +3 -0
  56. package/dist/api/utilities/pixel-format.js +3 -0
  57. package/dist/api/utilities/pixel-format.js.map +1 -1
  58. package/dist/api/utilities/sample-format.d.ts +5 -0
  59. package/dist/api/utilities/sample-format.js +5 -0
  60. package/dist/api/utilities/sample-format.js.map +1 -1
  61. package/dist/api/utilities/scheduler.d.ts +21 -52
  62. package/dist/api/utilities/scheduler.js +20 -58
  63. package/dist/api/utilities/scheduler.js.map +1 -1
  64. package/dist/api/utilities/streaming.d.ts +32 -1
  65. package/dist/api/utilities/streaming.js +32 -1
  66. package/dist/api/utilities/streaming.js.map +1 -1
  67. package/dist/api/utilities/timestamp.d.ts +14 -0
  68. package/dist/api/utilities/timestamp.js +14 -0
  69. package/dist/api/utilities/timestamp.js.map +1 -1
  70. package/dist/api/utilities/whisper-model.d.ts +310 -0
  71. package/dist/api/utilities/whisper-model.js +528 -0
  72. package/dist/api/utilities/whisper-model.js.map +1 -0
  73. package/dist/api/whisper.d.ts +324 -0
  74. package/dist/api/whisper.js +362 -0
  75. package/dist/api/whisper.js.map +1 -0
  76. package/dist/constants/constants.d.ts +3 -1
  77. package/dist/constants/constants.js +1 -0
  78. package/dist/constants/constants.js.map +1 -1
  79. package/dist/ffmpeg/index.d.ts +3 -3
  80. package/dist/ffmpeg/index.js +3 -3
  81. package/dist/ffmpeg/utils.d.ts +27 -0
  82. package/dist/ffmpeg/utils.js +28 -16
  83. package/dist/ffmpeg/utils.js.map +1 -1
  84. package/dist/lib/binding.d.ts +4 -4
  85. package/dist/lib/binding.js.map +1 -1
  86. package/dist/lib/codec-parameters.d.ts +47 -1
  87. package/dist/lib/codec-parameters.js +55 -0
  88. package/dist/lib/codec-parameters.js.map +1 -1
  89. package/dist/lib/fifo.d.ts +416 -0
  90. package/dist/lib/fifo.js +453 -0
  91. package/dist/lib/fifo.js.map +1 -0
  92. package/dist/lib/frame.d.ts +96 -1
  93. package/dist/lib/frame.js +139 -1
  94. package/dist/lib/frame.js.map +1 -1
  95. package/dist/lib/index.d.ts +1 -0
  96. package/dist/lib/index.js +2 -0
  97. package/dist/lib/index.js.map +1 -1
  98. package/dist/lib/native-types.d.ts +29 -2
  99. package/dist/lib/rational.d.ts +18 -0
  100. package/dist/lib/rational.js +19 -0
  101. package/dist/lib/rational.js.map +1 -1
  102. package/dist/lib/types.d.ts +23 -1
  103. package/install/check.js +2 -2
  104. package/package.json +30 -20
@@ -0,0 +1,310 @@
1
+ /**
2
+ * Model type for Whisper downloads
3
+ */
4
+ export type WhisperModelType = 'ggml' | 'vad';
5
+ /**
6
+ * Options for downloading a Whisper model
7
+ */
8
+ export interface DownloadOptions {
9
+ model: WhisperModelName | WhisperVADModelName;
10
+ outputPath?: string;
11
+ type?: WhisperModelType;
12
+ }
13
+ /**
14
+ * Standard GGML Whisper models
15
+ */
16
+ export declare const WHISPER_MODELS: readonly ["tiny", "tiny.en", "tiny-q5_1", "tiny.en-q5_1", "tiny-q8_0", "base", "base.en", "base-q5_1", "base.en-q5_1", "base-q8_0", "small", "small.en", "small.en-tdrz", "small-q5_1", "small.en-q5_1", "small-q8_0", "medium", "medium.en", "medium-q5_0", "medium.en-q5_0", "medium-q8_0", "large-v1", "large-v2", "large-v2-q5_0", "large-v2-q8_0", "large-v3", "large-v3-q5_0", "large-v3-turbo", "large-v3-turbo-q5_0", "large-v3-turbo-q8_0"];
17
+ /**
18
+ * Whisper VAD (Voice Activity Detection) models
19
+ */
20
+ export declare const WHISPER_VAD_MODELS: readonly ["silero-v5.1.2", "silero-v6.2.0"];
21
+ export type WhisperModelName = (typeof WHISPER_MODELS)[number];
22
+ export type WhisperVADModelName = (typeof WHISPER_VAD_MODELS)[number];
23
+ /**
24
+ * Whisper.cpp model downloader utilities.
25
+ *
26
+ * Provides static methods for downloading GGML and VAD models from HuggingFace,
27
+ * validating model names, and checking model availability. Supports automatic
28
+ * model type detection and prevents concurrent downloads of the same model.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * import { WhisperDownloader } from 'node-av';
33
+ *
34
+ * // Download a GGML model
35
+ * const modelPath = await WhisperDownloader.downloadModel({
36
+ * model: 'base',
37
+ * outputPath: './models'
38
+ * });
39
+ *
40
+ * // Download a VAD model
41
+ * const vadPath = await WhisperDownloader.downloadVADModel('silero-v5.1.2', './models');
42
+ *
43
+ * // Check available models
44
+ * const categories = WhisperDownloader.getModelsByCategory();
45
+ * console.log(categories); // Map { 'tiny' => ['tiny', 'tiny.en', ...], ... }
46
+ * ```
47
+ */
48
+ export declare class WhisperDownloader {
49
+ static readonly DEFAULT_MODEL_PATH: string;
50
+ private static readonly DEFAULT_SRC;
51
+ private static readonly DEFAULT_PFX;
52
+ private static readonly TDRZ_SRC;
53
+ private static readonly TDRZ_PFX;
54
+ private static readonly VAD_SRC;
55
+ private static readonly VAD_PFX;
56
+ private static readonly activeDownloads;
57
+ private constructor();
58
+ /**
59
+ * Check if a model name is a valid GGML model.
60
+ *
61
+ * Validates whether the provided string matches one of the available
62
+ * GGML Whisper model names.
63
+ *
64
+ * @param model - Model name to validate
65
+ *
66
+ * @returns True if the model is a valid GGML model name
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * import { WhisperDownloader } from 'node-av';
71
+ *
72
+ * console.log(WhisperDownloader.isValidModel('base')); // true
73
+ * console.log(WhisperDownloader.isValidModel('large-v3')); // true
74
+ * console.log(WhisperDownloader.isValidModel('invalid')); // false
75
+ * ```
76
+ */
77
+ static isValidModel(model: string): model is WhisperModelName;
78
+ /**
79
+ * Check if a model name is a valid VAD model.
80
+ *
81
+ * Validates whether the provided string matches one of the available
82
+ * Silero VAD model names.
83
+ *
84
+ * @param model - Model name to validate
85
+ *
86
+ * @returns True if the model is a valid VAD model name
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * import { WhisperDownloader } from 'node-av';
91
+ *
92
+ * console.log(WhisperDownloader.isValidVADModel('silero-v5.1.2')); // true
93
+ * console.log(WhisperDownloader.isValidVADModel('invalid')); // false
94
+ * ```
95
+ */
96
+ static isValidVADModel(model: string): model is WhisperVADModelName;
97
+ /**
98
+ * Get all available GGML models grouped by category.
99
+ *
100
+ * Returns a map of model categories (tiny, base, small, medium, large)
101
+ * with their corresponding model variants.
102
+ *
103
+ * @returns Map of category names to model name arrays
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * import { WhisperDownloader } from 'node-av';
108
+ *
109
+ * const categories = WhisperDownloader.getModelsByCategory();
110
+ * console.log(categories.get('base'));
111
+ * // ['base', 'base.en', 'base-q5_1', 'base.en-q5_1', 'base-q8_0']
112
+ *
113
+ * // List all categories
114
+ * for (const [category, models] of categories) {
115
+ * console.log(`${category}: ${models.length} variants`);
116
+ * }
117
+ * ```
118
+ */
119
+ static getModelsByCategory(): Map<string, string[]>;
120
+ /**
121
+ * Get the download URL for a model.
122
+ *
123
+ * Constructs the HuggingFace download URL for a given model name.
124
+ * Automatically detects whether it's a GGML or VAD model if type is not specified.
125
+ * Handles special models like tinydiarize variants.
126
+ *
127
+ * @param model - Model name
128
+ *
129
+ * @param type - Model type (auto-detected if not provided)
130
+ *
131
+ * @returns Full download URL for the model
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * import { WhisperDownloader } from 'node-av';
136
+ *
137
+ * // GGML model URL
138
+ * const url = WhisperDownloader.getModelUrl('base');
139
+ * console.log(url);
140
+ * // 'https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.bin'
141
+ *
142
+ * // VAD model URL
143
+ * const vadUrl = WhisperDownloader.getModelUrl('silero-v5.1.2');
144
+ * console.log(vadUrl);
145
+ * // 'https://huggingface.co/ggml-org/whisper-vad/resolve/main/ggml-silero-v5.1.2.bin'
146
+ * ```
147
+ */
148
+ static getModelUrl(model: string, type?: WhisperModelType): string;
149
+ /**
150
+ * Check if a model file already exists.
151
+ *
152
+ * Checks whether a model file has already been downloaded to the specified path.
153
+ * Useful for skipping redundant downloads.
154
+ *
155
+ * @param model - Model name
156
+ *
157
+ * @param outputPath - Directory path to check
158
+ *
159
+ * @returns True if the model file exists
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * import { WhisperDownloader } from 'node-av';
164
+ *
165
+ * if (WhisperDownloader.modelExists('base', './models')) {
166
+ * console.log('Model already downloaded');
167
+ * } else {
168
+ * await WhisperDownloader.downloadModel({
169
+ * model: 'base',
170
+ * outputPath: './models'
171
+ * });
172
+ * }
173
+ * ```
174
+ */
175
+ static modelExists(model: string, outputPath: string): boolean;
176
+ /**
177
+ * Find whisper-cli executable in system PATH.
178
+ *
179
+ * Searches for whisper-cli binary in system PATH and local build directory.
180
+ * Returns the path to the executable if found.
181
+ *
182
+ * @returns Path to whisper-cli executable, or null if not found
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * import { WhisperDownloader } from 'node-av';
187
+ *
188
+ * const cliPath = await WhisperDownloader.findWhisperCli();
189
+ * if (cliPath) {
190
+ * console.log(`Found whisper-cli at: ${cliPath}`);
191
+ * } else {
192
+ * console.log('whisper-cli not found');
193
+ * }
194
+ * ```
195
+ */
196
+ static findWhisperCli(): Promise<string | null>;
197
+ /**
198
+ * Download a Whisper model file.
199
+ *
200
+ * Downloads a GGML or VAD model from HuggingFace to the specified directory.
201
+ * Automatically detects model type based on model name if not specified.
202
+ * Prevents race conditions when the same model is downloaded concurrently.
203
+ * Returns immediately if the model file already exists.
204
+ *
205
+ * @param options - Download configuration options
206
+ *
207
+ * @returns Path to the downloaded model file
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * import { WhisperDownloader } from 'node-av';
212
+ *
213
+ * // Download GGML model (auto-detected)
214
+ * const path = await WhisperDownloader.downloadModel({
215
+ * model: 'base',
216
+ * outputPath: './models'
217
+ * });
218
+ * console.log(`Downloaded to: ${path}`);
219
+ *
220
+ * // Download VAD model (auto-detected)
221
+ * const vadPath = await WhisperDownloader.downloadModel({
222
+ * model: 'silero-v5.1.2',
223
+ * outputPath: './models'
224
+ * });
225
+ *
226
+ * // Explicit type specification
227
+ * const explicitPath = await WhisperDownloader.downloadModel({
228
+ * model: 'base',
229
+ * outputPath: './models',
230
+ * type: 'ggml'
231
+ * });
232
+ * ```
233
+ */
234
+ static downloadModel(options: DownloadOptions): Promise<string>;
235
+ /**
236
+ * Download a VAD model (convenience method).
237
+ *
238
+ * Convenience wrapper for downloading VAD models without specifying type.
239
+ * Equivalent to calling downloadModel() with type: 'vad'.
240
+ *
241
+ * @param model - VAD model name
242
+ *
243
+ * @param outputPath - Directory path for download (default: current directory)
244
+ *
245
+ * @returns Path to the downloaded VAD model file
246
+ *
247
+ * @example
248
+ * ```typescript
249
+ * import { WhisperDownloader } from 'node-av';
250
+ *
251
+ * const vadPath = await WhisperDownloader.downloadVADModel(
252
+ * 'silero-v5.1.2',
253
+ * './models'
254
+ * );
255
+ * console.log(`VAD model downloaded to: ${vadPath}`);
256
+ * ```
257
+ */
258
+ static downloadVADModel(model: WhisperVADModelName, outputPath?: string): Promise<string>;
259
+ /**
260
+ * Download multiple Whisper models.
261
+ *
262
+ * Downloads multiple models sequentially to avoid overwhelming the network.
263
+ * Each model is validated and downloaded using the same logic as downloadModel().
264
+ *
265
+ * @param models - Array of model names to download
266
+ *
267
+ * @param outputPath - Directory path for downloads (default: current directory)
268
+ *
269
+ * @param type - Model type for all models (auto-detected if not provided)
270
+ *
271
+ * @returns Array of paths to downloaded model files
272
+ *
273
+ * @example
274
+ * ```typescript
275
+ * import { WhisperDownloader } from 'node-av';
276
+ *
277
+ * // Download multiple GGML models
278
+ * const paths = await WhisperDownloader.downloadModels(
279
+ * ['tiny', 'base', 'small'],
280
+ * './models'
281
+ * );
282
+ * console.log(`Downloaded ${paths.length} models`);
283
+ *
284
+ * // Download multiple VAD models
285
+ * const vadPaths = await WhisperDownloader.downloadModels(
286
+ * ['silero-v5.1.2', 'silero-v6.2.0'],
287
+ * './models',
288
+ * 'vad'
289
+ * );
290
+ * ```
291
+ */
292
+ static downloadModels(models: (WhisperModelName | WhisperVADModelName)[], outputPath?: string, type?: WhisperModelType): Promise<string[]>;
293
+ /**
294
+ * Follow HTTP redirects recursively to download a file.
295
+ *
296
+ * Handles HTTP redirects (301, 302, 307, 308) up to a maximum of 5 redirects.
297
+ * Downloads the file to the specified output path.
298
+ *
299
+ * @param url - URL to download
300
+ *
301
+ * @param outputPath - Local file path to save the download
302
+ *
303
+ * @param redirectCount - Current redirect count (used internally)
304
+ *
305
+ * @returns Promise that resolves when the download is complete
306
+ *
307
+ * @internal
308
+ */
309
+ private static followRedirect;
310
+ }