@nodetool-ai/audio-nodes 0.8.1

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 (59) hide show
  1. package/README.md +62 -0
  2. package/dist/.nodetool-build-stamp +1 -0
  3. package/dist/index.d.ts +12 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +14 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/audio-context.d.ts +7 -0
  8. package/dist/lib/audio-context.d.ts.map +1 -0
  9. package/dist/lib/audio-context.js +42 -0
  10. package/dist/lib/audio-context.js.map +1 -0
  11. package/dist/lib/audio-wav.d.ts +133 -0
  12. package/dist/lib/audio-wav.d.ts.map +1 -0
  13. package/dist/lib/audio-wav.js +504 -0
  14. package/dist/lib/audio-wav.js.map +1 -0
  15. package/dist/lib/biquad.d.ts +48 -0
  16. package/dist/lib/biquad.d.ts.map +1 -0
  17. package/dist/lib/biquad.js +127 -0
  18. package/dist/lib/biquad.js.map +1 -0
  19. package/dist/lib/cv.d.ts +141 -0
  20. package/dist/lib/cv.d.ts.map +1 -0
  21. package/dist/lib/cv.js +261 -0
  22. package/dist/lib/cv.js.map +1 -0
  23. package/dist/lib/synth-dsp.d.ts +43 -0
  24. package/dist/lib/synth-dsp.d.ts.map +1 -0
  25. package/dist/lib/synth-dsp.js +88 -0
  26. package/dist/lib/synth-dsp.js.map +1 -0
  27. package/dist/nodes/audio.d.ts +527 -0
  28. package/dist/nodes/audio.d.ts.map +1 -0
  29. package/dist/nodes/audio.js +1816 -0
  30. package/dist/nodes/audio.js.map +1 -0
  31. package/dist/nodes/game.d.ts +68 -0
  32. package/dist/nodes/game.d.ts.map +1 -0
  33. package/dist/nodes/game.js +304 -0
  34. package/dist/nodes/game.js.map +1 -0
  35. package/dist/nodes/lib-audio-dsp.d.ts +146 -0
  36. package/dist/nodes/lib-audio-dsp.d.ts.map +1 -0
  37. package/dist/nodes/lib-audio-dsp.js +477 -0
  38. package/dist/nodes/lib-audio-dsp.js.map +1 -0
  39. package/dist/nodes/lib-audio-effects.d.ts +174 -0
  40. package/dist/nodes/lib-audio-effects.d.ts.map +1 -0
  41. package/dist/nodes/lib-audio-effects.js +962 -0
  42. package/dist/nodes/lib-audio-effects.js.map +1 -0
  43. package/dist/nodes/output.d.ts +29 -0
  44. package/dist/nodes/output.d.ts.map +1 -0
  45. package/dist/nodes/output.js +179 -0
  46. package/dist/nodes/output.js.map +1 -0
  47. package/dist/nodes/preview.d.ts +26 -0
  48. package/dist/nodes/preview.d.ts.map +1 -0
  49. package/dist/nodes/preview.js +44 -0
  50. package/dist/nodes/preview.js.map +1 -0
  51. package/dist/nodes/realtime-audio.d.ts +118 -0
  52. package/dist/nodes/realtime-audio.d.ts.map +1 -0
  53. package/dist/nodes/realtime-audio.js +391 -0
  54. package/dist/nodes/realtime-audio.js.map +1 -0
  55. package/dist/nodes/synthesis.d.ts +194 -0
  56. package/dist/nodes/synthesis.d.ts.map +1 -0
  57. package/dist/nodes/synthesis.js +955 -0
  58. package/dist/nodes/synthesis.js.map +1 -0
  59. package/package.json +80 -0
@@ -0,0 +1,1816 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BaseNode, prop } from "@nodetool-ai/node-sdk";
8
+ import { loadOfflineAudioContext } from "../lib/audio-context.js";
9
+ import { tagAsServer } from "@nodetool-ai/nodes-utils";
10
+ import { loadNodeFsPromises, loadNodePath, writeSavedFile, VISIBLE_WHEN_NOT_SAVING_TO_WORKSPACE, SAVE_TO_WORKSPACE_DESCRIPTION, SAVE_TO_WORKSPACE_TITLE } from "@nodetool-ai/nodes-utils";
11
+ const NODE_ONLY = ["node"];
12
+ import { audioBytes, audioBytesAsync, audioRefFromBytes, audioRefFromWav, concatBytes, decodeAudioToWav, encodePcm16Wav, encodeWav, parseWavBytes, readWavHeader, requireAudioBytes, toBytes, uriToPath } from "../lib/audio-wav.js";
13
+ import { isNonEmptyString, isObjectLike, isPositiveNumber, isString } from "@nodetool-ai/node-sdk";
14
+ const DEFAULT_AUDIO_EXTENSIONS = [
15
+ ".mp3",
16
+ ".wav",
17
+ ".flac",
18
+ ".ogg",
19
+ ".m4a",
20
+ ".aac"
21
+ ];
22
+ /** Number of sample frames (samples per channel) in a decoded WAV. */
23
+ function wavFrameCount(wav) {
24
+ return wav.numChannels > 0
25
+ ? Math.floor(wav.samples.length / wav.numChannels)
26
+ : 0;
27
+ }
28
+ /**
29
+ * Recursively (optionally) walk a folder yielding audio files whose extension
30
+ * is in `extensions` (compared case-insensitively, leading dot required).
31
+ */
32
+ async function* walkAudioFiles(folder, extensions, recursive) {
33
+ const fs = await loadNodeFsPromises();
34
+ const path = await loadNodePath();
35
+ let entries;
36
+ try {
37
+ entries = await fs.readdir(folder, { withFileTypes: true });
38
+ }
39
+ catch {
40
+ // folder does not exist or is not accessible
41
+ return;
42
+ }
43
+ for (const entry of entries) {
44
+ const full = path.join(folder, entry.name);
45
+ if (entry.isDirectory()) {
46
+ if (recursive)
47
+ yield* walkAudioFiles(full, extensions, recursive);
48
+ continue;
49
+ }
50
+ if (!entry.isFile())
51
+ continue;
52
+ const ext = path.extname(entry.name).toLowerCase();
53
+ if (!extensions.includes(ext))
54
+ continue;
55
+ yield { full, name: entry.name };
56
+ }
57
+ }
58
+ /**
59
+ * Resolve a folder prop that may be a plain path string, a `file:` URI, or a
60
+ * folder asset ref (`{ type: "folder", uri }`) into a filesystem path.
61
+ */
62
+ function resolveFolderPath(raw) {
63
+ if (isNonEmptyString(raw)) {
64
+ return raw.startsWith("file:") ? uriToPath(raw) : raw;
65
+ }
66
+ if (isObjectLike(raw) && isNonEmptyString(raw.uri)) {
67
+ return uriToPath(raw.uri);
68
+ }
69
+ return "";
70
+ }
71
+ function dateName(name) {
72
+ const now = new Date();
73
+ const pad = (v) => String(v).padStart(2, "0");
74
+ return name
75
+ .replaceAll("%Y", String(now.getFullYear()))
76
+ .replaceAll("%m", pad(now.getMonth() + 1))
77
+ .replaceAll("%d", pad(now.getDate()))
78
+ .replaceAll("%H", pad(now.getHours()))
79
+ .replaceAll("%M", pad(now.getMinutes()))
80
+ .replaceAll("%S", pad(now.getSeconds()));
81
+ }
82
+ function getModelConfig(props) {
83
+ const model = (props.model ?? {});
84
+ if (isString(model)) {
85
+ return { providerId: "", modelId: model };
86
+ }
87
+ return {
88
+ providerId: isString(model.provider) ? model.provider : "",
89
+ modelId: isString(model.id) ? model.id : ""
90
+ };
91
+ }
92
+ function hasProviderSupport(context, providerId, modelId) {
93
+ return (!!context &&
94
+ typeof context.runProviderPrediction === "function" &&
95
+ typeof context.streamProviderPrediction === "function" &&
96
+ typeof context.providerSupportsStreamingTTS === "function" &&
97
+ typeof context.textToSpeechEncoded === "function" &&
98
+ !!providerId &&
99
+ !!modelId);
100
+ }
101
+ export class LoadAudioAssetsNode extends BaseNode {
102
+ static nodeType = "nodetool.audio.LoadAudioAssets";
103
+ static platforms = NODE_ONLY;
104
+ static title = "Load Audio Assets";
105
+ static description = "Load audio files from an asset folder.\n load, audio, file, import";
106
+ static metadataOutputTypes = {
107
+ audio: "audio",
108
+ name: "str",
109
+ audios: "list"
110
+ };
111
+ static inlineFields = [];
112
+ static inputFields = [];
113
+ static inputMode = "buffered";
114
+ static outputCorrelation = {
115
+ audio: { kind: "iteration", source: "__execution__", group: "items" },
116
+ name: { kind: "iteration", source: "__execution__", group: "items" },
117
+ audios: { kind: "single", source: "__execution__" }
118
+ };
119
+ async process() {
120
+ const collected = [];
121
+ const names = [];
122
+ for await (const item of this._loadAudios()) {
123
+ collected.push(item.audio);
124
+ names.push(String(item.name ?? ""));
125
+ }
126
+ return {
127
+ audio: collected[0] ?? {},
128
+ name: names[0] ?? "",
129
+ audios: collected
130
+ };
131
+ }
132
+ async *_loadAudios() {
133
+ const folder = resolveFolderPath(this.folder);
134
+ if (!folder)
135
+ return;
136
+ const fs = await loadNodeFsPromises();
137
+ for await (const { full, name } of walkAudioFiles(folder, DEFAULT_AUDIO_EXTENSIONS, false)) {
138
+ const data = new Uint8Array(await fs.readFile(full));
139
+ yield {
140
+ audio: audioRefFromBytes(data, `file://${full}`),
141
+ name
142
+ };
143
+ }
144
+ }
145
+ async *genProcess() {
146
+ const collected = [];
147
+ for await (const item of this._loadAudios()) {
148
+ collected.push(item.audio);
149
+ yield item;
150
+ }
151
+ yield { audios: collected };
152
+ }
153
+ }
154
+ __decorate([
155
+ prop({
156
+ type: "folder",
157
+ default: {
158
+ type: "folder",
159
+ uri: "",
160
+ asset_id: null,
161
+ data: null,
162
+ metadata: null
163
+ },
164
+ title: "Folder",
165
+ description: "The asset folder to load the audio files from."
166
+ })
167
+ ], LoadAudioAssetsNode.prototype, "folder", void 0);
168
+ export class LoadAudioFileNode extends BaseNode {
169
+ static nodeType = "nodetool.audio.LoadAudioFile";
170
+ static platforms = NODE_ONLY;
171
+ static title = "Load Audio File";
172
+ static description = "Read an audio file from disk.\n audio, input, load, file";
173
+ static metadataOutputTypes = {
174
+ output: "audio"
175
+ };
176
+ static inlineFields = [];
177
+ static inputFields = [];
178
+ async process() {
179
+ const p = uriToPath(this.path);
180
+ const fs = await loadNodeFsPromises();
181
+ const data = new Uint8Array(await fs.readFile(p));
182
+ return { output: audioRefFromBytes(data, `file://${p}`) };
183
+ }
184
+ }
185
+ __decorate([
186
+ prop({
187
+ type: "str",
188
+ default: "",
189
+ title: "Path",
190
+ description: "Path to the audio file to read"
191
+ })
192
+ ], LoadAudioFileNode.prototype, "path", void 0);
193
+ export class LoadAudioFolderNode extends BaseNode {
194
+ static nodeType = "nodetool.audio.LoadAudioFolder";
195
+ static platforms = NODE_ONLY;
196
+ static title = "Load Audio Folder";
197
+ static description = "Load all audio files from a folder, optionally including subfolders.\n audio, load, folder, files";
198
+ static metadataOutputTypes = {
199
+ audio: "audio",
200
+ path: "str",
201
+ audios: "list"
202
+ };
203
+ static inlineFields = [];
204
+ static inputFields = [];
205
+ static inputMode = "buffered";
206
+ static outputCorrelation = {
207
+ audio: { kind: "iteration", source: "__execution__", group: "items" },
208
+ path: { kind: "iteration", source: "__execution__", group: "items" },
209
+ audios: { kind: "single", source: "__execution__" }
210
+ };
211
+ _extensions() {
212
+ return this.extensions.map((e) => {
213
+ const s = String(e).toLowerCase();
214
+ return s.startsWith(".") ? s : `.${s}`;
215
+ });
216
+ }
217
+ async *_load() {
218
+ const folder = resolveFolderPath(this.folder);
219
+ if (!folder)
220
+ return;
221
+ const recursive = this.include_subdirectories;
222
+ const extensions = this._extensions();
223
+ const fs = await loadNodeFsPromises();
224
+ for await (const { full } of walkAudioFiles(folder, extensions, recursive)) {
225
+ const data = new Uint8Array(await fs.readFile(full));
226
+ yield { audio: audioRefFromBytes(data, `file://${full}`), path: full };
227
+ }
228
+ }
229
+ async process() {
230
+ const collected = [];
231
+ const paths = [];
232
+ for await (const item of this._load()) {
233
+ collected.push(item.audio);
234
+ paths.push(String(item.path ?? ""));
235
+ }
236
+ return { audio: collected[0] ?? {}, path: paths[0] ?? "", audios: collected };
237
+ }
238
+ async *genProcess() {
239
+ const collected = [];
240
+ for await (const item of this._load()) {
241
+ collected.push(item.audio);
242
+ yield item;
243
+ }
244
+ yield { audios: collected };
245
+ }
246
+ }
247
+ __decorate([
248
+ prop({
249
+ type: "str",
250
+ default: "",
251
+ title: "Folder",
252
+ description: "Folder to scan for audio files"
253
+ })
254
+ ], LoadAudioFolderNode.prototype, "folder", void 0);
255
+ __decorate([
256
+ prop({
257
+ type: "bool",
258
+ default: false,
259
+ title: "Include Subdirectories",
260
+ description: "Include audio in subfolders"
261
+ })
262
+ ], LoadAudioFolderNode.prototype, "include_subdirectories", void 0);
263
+ __decorate([
264
+ prop({
265
+ type: "list[str]",
266
+ default: DEFAULT_AUDIO_EXTENSIONS,
267
+ title: "Extensions",
268
+ description: "Audio file extensions to include"
269
+ })
270
+ ], LoadAudioFolderNode.prototype, "extensions", void 0);
271
+ export class SaveAudioNode extends BaseNode {
272
+ static nodeType = "nodetool.audio.SaveAudio";
273
+ static platforms = NODE_ONLY;
274
+ static title = "Save Audio Asset";
275
+ static description = "Save an audio file to a specified asset folder.\n audio, folder, name";
276
+ static metadataOutputTypes = {
277
+ output: "audio"
278
+ };
279
+ static inlineFields = [];
280
+ static inputFields = ["audio"];
281
+ async process() {
282
+ const audio = this.audio;
283
+ const folder = resolveFolderPath(this.folder) || ".";
284
+ const name = dateName(String(this.name || "audio.wav"));
285
+ const fs = await loadNodeFsPromises();
286
+ const path = await loadNodePath();
287
+ const full = path.resolve(folder, name);
288
+ await fs.mkdir(path.dirname(full), { recursive: true });
289
+ await fs.writeFile(full, audioBytes(audio));
290
+ return { output: audioRefFromBytes(audioBytes(audio), `file://${full}`) };
291
+ }
292
+ }
293
+ __decorate([
294
+ prop({
295
+ type: "audio",
296
+ default: {
297
+ type: "audio",
298
+ uri: "",
299
+ asset_id: null,
300
+ data: null,
301
+ metadata: null
302
+ },
303
+ title: "Audio"
304
+ })
305
+ ], SaveAudioNode.prototype, "audio", void 0);
306
+ __decorate([
307
+ prop({
308
+ type: "folder",
309
+ default: {
310
+ type: "folder",
311
+ uri: "",
312
+ asset_id: null,
313
+ data: null,
314
+ metadata: null
315
+ },
316
+ title: "Folder",
317
+ description: "The asset folder to save the audio file to. "
318
+ })
319
+ ], SaveAudioNode.prototype, "folder", void 0);
320
+ __decorate([
321
+ prop({
322
+ type: "str",
323
+ default: "%Y-%m-%d-%H-%M-%S.wav",
324
+ title: "Name",
325
+ description: "\n The name of the audio file.\n You can use time and date variables to create unique names:\n %Y - Year\n %m - Month\n %d - Day\n %H - Hour\n %M - Minute\n %S - Second\n "
326
+ })
327
+ ], SaveAudioNode.prototype, "name", void 0);
328
+ export class SaveAudioFileNode extends BaseNode {
329
+ static nodeType = "nodetool.audio.SaveAudioFile";
330
+ static platforms = NODE_ONLY;
331
+ static title = "Save Audio File";
332
+ static description = "Write an audio file to disk.\n audio, output, save, file\n\n The filename can include time and date variables:\n %Y - Year, %m - Month, %d - Day\n %H - Hour, %M - Minute, %S - Second\n\n Supported formats: mp3, wav, ogg, flac, aac, m4a";
333
+ static metadataOutputTypes = {
334
+ output: "audio"
335
+ };
336
+ static inlineFields = ["save_to_workspace"];
337
+ static inputFields = ["audio"];
338
+ async process(context) {
339
+ const audio = this.audio;
340
+ const p = await writeSavedFile({
341
+ folder: this.folder,
342
+ filename: dateName(String(this.filename || "audio.wav")),
343
+ saveToWorkspace: this.save_to_workspace,
344
+ workspace: context?.workspace,
345
+ workspaceDir: context?.workspaceDir,
346
+ bytes: audioBytes(audio)
347
+ });
348
+ return { output: p };
349
+ }
350
+ }
351
+ __decorate([
352
+ prop({
353
+ type: "audio",
354
+ default: {
355
+ type: "audio",
356
+ uri: "",
357
+ asset_id: null,
358
+ data: null,
359
+ metadata: null
360
+ },
361
+ title: "Audio",
362
+ description: "The audio to save"
363
+ })
364
+ ], SaveAudioFileNode.prototype, "audio", void 0);
365
+ __decorate([
366
+ prop({
367
+ type: "bool",
368
+ default: true,
369
+ title: SAVE_TO_WORKSPACE_TITLE,
370
+ description: SAVE_TO_WORKSPACE_DESCRIPTION
371
+ })
372
+ ], SaveAudioFileNode.prototype, "save_to_workspace", void 0);
373
+ __decorate([
374
+ prop({
375
+ type: "str",
376
+ default: "",
377
+ title: "Folder",
378
+ description: "Folder where the file will be saved",
379
+ json_schema_extra: VISIBLE_WHEN_NOT_SAVING_TO_WORKSPACE
380
+ })
381
+ ], SaveAudioFileNode.prototype, "folder", void 0);
382
+ __decorate([
383
+ prop({
384
+ type: "str",
385
+ default: "",
386
+ title: "Filename",
387
+ description: "\n Name of the file to save.\n You can use time and date variables to create unique names:\n %Y - Year\n %m - Month\n %d - Day\n %H - Hour\n %M - Minute\n %S - Second\n "
388
+ })
389
+ ], SaveAudioFileNode.prototype, "filename", void 0);
390
+ export class NormalizeAudioNode extends BaseNode {
391
+ static nodeType = "nodetool.audio.Normalize";
392
+ static title = "Normalize";
393
+ static description = "Normalizes the volume of an audio file.\n audio, fix, dynamics, volume";
394
+ static metadataOutputTypes = {
395
+ output: "audio"
396
+ };
397
+ static inlineFields = [];
398
+ static inputFields = ["audio"];
399
+ async process(context) {
400
+ const bytes = await requireAudioBytes(this.audio, context);
401
+ const wav = await decodeAudioToWav(bytes);
402
+ if (wav.samples.length === 0) {
403
+ return {
404
+ output: audioRefFromWav(encodeWav(wav.samples, wav.sampleRate, wav.numChannels))
405
+ };
406
+ }
407
+ let peak = 0;
408
+ for (const sample of wav.samples)
409
+ peak = Math.max(peak, Math.abs(sample));
410
+ if (peak === 0) {
411
+ return {
412
+ output: audioRefFromWav(encodeWav(wav.samples, wav.sampleRate, wav.numChannels))
413
+ };
414
+ }
415
+ const gain = 1 / peak;
416
+ const normalized = new Float32Array(wav.samples.length);
417
+ for (let i = 0; i < wav.samples.length; i += 1) {
418
+ normalized[i] = wav.samples[i] * gain;
419
+ }
420
+ return {
421
+ output: audioRefFromWav(encodeWav(normalized, wav.sampleRate, wav.numChannels))
422
+ };
423
+ }
424
+ }
425
+ __decorate([
426
+ prop({
427
+ type: "audio",
428
+ default: {
429
+ type: "audio",
430
+ uri: "",
431
+ asset_id: null,
432
+ data: null,
433
+ metadata: null
434
+ },
435
+ title: "Audio",
436
+ description: "The audio file to normalize."
437
+ })
438
+ ], NormalizeAudioNode.prototype, "audio", void 0);
439
+ export class OverlayAudioNode extends BaseNode {
440
+ static nodeType = "nodetool.audio.OverlayAudio";
441
+ static title = "Overlay Audio";
442
+ static description = "Overlays two audio files together.\n audio, edit, transform";
443
+ static metadataOutputTypes = {
444
+ output: "audio"
445
+ };
446
+ static inlineFields = [];
447
+ static inputFields = ["a", "b"];
448
+ async process(context) {
449
+ const aBytes = await audioBytesAsync(this.a, context);
450
+ const bBytes = await audioBytesAsync(this.b, context);
451
+ const [aw, bw] = await Promise.all([
452
+ decodeAudioToWav(aBytes),
453
+ decodeAudioToWav(bBytes)
454
+ ]);
455
+ // Matching layouts can be summed directly. encodeWav clips to [-1, 1].
456
+ if (aw.sampleRate === bw.sampleRate &&
457
+ aw.numChannels === bw.numChannels) {
458
+ const len = Math.max(aw.samples.length, bw.samples.length);
459
+ const mixed = new Float32Array(len);
460
+ for (let i = 0; i < len; i += 1) {
461
+ mixed[i] = (aw.samples[i] ?? 0) + (bw.samples[i] ?? 0);
462
+ }
463
+ return {
464
+ output: audioRefFromWav(encodeWav(mixed, aw.sampleRate, aw.numChannels))
465
+ };
466
+ }
467
+ const Context = await loadOfflineAudioContext();
468
+ if (!Context) {
469
+ throw new Error("Overlay Audio requires matching sample rates and channel counts when WebAudio is unavailable.");
470
+ }
471
+ const sampleRate = Math.max(aw.sampleRate, bw.sampleRate);
472
+ const channels = Math.max(aw.numChannels, bw.numChannels);
473
+ const duration = Math.max(wavFrameCount(aw) / aw.sampleRate, wavFrameCount(bw) / bw.sampleRate);
474
+ const frames = Math.ceil(duration * sampleRate);
475
+ const offline = new Context(channels, frames, sampleRate);
476
+ for (const wav of [aw, bw]) {
477
+ const buffer = offline.createBuffer(wav.numChannels, wavFrameCount(wav), wav.sampleRate);
478
+ for (let channel = 0; channel < wav.numChannels; channel++) {
479
+ const target = buffer.getChannelData(channel);
480
+ for (let frame = 0; frame < target.length; frame++) {
481
+ target[frame] = wav.samples[frame * wav.numChannels + channel];
482
+ }
483
+ }
484
+ const source = offline.createBufferSource();
485
+ source.buffer = buffer;
486
+ source.connect(offline.destination);
487
+ source.start();
488
+ }
489
+ const rendered = await offline.startRendering();
490
+ const mixed = new Float32Array(frames * channels);
491
+ for (let channel = 0; channel < channels; channel++) {
492
+ const samples = rendered.getChannelData(channel);
493
+ for (let frame = 0; frame < frames; frame++)
494
+ mixed[frame * channels + channel] = samples[frame];
495
+ }
496
+ return { output: audioRefFromWav(encodeWav(mixed, sampleRate, channels)) };
497
+ }
498
+ }
499
+ __decorate([
500
+ prop({
501
+ type: "audio",
502
+ default: {
503
+ type: "audio",
504
+ uri: "",
505
+ asset_id: null,
506
+ data: null,
507
+ metadata: null
508
+ },
509
+ title: "A",
510
+ description: "The first audio file."
511
+ })
512
+ ], OverlayAudioNode.prototype, "a", void 0);
513
+ __decorate([
514
+ prop({
515
+ type: "audio",
516
+ default: {
517
+ type: "audio",
518
+ uri: "",
519
+ asset_id: null,
520
+ data: null,
521
+ metadata: null
522
+ },
523
+ title: "B",
524
+ description: "The second audio file."
525
+ })
526
+ ], OverlayAudioNode.prototype, "b", void 0);
527
+ export class RemoveSilenceNode extends BaseNode {
528
+ static nodeType = "nodetool.audio.RemoveSilence";
529
+ static title = "Remove Silence";
530
+ static description = "Removes or shortens silence in an audio file with smooth transitions.\n audio, edit, clean";
531
+ static metadataOutputTypes = {
532
+ output: "audio"
533
+ };
534
+ static inlineFields = [];
535
+ static inputFields = ["audio"];
536
+ async process(context) {
537
+ const bytes = await audioBytesAsync(this.audio, context);
538
+ const wav = parseWavBytes(bytes);
539
+ if (!wav || wav.samples.length === 0) {
540
+ return { output: audioRefFromBytes(bytes) };
541
+ }
542
+ const { sampleRate, numChannels } = wav;
543
+ const frames = wavFrameCount(wav);
544
+ const thresholdDb = this.threshold;
545
+ const minLenMs = Math.max(0, this.min_length);
546
+ const reduction = Math.min(1, Math.max(0, this.reduction_factor));
547
+ const minGapMs = Math.max(0, this.min_silence_between_parts);
548
+ const crossfadeMs = Math.max(0, this.crossfade);
549
+ const thresholdLin = Math.pow(10, thresholdDb / 20);
550
+ const minLenFrames = Math.round((minLenMs / 1000) * sampleRate);
551
+ const minGapFrames = Math.round((minGapMs / 1000) * sampleRate);
552
+ const crossfadeFrames = Math.round((crossfadeMs / 1000) * sampleRate);
553
+ const isSilent = (f) => {
554
+ let amp = 0;
555
+ for (let ch = 0; ch < numChannels; ch++) {
556
+ amp = Math.max(amp, Math.abs(wav.samples[f * numChannels + ch]));
557
+ }
558
+ return amp < thresholdLin;
559
+ };
560
+ // Collect the source frame indices to keep, shortening long silences.
561
+ const kept = [];
562
+ let f = 0;
563
+ while (f < frames) {
564
+ if (!isSilent(f)) {
565
+ kept.push(f);
566
+ f += 1;
567
+ continue;
568
+ }
569
+ const runStart = f;
570
+ while (f < frames && isSilent(f))
571
+ f += 1;
572
+ const runLen = f - runStart;
573
+ if (runLen < minLenFrames) {
574
+ for (let k = runStart; k < f; k++)
575
+ kept.push(k);
576
+ }
577
+ else {
578
+ let keep = Math.round(runLen * (1 - reduction));
579
+ // Preserve a minimum gap between non-silent segments.
580
+ if (kept.length > 0 && f < frames)
581
+ keep = Math.max(keep, minGapFrames);
582
+ keep = Math.min(keep, runLen);
583
+ for (let k = 0; k < keep; k++)
584
+ kept.push(runStart + k);
585
+ }
586
+ }
587
+ if (kept.length === frames) {
588
+ return {
589
+ output: audioRefFromWav(encodeWav(wav.samples, sampleRate, numChannels))
590
+ };
591
+ }
592
+ const out = new Float32Array(kept.length * numChannels);
593
+ for (let i = 0; i < kept.length; i++) {
594
+ const src = kept[i];
595
+ for (let ch = 0; ch < numChannels; ch++) {
596
+ out[i * numChannels + ch] = wav.samples[src * numChannels + ch];
597
+ }
598
+ }
599
+ // Smooth the splices: short fades on either side of each discontinuity
600
+ // (where consecutive kept frames are not adjacent in the source) to avoid
601
+ // audible clicks.
602
+ if (crossfadeFrames > 0) {
603
+ for (let i = 1; i < kept.length; i++) {
604
+ if (kept[i] === kept[i - 1] + 1)
605
+ continue;
606
+ for (let k = 0; k < crossfadeFrames; k++) {
607
+ const g = (k + 1) / (crossfadeFrames + 1);
608
+ const before = i - 1 - k;
609
+ const after = i + k;
610
+ if (before >= 0) {
611
+ for (let ch = 0; ch < numChannels; ch++) {
612
+ out[before * numChannels + ch] *= g;
613
+ }
614
+ }
615
+ if (after < kept.length) {
616
+ for (let ch = 0; ch < numChannels; ch++) {
617
+ out[after * numChannels + ch] *= g;
618
+ }
619
+ }
620
+ }
621
+ }
622
+ }
623
+ return {
624
+ output: audioRefFromWav(encodeWav(out, sampleRate, numChannels))
625
+ };
626
+ }
627
+ }
628
+ __decorate([
629
+ prop({
630
+ type: "audio",
631
+ default: {
632
+ type: "audio",
633
+ uri: "",
634
+ asset_id: null,
635
+ data: null,
636
+ metadata: null
637
+ },
638
+ title: "Audio",
639
+ description: "The audio file to process."
640
+ })
641
+ ], RemoveSilenceNode.prototype, "audio", void 0);
642
+ __decorate([
643
+ prop({
644
+ type: "int",
645
+ default: 200,
646
+ title: "Min Length",
647
+ description: "Minimum length of silence to be processed (in milliseconds).",
648
+ min: 0,
649
+ max: 10000
650
+ })
651
+ ], RemoveSilenceNode.prototype, "min_length", void 0);
652
+ __decorate([
653
+ prop({
654
+ type: "int",
655
+ default: -40,
656
+ title: "Threshold",
657
+ description: "Silence threshold in dB (relative to full scale). Higher values detect more silence.",
658
+ min: -60,
659
+ max: 0
660
+ })
661
+ ], RemoveSilenceNode.prototype, "threshold", void 0);
662
+ __decorate([
663
+ prop({
664
+ type: "float",
665
+ default: 1,
666
+ title: "Reduction Factor",
667
+ description: "Factor to reduce silent parts (0.0 to 1.0). 0.0 keeps silence as is, 1.0 removes it completely.",
668
+ min: 0,
669
+ max: 1
670
+ })
671
+ ], RemoveSilenceNode.prototype, "reduction_factor", void 0);
672
+ __decorate([
673
+ prop({
674
+ type: "int",
675
+ default: 10,
676
+ title: "Crossfade",
677
+ description: "Duration of crossfade in milliseconds to apply between segments for smooth transitions.",
678
+ min: 0,
679
+ max: 50
680
+ })
681
+ ], RemoveSilenceNode.prototype, "crossfade", void 0);
682
+ __decorate([
683
+ prop({
684
+ type: "int",
685
+ default: 100,
686
+ title: "Min Silence Between Parts",
687
+ description: "Minimum silence duration in milliseconds to maintain between non-silent segments",
688
+ min: 0,
689
+ max: 500
690
+ })
691
+ ], RemoveSilenceNode.prototype, "min_silence_between_parts", void 0);
692
+ export class SliceAudioNode extends BaseNode {
693
+ static nodeType = "nodetool.audio.SliceAudio";
694
+ static title = "Slice Audio";
695
+ static description = "Extracts a section of an audio file.\n audio, edit, trim";
696
+ static metadataOutputTypes = {
697
+ output: "audio"
698
+ };
699
+ static inlineFields = [];
700
+ static inputFields = ["audio"];
701
+ async process(context) {
702
+ const bytes = await requireAudioBytes(this.audio, context);
703
+ const start = Math.max(0, this.start);
704
+ const end = this.end;
705
+ const wav = await decodeAudioToWav(bytes);
706
+ const { sampleRate, numChannels } = wav;
707
+ const frames = wavFrameCount(wav);
708
+ const startFrame = Math.min(frames, Math.round(start * sampleRate));
709
+ const endFrame = end <= 0 ? frames : Math.min(frames, Math.round(end * sampleRate));
710
+ const sliced = wav.samples.slice(startFrame * numChannels, Math.max(startFrame, endFrame) * numChannels);
711
+ return {
712
+ output: audioRefFromWav(encodeWav(sliced, sampleRate, numChannels))
713
+ };
714
+ }
715
+ }
716
+ __decorate([
717
+ prop({
718
+ type: "audio",
719
+ default: {
720
+ type: "audio",
721
+ uri: "",
722
+ asset_id: null,
723
+ data: null,
724
+ metadata: null
725
+ },
726
+ title: "Audio",
727
+ description: "The audio file."
728
+ })
729
+ ], SliceAudioNode.prototype, "audio", void 0);
730
+ __decorate([
731
+ prop({
732
+ type: "float",
733
+ default: 0,
734
+ title: "Start",
735
+ description: "The start time in seconds.",
736
+ min: 0
737
+ })
738
+ ], SliceAudioNode.prototype, "start", void 0);
739
+ __decorate([
740
+ prop({
741
+ type: "float",
742
+ default: 1,
743
+ title: "End",
744
+ description: "The end time in seconds. 0 or less slices to the end.",
745
+ min: 0
746
+ })
747
+ ], SliceAudioNode.prototype, "end", void 0);
748
+ export class MonoToStereoNode extends BaseNode {
749
+ static nodeType = "nodetool.audio.MonoToStereo";
750
+ static title = "Mono To Stereo";
751
+ static description = "Converts a mono audio signal to stereo.\n audio, convert, channels";
752
+ static metadataOutputTypes = {
753
+ output: "audio"
754
+ };
755
+ static inlineFields = [];
756
+ static inputFields = ["audio"];
757
+ async process(context) {
758
+ const bytes = await audioBytesAsync(this.audio, context);
759
+ const wav = await decodeAudioToWav(bytes);
760
+ // Already stereo (or more): pass through unchanged.
761
+ if (wav.numChannels >= 2) {
762
+ return {
763
+ output: audioRefFromWav(encodeWav(wav.samples, wav.sampleRate, wav.numChannels))
764
+ };
765
+ }
766
+ const frames = wav.samples.length;
767
+ const out = new Float32Array(frames * 2);
768
+ for (let i = 0; i < frames; i += 1) {
769
+ out[i * 2] = wav.samples[i];
770
+ out[i * 2 + 1] = wav.samples[i];
771
+ }
772
+ return { output: audioRefFromWav(encodeWav(out, wav.sampleRate, 2)) };
773
+ }
774
+ }
775
+ __decorate([
776
+ prop({
777
+ type: "audio",
778
+ default: {
779
+ type: "audio",
780
+ uri: "",
781
+ asset_id: null,
782
+ data: null,
783
+ metadata: null
784
+ },
785
+ title: "Audio",
786
+ description: "The mono audio file to convert."
787
+ })
788
+ ], MonoToStereoNode.prototype, "audio", void 0);
789
+ export class StereoToMonoNode extends BaseNode {
790
+ static nodeType = "nodetool.audio.StereoToMono";
791
+ static title = "Stereo To Mono";
792
+ static description = "Converts a stereo audio signal to mono.\n audio, convert, channels";
793
+ static metadataOutputTypes = {
794
+ output: "audio"
795
+ };
796
+ static inlineFields = [];
797
+ static inputFields = ["audio"];
798
+ async process(context) {
799
+ const bytes = await audioBytesAsync(this.audio, context);
800
+ const method = this.method;
801
+ const wav = parseWavBytes(bytes);
802
+ if (!wav) {
803
+ // Non-WAV fallback: keep every other byte.
804
+ const out = new Uint8Array(Math.ceil(bytes.length / 2));
805
+ for (let i = 0, j = 0; i < bytes.length; i += 2, j += 1) {
806
+ out[j] = bytes[i];
807
+ }
808
+ return { output: audioRefFromBytes(out) };
809
+ }
810
+ const numChannels = wav.numChannels;
811
+ // Already mono: pass through unchanged.
812
+ if (numChannels <= 1) {
813
+ return {
814
+ output: audioRefFromWav(encodeWav(wav.samples, wav.sampleRate, 1))
815
+ };
816
+ }
817
+ const frames = wavFrameCount(wav);
818
+ const out = new Float32Array(frames);
819
+ for (let f = 0; f < frames; f += 1) {
820
+ const base = f * numChannels;
821
+ if (method === "left") {
822
+ out[f] = wav.samples[base];
823
+ }
824
+ else if (method === "right") {
825
+ out[f] = wav.samples[base + 1];
826
+ }
827
+ else {
828
+ let sum = 0;
829
+ for (let ch = 0; ch < numChannels; ch++)
830
+ sum += wav.samples[base + ch];
831
+ out[f] = sum / numChannels;
832
+ }
833
+ }
834
+ return { output: audioRefFromWav(encodeWav(out, wav.sampleRate, 1)) };
835
+ }
836
+ }
837
+ __decorate([
838
+ prop({
839
+ type: "audio",
840
+ default: {
841
+ type: "audio",
842
+ uri: "",
843
+ asset_id: null,
844
+ data: null,
845
+ metadata: null
846
+ },
847
+ title: "Audio",
848
+ description: "The stereo audio file to convert."
849
+ })
850
+ ], StereoToMonoNode.prototype, "audio", void 0);
851
+ __decorate([
852
+ prop({
853
+ type: "str",
854
+ default: "average",
855
+ title: "Method",
856
+ description: "Method to use for conversion: 'average', 'left', or 'right'."
857
+ })
858
+ ], StereoToMonoNode.prototype, "method", void 0);
859
+ export class ReverseAudioNode extends BaseNode {
860
+ static nodeType = "nodetool.audio.Reverse";
861
+ static title = "Reverse";
862
+ static description = "Reverses an audio file.\n audio, edit, transform";
863
+ static metadataOutputTypes = {
864
+ output: "audio"
865
+ };
866
+ static inlineFields = [];
867
+ static inputFields = ["audio"];
868
+ async process(context) {
869
+ const bytes = await audioBytesAsync(this.audio, context);
870
+ const wav = parseWavBytes(bytes);
871
+ if (!wav) {
872
+ // Non-WAV fallback: reverse raw bytes.
873
+ return { output: audioRefFromBytes(new Uint8Array([...bytes].reverse())) };
874
+ }
875
+ const { sampleRate, numChannels } = wav;
876
+ const frames = wavFrameCount(wav);
877
+ const out = new Float32Array(wav.samples.length);
878
+ for (let f = 0; f < frames; f += 1) {
879
+ const src = frames - 1 - f;
880
+ for (let ch = 0; ch < numChannels; ch++) {
881
+ out[f * numChannels + ch] = wav.samples[src * numChannels + ch];
882
+ }
883
+ }
884
+ return {
885
+ output: audioRefFromWav(encodeWav(out, sampleRate, numChannels))
886
+ };
887
+ }
888
+ }
889
+ __decorate([
890
+ prop({
891
+ type: "audio",
892
+ default: {
893
+ type: "audio",
894
+ uri: "",
895
+ asset_id: null,
896
+ data: null,
897
+ metadata: null
898
+ },
899
+ title: "Audio",
900
+ description: "The audio file to reverse."
901
+ })
902
+ ], ReverseAudioNode.prototype, "audio", void 0);
903
+ export class FadeInAudioNode extends BaseNode {
904
+ static nodeType = "nodetool.audio.FadeIn";
905
+ static title = "Fade In";
906
+ static description = "Applies a fade-in effect to the beginning of an audio file.\n audio, edit, transition";
907
+ static metadataOutputTypes = {
908
+ output: "audio"
909
+ };
910
+ static inlineFields = [];
911
+ static inputFields = ["audio"];
912
+ async process(context) {
913
+ const bytes = await requireAudioBytes(this.audio, context);
914
+ const duration = Math.max(0, this.duration);
915
+ const wav = await decodeAudioToWav(bytes);
916
+ const { sampleRate, numChannels } = wav;
917
+ const frames = wavFrameCount(wav);
918
+ const fadeFrames = Math.min(frames, Math.round(duration * sampleRate));
919
+ const out = new Float32Array(wav.samples);
920
+ for (let f = 0; f < fadeFrames; f += 1) {
921
+ const gain = fadeFrames > 0 ? f / fadeFrames : 1;
922
+ for (let ch = 0; ch < numChannels; ch++) {
923
+ out[f * numChannels + ch] *= gain;
924
+ }
925
+ }
926
+ return {
927
+ output: audioRefFromWav(encodeWav(out, sampleRate, numChannels))
928
+ };
929
+ }
930
+ }
931
+ __decorate([
932
+ prop({
933
+ type: "audio",
934
+ default: {
935
+ type: "audio",
936
+ uri: "",
937
+ asset_id: null,
938
+ data: null,
939
+ metadata: null
940
+ },
941
+ title: "Audio",
942
+ description: "The audio file to apply fade-in to."
943
+ })
944
+ ], FadeInAudioNode.prototype, "audio", void 0);
945
+ __decorate([
946
+ prop({
947
+ type: "float",
948
+ default: 1,
949
+ title: "Duration",
950
+ description: "Duration of the fade-in effect in seconds.",
951
+ min: 0
952
+ })
953
+ ], FadeInAudioNode.prototype, "duration", void 0);
954
+ export class FadeOutAudioNode extends BaseNode {
955
+ static nodeType = "nodetool.audio.FadeOut";
956
+ static title = "Fade Out";
957
+ static description = "Applies a fade-out effect to the end of an audio file.\n audio, edit, transition";
958
+ static metadataOutputTypes = {
959
+ output: "audio"
960
+ };
961
+ static inlineFields = [];
962
+ static inputFields = ["audio"];
963
+ async process(context) {
964
+ const bytes = await requireAudioBytes(this.audio, context);
965
+ const duration = Math.max(0, this.duration);
966
+ const wav = await decodeAudioToWav(bytes);
967
+ const { sampleRate, numChannels } = wav;
968
+ const frames = wavFrameCount(wav);
969
+ const fadeFrames = Math.min(frames, Math.round(duration * sampleRate));
970
+ const out = new Float32Array(wav.samples);
971
+ const startFrame = frames - fadeFrames;
972
+ for (let f = startFrame; f < frames; f += 1) {
973
+ const gain = fadeFrames > 0 ? (frames - f) / fadeFrames : 1;
974
+ for (let ch = 0; ch < numChannels; ch++) {
975
+ out[f * numChannels + ch] *= gain;
976
+ }
977
+ }
978
+ return {
979
+ output: audioRefFromWav(encodeWav(out, sampleRate, numChannels))
980
+ };
981
+ }
982
+ }
983
+ __decorate([
984
+ prop({
985
+ type: "audio",
986
+ default: {
987
+ type: "audio",
988
+ uri: "",
989
+ asset_id: null,
990
+ data: null,
991
+ metadata: null
992
+ },
993
+ title: "Audio",
994
+ description: "The audio file to apply fade-out to."
995
+ })
996
+ ], FadeOutAudioNode.prototype, "audio", void 0);
997
+ __decorate([
998
+ prop({
999
+ type: "float",
1000
+ default: 1,
1001
+ title: "Duration",
1002
+ description: "Duration of the fade-out effect in seconds.",
1003
+ min: 0
1004
+ })
1005
+ ], FadeOutAudioNode.prototype, "duration", void 0);
1006
+ export class RepeatAudioNode extends BaseNode {
1007
+ static nodeType = "nodetool.audio.Repeat";
1008
+ static title = "Repeat";
1009
+ static description = "Loops an audio file a specified number of times.\n audio, edit, repeat";
1010
+ static metadataOutputTypes = {
1011
+ output: "audio"
1012
+ };
1013
+ static inlineFields = [];
1014
+ static inputFields = ["audio"];
1015
+ async process(context) {
1016
+ const bytes = await audioBytesAsync(this.audio, context);
1017
+ const count = Math.max(1, Math.floor(this.loops));
1018
+ const wav = parseWavBytes(bytes);
1019
+ if (!wav) {
1020
+ // Non-WAV fallback: repeat raw bytes.
1021
+ return {
1022
+ output: audioRefFromBytes(concatBytes(Array.from({ length: count }, () => bytes)))
1023
+ };
1024
+ }
1025
+ const out = new Float32Array(wav.samples.length * count);
1026
+ for (let r = 0; r < count; r += 1) {
1027
+ out.set(wav.samples, r * wav.samples.length);
1028
+ }
1029
+ return {
1030
+ output: audioRefFromWav(encodeWav(out, wav.sampleRate, wav.numChannels))
1031
+ };
1032
+ }
1033
+ }
1034
+ __decorate([
1035
+ prop({
1036
+ type: "audio",
1037
+ default: {
1038
+ type: "audio",
1039
+ uri: "",
1040
+ asset_id: null,
1041
+ data: null,
1042
+ metadata: null
1043
+ },
1044
+ title: "Audio",
1045
+ description: "The audio file to loop."
1046
+ })
1047
+ ], RepeatAudioNode.prototype, "audio", void 0);
1048
+ __decorate([
1049
+ prop({
1050
+ type: "int",
1051
+ default: 2,
1052
+ title: "Loops",
1053
+ description: "Number of times to loop the audio. Minimum 1 (plays once), maximum 100.",
1054
+ min: 1,
1055
+ max: 100
1056
+ })
1057
+ ], RepeatAudioNode.prototype, "loops", void 0);
1058
+ export class AudioMixerNode extends BaseNode {
1059
+ static nodeType = "nodetool.audio.AudioMixer";
1060
+ static body = "content_card";
1061
+ static title = "Audio Mixer";
1062
+ static description = "Mix multiple audio tracks together. Add tracks dynamically with the “add audio input” button; wire a Gain node upstream of any track that needs a different level.\n audio, mix, combine, blend, layer, add, overlay";
1063
+ static metadataOutputTypes = {
1064
+ output: "audio"
1065
+ };
1066
+ static inlineFields = [];
1067
+ static inputFields = [];
1068
+ static supportsDynamicInputs = true;
1069
+ async process(context) {
1070
+ const inputs = Array.from(this.dynamicProps.values()).filter((t) => isObjectLike(t));
1071
+ const tracks = (await Promise.all(inputs.map((t) => audioBytesAsync(t, context)))).filter((bytes) => bytes.length > 0);
1072
+ if (tracks.length === 0)
1073
+ return { output: audioRefFromBytes(new Uint8Array()) };
1074
+ // Decode every track to PCM (WAV directly, or mp3/flac/… via WebAudio).
1075
+ // Undecodable input throws instead of falling through to a meaningless
1076
+ // byte-level average.
1077
+ const wavs = await Promise.all(tracks.map((bytes) => decodeAudioToWav(bytes)));
1078
+ // Index-based mixing only lines up when sample rate and channel count
1079
+ // match across tracks; resampling is out of scope, so a mismatch is an
1080
+ // error rather than a silently distorted mix.
1081
+ const uniform = wavs.every((w) => w.sampleRate === wavs[0].sampleRate &&
1082
+ w.numChannels === wavs[0].numChannels);
1083
+ if (!uniform) {
1084
+ throw new Error("Audio Mixer requires all tracks to share the same sample rate and " +
1085
+ "channel count. Resample or convert the inputs to a common format " +
1086
+ "upstream before mixing.");
1087
+ }
1088
+ const len = Math.max(...wavs.map((w) => w.samples.length));
1089
+ const mixed = new Float32Array(len);
1090
+ for (let i = 0; i < len; i += 1) {
1091
+ let total = 0;
1092
+ for (const w of wavs)
1093
+ total += w.samples[i] ?? 0;
1094
+ mixed[i] = total / wavs.length;
1095
+ }
1096
+ return {
1097
+ output: audioRefFromWav(encodeWav(mixed, wavs[0].sampleRate, wavs[0].numChannels))
1098
+ };
1099
+ }
1100
+ }
1101
+ export class TrimAudioNode extends BaseNode {
1102
+ static nodeType = "nodetool.audio.Trim";
1103
+ static title = "Trim";
1104
+ static description = "Trim an audio file to a specified duration.\n audio, trim, cut";
1105
+ static metadataOutputTypes = {
1106
+ output: "audio"
1107
+ };
1108
+ static inlineFields = [];
1109
+ static inputFields = ["audio"];
1110
+ async process(context) {
1111
+ const bytes = await requireAudioBytes(this.audio, context);
1112
+ const start = Math.max(0, this.start);
1113
+ const end = Math.max(0, this.end);
1114
+ const wav = await decodeAudioToWav(bytes);
1115
+ const { sampleRate, numChannels } = wav;
1116
+ const frames = wavFrameCount(wav);
1117
+ // start/end are absolute times in seconds; end <= 0 means "to the end".
1118
+ const startFrame = Math.min(frames, Math.round(start * sampleRate));
1119
+ const endFrame = end > 0 ? Math.min(frames, Math.round(end * sampleRate)) : frames;
1120
+ const trimmed = wav.samples.slice(startFrame * numChannels, Math.max(startFrame, endFrame) * numChannels);
1121
+ return {
1122
+ output: audioRefFromWav(encodeWav(trimmed, sampleRate, numChannels))
1123
+ };
1124
+ }
1125
+ }
1126
+ __decorate([
1127
+ prop({
1128
+ type: "audio",
1129
+ default: {
1130
+ type: "audio",
1131
+ uri: "",
1132
+ asset_id: null,
1133
+ data: null,
1134
+ metadata: null
1135
+ },
1136
+ title: "Audio",
1137
+ description: "The audio file to trim."
1138
+ })
1139
+ ], TrimAudioNode.prototype, "audio", void 0);
1140
+ __decorate([
1141
+ prop({
1142
+ type: "float",
1143
+ default: 0,
1144
+ title: "Start",
1145
+ description: "The start time of the trimmed audio in seconds.",
1146
+ min: 0
1147
+ })
1148
+ ], TrimAudioNode.prototype, "start", void 0);
1149
+ __decorate([
1150
+ prop({
1151
+ type: "float",
1152
+ default: 0,
1153
+ title: "End",
1154
+ description: "The end time of the trimmed audio in seconds.",
1155
+ min: 0
1156
+ })
1157
+ ], TrimAudioNode.prototype, "end", void 0);
1158
+ export class CreateSilenceNode extends BaseNode {
1159
+ static nodeType = "nodetool.audio.CreateSilence";
1160
+ static title = "Create Silence";
1161
+ static description = "Creates a silent audio file with a specified duration.\n audio, silence, empty";
1162
+ static metadataOutputTypes = {
1163
+ output: "audio"
1164
+ };
1165
+ static inlineFields = [];
1166
+ static inputFields = [];
1167
+ async process() {
1168
+ const duration = Math.max(0, this.duration);
1169
+ const sampleRate = Math.max(1, Math.floor(this.sample_rate));
1170
+ const frames = Math.round(duration * sampleRate);
1171
+ return {
1172
+ output: audioRefFromWav(encodeWav(new Float32Array(frames), sampleRate, 1))
1173
+ };
1174
+ }
1175
+ }
1176
+ __decorate([
1177
+ prop({
1178
+ type: "float",
1179
+ default: 1,
1180
+ title: "Duration",
1181
+ description: "The duration of the silence in seconds.",
1182
+ min: 0
1183
+ })
1184
+ ], CreateSilenceNode.prototype, "duration", void 0);
1185
+ __decorate([
1186
+ prop({
1187
+ type: "int",
1188
+ default: 44100,
1189
+ title: "Sample Rate",
1190
+ description: "Sample rate of the generated silence in Hz.",
1191
+ min: 1
1192
+ })
1193
+ ], CreateSilenceNode.prototype, "sample_rate", void 0);
1194
+ export class ConcatAudioNode extends BaseNode {
1195
+ static nodeType = "nodetool.audio.Concat";
1196
+ static body = "content_card";
1197
+ static title = "Concatenate Audio";
1198
+ static description = "Concatenates audio files together. Add inputs dynamically with the “add audio input” button, or wire a list of audio into a single input.\n audio, edit, join, +";
1199
+ static metadataOutputTypes = {
1200
+ output: "audio"
1201
+ };
1202
+ static inlineFields = [];
1203
+ static inputFields = [];
1204
+ static supportsDynamicInputs = true;
1205
+ async process(context) {
1206
+ // Each dynamic input may be a single audio ref or a list<audio> from an
1207
+ // upstream loop/list node — flatten so list elements concatenate in order.
1208
+ const values = Array.from(this.dynamicProps.values()).flatMap((v) => Array.isArray(v) ? v : [v]);
1209
+ const parts = (await Promise.all(values.map((v) => audioBytesAsync(v, context)))).filter((b) => b.length > 0);
1210
+ return { output: await concatAudio(parts) };
1211
+ }
1212
+ }
1213
+ /**
1214
+ * Concatenate audio byte buffers. Every part is decoded to PCM (WAV directly,
1215
+ * or mp3/flac/… via WebAudio) and joined in sample space so the result is a
1216
+ * single valid WAV. Undecodable input throws rather than silently emitting an
1217
+ * unplayable byte concatenation, and mismatched layouts throw because joining
1218
+ * differing sample rates without resampling would distort the audio.
1219
+ */
1220
+ async function concatAudio(parts) {
1221
+ if (parts.length === 0)
1222
+ return audioRefFromBytes(new Uint8Array());
1223
+ const list = await Promise.all(parts.map((b) => decodeAudioToWav(b)));
1224
+ const uniform = list.every((w) => w.sampleRate === list[0].sampleRate &&
1225
+ w.numChannels === list[0].numChannels);
1226
+ if (!uniform) {
1227
+ throw new Error("Cannot concatenate audio with differing sample rates or channel " +
1228
+ "counts. Convert the inputs to a common format upstream before " +
1229
+ "joining.");
1230
+ }
1231
+ const total = list.reduce((s, w) => s + w.samples.length, 0);
1232
+ const out = new Float32Array(total);
1233
+ let pos = 0;
1234
+ for (const w of list) {
1235
+ out.set(w.samples, pos);
1236
+ pos += w.samples.length;
1237
+ }
1238
+ return audioRefFromWav(encodeWav(out, list[0].sampleRate, list[0].numChannels));
1239
+ }
1240
+ export class ConcatAudioListNode extends BaseNode {
1241
+ static nodeType = "nodetool.audio.ConcatList";
1242
+ static title = "Concatenate Audio List";
1243
+ static description = "Concatenates multiple audio files together in sequence.\n audio, edit, join, multiple, +";
1244
+ static metadataOutputTypes = {
1245
+ output: "audio"
1246
+ };
1247
+ static inlineFields = [];
1248
+ static inputFields = ["audio_files"];
1249
+ async process(context) {
1250
+ const audios = this.audio_files;
1251
+ const parts = (await Promise.all(audios.map((a) => audioBytesAsync(a, context)))).filter((b) => b.length > 0);
1252
+ return { output: await concatAudio(parts) };
1253
+ }
1254
+ }
1255
+ __decorate([
1256
+ prop({
1257
+ type: "list[audio]",
1258
+ default: [],
1259
+ title: "Audio Files",
1260
+ description: "List of audio files to concatenate in sequence."
1261
+ })
1262
+ ], ConcatAudioListNode.prototype, "audio_files", void 0);
1263
+ export class TextToSpeechNode extends BaseNode {
1264
+ static nodeType = "nodetool.audio.TextToSpeech";
1265
+ static body = "content_card";
1266
+ static title = "Text To Speech";
1267
+ static description = "Generate speech audio from text using any supported TTS provider. Automatically routes to the appropriate backend (OpenAI, HuggingFace, MLX).\n audio, generation, AI, text-to-speech, tts, voice";
1268
+ static metadataOutputTypes = {
1269
+ audio: "audio",
1270
+ chunk: "chunk"
1271
+ };
1272
+ static inlineFields = ["text"];
1273
+ static inputFields = ["text", "reference_audio"];
1274
+ static autoSaveAsset = true;
1275
+ static inputMode = "buffered";
1276
+ static outputCorrelation = {
1277
+ audio: { kind: "single", source: "__execution__" },
1278
+ // `chunk` is declared on the output schema but the current process()
1279
+ // accumulates and returns only `audio`. PR 1 classifies it as single
1280
+ // (aspirational) per the design's stale-chunk-port guidance; a follow-up
1281
+ // either makes the node stream real chunks or removes the handle.
1282
+ chunk: { kind: "single", source: "__execution__" }
1283
+ };
1284
+ async process(context) {
1285
+ const text = this.text;
1286
+ const { providerId, modelId } = getModelConfig(this.serialize());
1287
+ const modelObj = this.model;
1288
+ const explicitVoice = isString(modelObj.selected_voice)
1289
+ ? modelObj.selected_voice
1290
+ : "";
1291
+ const voiceList = Array.isArray(modelObj.voices)
1292
+ ? modelObj.voices
1293
+ : [];
1294
+ const capabilities = new Set(Array.isArray(modelObj.capabilities)
1295
+ ? modelObj.capabilities.filter(isString)
1296
+ : []);
1297
+ const voice = explicitVoice || voiceList[0] || "";
1298
+ if (hasProviderSupport(context, providerId, modelId)) {
1299
+ const params = {
1300
+ text,
1301
+ voice,
1302
+ speed: this.speed
1303
+ };
1304
+ let hasReferenceAudio = false;
1305
+ if (capabilities.has("voice_cloning")) {
1306
+ const referenceAudio = await audioBytesAsync(this.reference_audio, context);
1307
+ if (referenceAudio.length > 0) {
1308
+ params.reference_audio = referenceAudio;
1309
+ hasReferenceAudio = true;
1310
+ }
1311
+ }
1312
+ if (modelObj.requires_reference_text === true) {
1313
+ if (!hasReferenceAudio) {
1314
+ throw new Error(`${modelId} requires reference audio for voice cloning.`);
1315
+ }
1316
+ if (!isNonEmptyString(this.reference_text)) {
1317
+ throw new Error(`${modelId} requires an exact transcript of the reference audio.`);
1318
+ }
1319
+ }
1320
+ if (capabilities.has("reference_transcript") &&
1321
+ isNonEmptyString(this.reference_text)) {
1322
+ params.reference_text = this.reference_text;
1323
+ }
1324
+ if (capabilities.has("language_selection") &&
1325
+ isNonEmptyString(this.language)) {
1326
+ params.language = this.language;
1327
+ }
1328
+ if ((capabilities.has("voice_design") ||
1329
+ capabilities.has("instruction_control")) &&
1330
+ isNonEmptyString(this.instructions)) {
1331
+ params.instructions = this.instructions;
1332
+ }
1333
+ // Providers that stream raw PCM (OpenAI, Together, Replicate, ElevenLabs…)
1334
+ // are wrapped into a WAV. Providers that return an encoded audio file
1335
+ // (FAL, KIE) are consumed via the encoded path below.
1336
+ if (await context.providerSupportsStreamingTTS(providerId)) {
1337
+ const chunks = [];
1338
+ let sampleRate = 24000;
1339
+ for await (const item of context.streamProviderPrediction({
1340
+ provider: providerId,
1341
+ capability: "text_to_speech",
1342
+ model: modelId,
1343
+ params
1344
+ })) {
1345
+ const piece = item;
1346
+ if (isPositiveNumber(piece.sampleRate)) {
1347
+ sampleRate = piece.sampleRate;
1348
+ }
1349
+ if (piece.samples instanceof Int16Array) {
1350
+ chunks.push(new Uint8Array(piece.samples.buffer.slice(piece.samples.byteOffset, piece.samples.byteOffset + piece.samples.byteLength)));
1351
+ }
1352
+ }
1353
+ const wav = encodePcm16Wav(concatBytes(chunks), sampleRate, 1);
1354
+ return { audio: audioRefFromWav(wav) };
1355
+ }
1356
+ const encoded = await context.textToSpeechEncoded({
1357
+ provider: providerId,
1358
+ capability: "text_to_speech",
1359
+ model: modelId,
1360
+ params
1361
+ });
1362
+ if (encoded?.data && encoded.data.length > 0) {
1363
+ return { audio: audioRefFromBytes(encoded.data) };
1364
+ }
1365
+ throw new Error(`Text To Speech produced no audio for provider "${providerId}" / ` +
1366
+ `model "${modelId}".`);
1367
+ }
1368
+ throw new Error(`Text To Speech requires a TTS provider; no provider available for ` +
1369
+ `provider "${providerId}" / model "${modelId}".`);
1370
+ }
1371
+ }
1372
+ __decorate([
1373
+ prop({
1374
+ type: "tts_model",
1375
+ default: {
1376
+ type: "tts_model",
1377
+ provider: "openai",
1378
+ id: "tts-1",
1379
+ name: "TTS 1",
1380
+ path: null,
1381
+ voices: ["alloy", "echo", "fable", "onyx", "nova", "shimmer"],
1382
+ selected_voice: "alloy",
1383
+ capabilities: ["preset_voice"]
1384
+ },
1385
+ title: "Model",
1386
+ description: "The text-to-speech model to use"
1387
+ })
1388
+ ], TextToSpeechNode.prototype, "model", void 0);
1389
+ __decorate([
1390
+ prop({
1391
+ type: "str",
1392
+ default: "Hello! This is a text-to-speech demonstration.",
1393
+ title: "Text",
1394
+ description: "Text to convert to speech"
1395
+ })
1396
+ ], TextToSpeechNode.prototype, "text", void 0);
1397
+ __decorate([
1398
+ prop({
1399
+ type: "float",
1400
+ default: 1,
1401
+ title: "Speed",
1402
+ description: "Speech speed multiplier (0.25 to 4.0)",
1403
+ min: 0.25,
1404
+ max: 4
1405
+ })
1406
+ ], TextToSpeechNode.prototype, "speed", void 0);
1407
+ __decorate([
1408
+ prop({
1409
+ type: "audio",
1410
+ default: {
1411
+ type: "audio",
1412
+ uri: "",
1413
+ asset_id: null,
1414
+ data: null,
1415
+ metadata: null
1416
+ },
1417
+ title: "Reference Audio",
1418
+ description: "A voice recording used by models that support voice cloning.",
1419
+ json_schema_extra: {
1420
+ visible_when: {
1421
+ property: "model",
1422
+ path: "capabilities",
1423
+ includes: "voice_cloning"
1424
+ }
1425
+ }
1426
+ })
1427
+ ], TextToSpeechNode.prototype, "reference_audio", void 0);
1428
+ __decorate([
1429
+ prop({
1430
+ type: "str",
1431
+ default: "",
1432
+ title: "Reference Text",
1433
+ description: "Transcript of the reference recording when required.",
1434
+ json_schema_extra: {
1435
+ visible_when: {
1436
+ property: "model",
1437
+ path: "capabilities",
1438
+ includes: "reference_transcript"
1439
+ }
1440
+ }
1441
+ })
1442
+ ], TextToSpeechNode.prototype, "reference_text", void 0);
1443
+ __decorate([
1444
+ prop({
1445
+ type: "str",
1446
+ default: "",
1447
+ title: "Language",
1448
+ description: "Optional language code or name.",
1449
+ json_schema_extra: {
1450
+ visible_when: {
1451
+ property: "model",
1452
+ path: "capabilities",
1453
+ includes: "language_selection"
1454
+ }
1455
+ }
1456
+ })
1457
+ ], TextToSpeechNode.prototype, "language", void 0);
1458
+ __decorate([
1459
+ prop({
1460
+ type: "str",
1461
+ default: "",
1462
+ title: "Instructions",
1463
+ description: "Optional voice style and delivery instructions.",
1464
+ json_schema_extra: {
1465
+ visible_when: {
1466
+ property: "model",
1467
+ path: "capabilities",
1468
+ includes_any: ["voice_design", "instruction_control"]
1469
+ }
1470
+ }
1471
+ })
1472
+ ], TextToSpeechNode.prototype, "instructions", void 0);
1473
+ function hasMusicProviderSupport(context, providerId, modelId) {
1474
+ return (!!context &&
1475
+ typeof context.textToMusic === "function" && !!providerId &&
1476
+ !!modelId);
1477
+ }
1478
+ export class TextToMusicNode extends BaseNode {
1479
+ static nodeType = "nodetool.audio.TextToMusic";
1480
+ static body = "content_card";
1481
+ static title = "Text To Music";
1482
+ static description = "Generate music from a text prompt using any supported music provider (FAL, Replicate, KIE/Suno, MiniMax). Optionally supply lyrics for vocal models.\n audio, generation, AI, text-to-music, music, song";
1483
+ static metadataOutputTypes = {
1484
+ audio: "audio"
1485
+ };
1486
+ static inlineFields = ["prompt"];
1487
+ static inputFields = ["prompt", "lyrics"];
1488
+ static autoSaveAsset = true;
1489
+ static inputMode = "buffered";
1490
+ static outputCorrelation = {
1491
+ audio: { kind: "single", source: "__execution__" }
1492
+ };
1493
+ async process(context) {
1494
+ const prompt = this.prompt;
1495
+ const lyrics = this.lyrics;
1496
+ const { providerId, modelId } = getModelConfig(this.serialize());
1497
+ if (!hasMusicProviderSupport(context, providerId, modelId)) {
1498
+ throw new Error(`Text To Music requires a music provider; no provider available for ` +
1499
+ `provider "${providerId}" / model "${modelId}".`);
1500
+ }
1501
+ const encoded = await context.textToMusic({
1502
+ provider: providerId,
1503
+ capability: "text_to_music",
1504
+ model: modelId,
1505
+ params: {
1506
+ prompt,
1507
+ lyrics: lyrics || undefined,
1508
+ duration_seconds: this.duration || undefined
1509
+ }
1510
+ });
1511
+ if (encoded?.data && encoded.data.length > 0) {
1512
+ return { audio: audioRefFromBytes(encoded.data) };
1513
+ }
1514
+ throw new Error(`Text To Music produced no audio for provider "${providerId}" / ` +
1515
+ `model "${modelId}".`);
1516
+ }
1517
+ }
1518
+ __decorate([
1519
+ prop({
1520
+ type: "music_model",
1521
+ default: {
1522
+ type: "music_model",
1523
+ provider: "replicate",
1524
+ id: "meta/musicgen",
1525
+ name: "MusicGen",
1526
+ path: null
1527
+ },
1528
+ title: "Model",
1529
+ description: "The text-to-music model to use"
1530
+ })
1531
+ ], TextToMusicNode.prototype, "model", void 0);
1532
+ __decorate([
1533
+ prop({
1534
+ type: "str",
1535
+ default: "An upbeat electronic track with a catchy melody and driving beat",
1536
+ title: "Prompt",
1537
+ description: "Describe the style, mood, genre, and instrumentation"
1538
+ })
1539
+ ], TextToMusicNode.prototype, "prompt", void 0);
1540
+ __decorate([
1541
+ prop({
1542
+ type: "str",
1543
+ default: "",
1544
+ title: "Lyrics",
1545
+ description: "Optional song lyrics for vocal models (e.g. Suno, MiniMax). Leave empty for instrumental."
1546
+ })
1547
+ ], TextToMusicNode.prototype, "lyrics", void 0);
1548
+ __decorate([
1549
+ prop({
1550
+ type: "float",
1551
+ default: 8,
1552
+ title: "Duration",
1553
+ description: "Requested duration in seconds (providers clamp to their limits).",
1554
+ min: 1,
1555
+ max: 300
1556
+ })
1557
+ ], TextToMusicNode.prototype, "duration", void 0);
1558
+ function hasAudioToAudioSupport(context, providerId, modelId) {
1559
+ return (!!context &&
1560
+ typeof context.audioToAudio === "function" &&
1561
+ !!providerId &&
1562
+ !!modelId);
1563
+ }
1564
+ export class AudioToAudioNode extends BaseNode {
1565
+ static nodeType = "nodetool.audio.AudioToAudio";
1566
+ static body = "content_card";
1567
+ static title = "Audio To Audio";
1568
+ static description = "Rewrite an existing recording with an audio-to-audio model: change the voice, isolate or denoise it, separate a stem, raise its sample rate.\n audio, audio-to-audio, voice-changer, isolation, denoise, stem-separation, AI";
1569
+ static metadataOutputTypes = {
1570
+ audio: "audio"
1571
+ };
1572
+ static inlineFields = [];
1573
+ static inputFields = ["audio", "prompt"];
1574
+ static autoSaveAsset = true;
1575
+ static inputMode = "buffered";
1576
+ static outputCorrelation = {
1577
+ audio: { kind: "single", source: "__execution__" }
1578
+ };
1579
+ async process(context) {
1580
+ const bytes = await audioBytesAsync(this.audio, context);
1581
+ if (bytes.length === 0)
1582
+ throw new Error("The input audio is empty.");
1583
+ const { providerId, modelId } = getModelConfig(this.serialize());
1584
+ if (!hasAudioToAudioSupport(context, providerId, modelId)) {
1585
+ throw new Error(`Audio To Audio requires an audio-to-audio provider; no provider ` +
1586
+ `available for provider "${providerId}" / model "${modelId}".`);
1587
+ }
1588
+ const encoded = await context.audioToAudio({
1589
+ provider: providerId,
1590
+ capability: "audio_to_audio",
1591
+ model: modelId,
1592
+ params: {
1593
+ audio: bytes,
1594
+ prompt: this.prompt || undefined,
1595
+ voice: this.voice || undefined,
1596
+ strength: Number(this.strength ?? 0.6)
1597
+ }
1598
+ });
1599
+ if (encoded?.data && encoded.data.length > 0) {
1600
+ return { audio: audioRefFromBytes(encoded.data) };
1601
+ }
1602
+ throw new Error(`Audio To Audio produced no audio for provider "${providerId}" / ` +
1603
+ `model "${modelId}".`);
1604
+ }
1605
+ }
1606
+ __decorate([
1607
+ prop({
1608
+ type: "audio_to_audio_model",
1609
+ default: {
1610
+ type: "audio_to_audio_model",
1611
+ provider: "fal_ai",
1612
+ id: "fal-ai/elevenlabs/voice-changer",
1613
+ name: "ElevenLabs Voice Changer",
1614
+ path: null,
1615
+ supported_tasks: []
1616
+ },
1617
+ title: "Model",
1618
+ description: "The audio-to-audio model to use"
1619
+ })
1620
+ ], AudioToAudioNode.prototype, "model", void 0);
1621
+ __decorate([
1622
+ prop({
1623
+ type: "audio",
1624
+ default: {
1625
+ type: "audio",
1626
+ uri: "",
1627
+ asset_id: null,
1628
+ data: null,
1629
+ metadata: null
1630
+ },
1631
+ title: "Audio",
1632
+ description: "The recording to transform"
1633
+ })
1634
+ ], AudioToAudioNode.prototype, "audio", void 0);
1635
+ __decorate([
1636
+ prop({
1637
+ type: "str",
1638
+ default: "",
1639
+ title: "Prompt",
1640
+ description: "Optional direction for models that take one. Separators and denoisers ignore it."
1641
+ })
1642
+ ], AudioToAudioNode.prototype, "prompt", void 0);
1643
+ __decorate([
1644
+ prop({
1645
+ type: "str",
1646
+ default: "",
1647
+ title: "Voice",
1648
+ description: "Target voice, for voice-conversion models that name one. Leave empty otherwise."
1649
+ })
1650
+ ], AudioToAudioNode.prototype, "voice", void 0);
1651
+ __decorate([
1652
+ prop({
1653
+ type: "float",
1654
+ default: 0.6,
1655
+ title: "Strength",
1656
+ description: "How far from the source to move, where the model takes it.",
1657
+ min: 0,
1658
+ max: 1
1659
+ })
1660
+ ], AudioToAudioNode.prototype, "strength", void 0);
1661
+ export class ChunkToAudioNode extends BaseNode {
1662
+ static nodeType = "nodetool.audio.ChunkToAudio";
1663
+ static title = "Chunk To Audio";
1664
+ static description = "Converts audio chunks from an input stream into AudioRef objects.\n audio, stream, chunk, convert";
1665
+ static metadataOutputTypes = {
1666
+ audio: "audio"
1667
+ };
1668
+ static inlineFields = [];
1669
+ static inputFields = ["chunk"];
1670
+ async process() {
1671
+ const chunk = this.chunk;
1672
+ if (isObjectLike(chunk)) {
1673
+ const c = chunk;
1674
+ // Audio chunks (e.g. from streaming TTS providers) carry base64 bytes
1675
+ // in `content` with content_type "audio"; legacy refs use `data`/`uri`.
1676
+ if (c.data) {
1677
+ return { audio: audioRefFromBytes(toBytes(c.data)) };
1678
+ }
1679
+ if (c.content_type === "audio" && isNonEmptyString(c.content)) {
1680
+ return { audio: audioRefFromBytes(toBytes(c.content)) };
1681
+ }
1682
+ if (isNonEmptyString(c.uri)) {
1683
+ return { audio: { type: "audio", uri: c.uri, data: "" } };
1684
+ }
1685
+ }
1686
+ return { audio: audioRefFromBytes(new Uint8Array()) };
1687
+ }
1688
+ }
1689
+ __decorate([
1690
+ prop({
1691
+ type: "chunk",
1692
+ default: {
1693
+ type: "chunk",
1694
+ node_id: null,
1695
+ thread_id: null,
1696
+ workflow_id: null,
1697
+ content_type: "text",
1698
+ content: "",
1699
+ content_metadata: {},
1700
+ done: false,
1701
+ thinking: false
1702
+ },
1703
+ title: "Chunk",
1704
+ description: "Stream of audio chunks"
1705
+ })
1706
+ ], ChunkToAudioNode.prototype, "chunk", void 0);
1707
+ export class GetAudioInfoNode extends BaseNode {
1708
+ static nodeType = "nodetool.audio.GetAudioInfo";
1709
+ static title = "Get Audio Info";
1710
+ static description = "Extract metadata from an audio file: duration, sample rate, channels, format.\n audio, info, metadata, duration, sample_rate, channels, format";
1711
+ static metadataOutputTypes = {
1712
+ duration: "float",
1713
+ sample_rate: "int",
1714
+ channels: "int",
1715
+ format: "str",
1716
+ size_bytes: "int"
1717
+ };
1718
+ static inlineFields = [];
1719
+ static inputFields = ["audio"];
1720
+ async process(context) {
1721
+ const bytes = await audioBytesAsync(this.audio, context);
1722
+ if (bytes.length === 0) {
1723
+ return { duration: 0, sample_rate: 0, channels: 0, format: "unknown", size_bytes: 0 };
1724
+ }
1725
+ let format = "unknown";
1726
+ let sampleRate = 0;
1727
+ let channels = 0;
1728
+ let duration = 0;
1729
+ const header = readWavHeader(bytes);
1730
+ if (header) {
1731
+ format = "wav";
1732
+ channels = header.numChannels;
1733
+ sampleRate = header.sampleRate;
1734
+ const { bitsPerSample, dataSize } = header;
1735
+ if (sampleRate > 0 && channels > 0 && bitsPerSample > 0) {
1736
+ duration = dataSize / (sampleRate * channels * (bitsPerSample / 8));
1737
+ }
1738
+ }
1739
+ if (format === "unknown" && bytes.length >= 4) {
1740
+ if (bytes[0] === 0xff && (bytes[1] & 0xe0) === 0xe0) {
1741
+ format = "mp3";
1742
+ }
1743
+ else if (bytes[0] === 0x66 && bytes[1] === 0x4c &&
1744
+ bytes[2] === 0x61 && bytes[3] === 0x43) {
1745
+ format = "flac";
1746
+ }
1747
+ else if (bytes[0] === 0x4f && bytes[1] === 0x67 &&
1748
+ bytes[2] === 0x67 && bytes[3] === 0x53) {
1749
+ format = "ogg";
1750
+ }
1751
+ }
1752
+ return {
1753
+ duration: Math.round(duration * 1000) / 1000,
1754
+ sample_rate: sampleRate,
1755
+ channels,
1756
+ format,
1757
+ size_bytes: bytes.length
1758
+ };
1759
+ }
1760
+ }
1761
+ __decorate([
1762
+ prop({
1763
+ type: "audio",
1764
+ default: {
1765
+ type: "audio",
1766
+ uri: "",
1767
+ asset_id: null,
1768
+ data: null,
1769
+ metadata: null
1770
+ },
1771
+ title: "Audio",
1772
+ description: "The audio to inspect."
1773
+ })
1774
+ ], GetAudioInfoNode.prototype, "audio", void 0);
1775
+ /**
1776
+ * Sample/byte transforms — server-only. They decode their input to PCM (WAV
1777
+ * directly, or compressed formats via WebAudio `decodeAudioData`), which needs
1778
+ * Node's `node-web-audio-api`; stored `/api/storage/<key>` refs also resolve
1779
+ * reliably only against the server's storage.
1780
+ */
1781
+ const AUDIO_TRANSFORM_NODES = tagAsServer([
1782
+ NormalizeAudioNode,
1783
+ OverlayAudioNode,
1784
+ RemoveSilenceNode,
1785
+ SliceAudioNode,
1786
+ MonoToStereoNode,
1787
+ StereoToMonoNode,
1788
+ ReverseAudioNode,
1789
+ FadeInAudioNode,
1790
+ FadeOutAudioNode,
1791
+ RepeatAudioNode,
1792
+ AudioMixerNode,
1793
+ TrimAudioNode,
1794
+ CreateSilenceNode,
1795
+ ConcatAudioNode,
1796
+ ConcatAudioListNode,
1797
+ ChunkToAudioNode,
1798
+ GetAudioInfoNode
1799
+ ]);
1800
+ /**
1801
+ * Server-only nodes: asset/file I/O (the Load/Save classes also declare
1802
+ * `static platforms = NODE_ONLY`, which wins over the tagger) and TTS,
1803
+ * which needs the server's provider prediction.
1804
+ */
1805
+ const AUDIO_SERVER_NODES = tagAsServer([
1806
+ LoadAudioAssetsNode,
1807
+ LoadAudioFileNode,
1808
+ LoadAudioFolderNode,
1809
+ SaveAudioNode,
1810
+ SaveAudioFileNode,
1811
+ TextToSpeechNode,
1812
+ TextToMusicNode,
1813
+ AudioToAudioNode
1814
+ ]);
1815
+ export const AUDIO_NODES = [...AUDIO_TRANSFORM_NODES, ...AUDIO_SERVER_NODES];
1816
+ //# sourceMappingURL=audio.js.map