speechflow 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +3 -3
- package/speechflow-cli/dst/speechflow-node-a2a-ffmpeg.d.ts +13 -0
- package/speechflow-cli/dst/speechflow-node-a2a-ffmpeg.js +153 -0
- package/speechflow-cli/dst/speechflow-node-a2a-ffmpeg.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-a2a-gender.d.ts +20 -0
- package/speechflow-cli/dst/speechflow-node-a2a-gender.js +349 -0
- package/speechflow-cli/dst/speechflow-node-a2a-gender.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-a2a-meter.d.ts +16 -0
- package/speechflow-cli/dst/speechflow-node-a2a-meter.js +232 -0
- package/speechflow-cli/dst/speechflow-node-a2a-meter.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-a2a-mute.d.ts +17 -0
- package/speechflow-cli/dst/speechflow-node-a2a-mute.js +117 -0
- package/speechflow-cli/dst/speechflow-node-a2a-mute.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-a2a-vad.d.ts +19 -0
- package/speechflow-cli/dst/speechflow-node-a2a-vad.js +374 -0
- package/speechflow-cli/dst/speechflow-node-a2a-vad.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-a2a-wav.d.ts +11 -0
- package/speechflow-cli/dst/speechflow-node-a2a-wav.js +211 -0
- package/speechflow-cli/dst/speechflow-node-a2a-wav.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-a2t-deepgram.d.ts +19 -0
- package/speechflow-cli/dst/speechflow-node-a2t-deepgram.js +328 -0
- package/speechflow-cli/dst/speechflow-node-a2t-deepgram.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-t2a-elevenlabs.d.ts +18 -0
- package/speechflow-cli/dst/speechflow-node-t2a-elevenlabs.js +238 -0
- package/speechflow-cli/dst/speechflow-node-t2a-elevenlabs.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-t2a-kokoro.d.ts +14 -0
- package/speechflow-cli/dst/speechflow-node-t2a-kokoro.js +155 -0
- package/speechflow-cli/dst/speechflow-node-t2a-kokoro.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-t2t-deepl.d.ts +15 -0
- package/speechflow-cli/dst/speechflow-node-t2t-deepl.js +146 -0
- package/speechflow-cli/dst/speechflow-node-t2t-deepl.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-t2t-format.d.ts +11 -0
- package/speechflow-cli/dst/speechflow-node-t2t-format.js +82 -0
- package/speechflow-cli/dst/speechflow-node-t2t-format.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-t2t-ollama.d.ts +13 -0
- package/speechflow-cli/dst/speechflow-node-t2t-ollama.js +247 -0
- package/speechflow-cli/dst/speechflow-node-t2t-ollama.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-t2t-openai.d.ts +13 -0
- package/speechflow-cli/dst/speechflow-node-t2t-openai.js +227 -0
- package/speechflow-cli/dst/speechflow-node-t2t-openai.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-t2t-sentence.d.ts +17 -0
- package/speechflow-cli/dst/speechflow-node-t2t-sentence.js +250 -0
- package/speechflow-cli/dst/speechflow-node-t2t-sentence.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-t2t-subtitle.d.ts +13 -0
- package/speechflow-cli/dst/speechflow-node-t2t-subtitle.js +278 -0
- package/speechflow-cli/dst/speechflow-node-t2t-subtitle.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-t2t-transformers.d.ts +14 -0
- package/speechflow-cli/dst/speechflow-node-t2t-transformers.js +265 -0
- package/speechflow-cli/dst/speechflow-node-t2t-transformers.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-x2x-filter.d.ts +11 -0
- package/speechflow-cli/dst/speechflow-node-x2x-filter.js +121 -0
- package/speechflow-cli/dst/speechflow-node-x2x-filter.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-x2x-trace.d.ts +11 -0
- package/speechflow-cli/dst/speechflow-node-x2x-trace.js +111 -0
- package/speechflow-cli/dst/speechflow-node-x2x-trace.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-xio-device.d.ts +13 -0
- package/speechflow-cli/dst/speechflow-node-xio-device.js +230 -0
- package/speechflow-cli/dst/speechflow-node-xio-device.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-xio-file.d.ts +11 -0
- package/speechflow-cli/dst/speechflow-node-xio-file.js +216 -0
- package/speechflow-cli/dst/speechflow-node-xio-file.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-xio-mqtt.d.ts +13 -0
- package/speechflow-cli/dst/speechflow-node-xio-mqtt.js +188 -0
- package/speechflow-cli/dst/speechflow-node-xio-mqtt.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node-xio-websocket.d.ts +13 -0
- package/speechflow-cli/dst/speechflow-node-xio-websocket.js +278 -0
- package/speechflow-cli/dst/speechflow-node-xio-websocket.js.map +1 -0
- package/speechflow-cli/dst/speechflow-node.d.ts +65 -0
- package/speechflow-cli/dst/speechflow-node.js +180 -0
- package/speechflow-cli/dst/speechflow-node.js.map +1 -0
- package/speechflow-cli/dst/speechflow-utils.d.ts +74 -0
- package/speechflow-cli/dst/speechflow-utils.js +519 -0
- package/speechflow-cli/dst/speechflow-utils.js.map +1 -0
- package/speechflow-cli/dst/speechflow.d.ts +7 -0
- package/speechflow-cli/dst/speechflow.js +837 -0
- package/speechflow-cli/dst/speechflow.js.map +1 -0
- package/speechflow-cli/package.json +1 -1
- package/speechflow-ui-db/dst/app-font-TypoPRO-SourceSansPro-Bold.eot +0 -0
- package/speechflow-ui-db/dst/app-font-TypoPRO-SourceSansPro-Bold.ttf +0 -0
- package/speechflow-ui-db/dst/app-font-TypoPRO-SourceSansPro-Bold.woff +0 -0
- package/speechflow-ui-db/dst/app-font-TypoPRO-SourceSansPro-Regular.eot +0 -0
- package/speechflow-ui-db/dst/app-font-TypoPRO-SourceSansPro-Regular.ttf +0 -0
- package/speechflow-ui-db/dst/app-font-TypoPRO-SourceSansPro-Regular.woff +0 -0
- package/speechflow-ui-db/dst/app-font-fa-brands-400.woff2 +0 -0
- package/speechflow-ui-db/dst/app-font-fa-regular-400.woff2 +0 -0
- package/speechflow-ui-db/dst/app-font-fa-solid-900.woff2 +0 -0
- package/speechflow-ui-db/dst/app-font-fa-v4compatibility.woff2 +0 -0
- package/speechflow-ui-db/dst/app-icon.svg +26 -0
- package/speechflow-ui-db/dst/index.css +5 -0
- package/speechflow-ui-db/dst/index.html +24 -0
- package/speechflow-ui-db/dst/index.js +616 -0
- package/speechflow-ui-st/dst/app-font-TypoPRO-SourceSansPro-Bold.eot +0 -0
- package/speechflow-ui-st/dst/app-font-TypoPRO-SourceSansPro-Bold.ttf +0 -0
- package/speechflow-ui-st/dst/app-font-TypoPRO-SourceSansPro-Bold.woff +0 -0
- package/speechflow-ui-st/dst/app-font-TypoPRO-SourceSansPro-Regular.eot +0 -0
- package/speechflow-ui-st/dst/app-font-TypoPRO-SourceSansPro-Regular.ttf +0 -0
- package/speechflow-ui-st/dst/app-font-TypoPRO-SourceSansPro-Regular.woff +0 -0
- package/speechflow-ui-st/dst/app-font-fa-brands-400.woff2 +0 -0
- package/speechflow-ui-st/dst/app-font-fa-regular-400.woff2 +0 -0
- package/speechflow-ui-st/dst/app-font-fa-solid-900.woff2 +0 -0
- package/speechflow-ui-st/dst/app-font-fa-v4compatibility.woff2 +0 -0
- package/speechflow-ui-st/dst/app-icon.svg +26 -0
- package/speechflow-ui-st/dst/index.css +5 -0
- package/speechflow-ui-st/dst/index.html +24 -0
- package/speechflow-ui-st/dst/index.js +610 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
** SpeechFlow - Speech Processing Flow Graph
|
|
4
|
+
** Copyright (c) 2024-2025 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
5
|
+
** Licensed under GPL 3.0 <https://spdx.org/licenses/GPL-3.0-only>
|
|
6
|
+
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
/* standard dependencies */
|
|
12
|
+
const node_stream_1 = __importDefault(require("node:stream"));
|
|
13
|
+
/* external dependencies */
|
|
14
|
+
const kokoro_js_1 = require("kokoro-js");
|
|
15
|
+
const speex_resampler_1 = __importDefault(require("speex-resampler"));
|
|
16
|
+
/* internal dependencies */
|
|
17
|
+
const speechflow_node_1 = __importDefault(require("./speechflow-node"));
|
|
18
|
+
/* SpeechFlow node for Kokoro text-to-speech conversion */
|
|
19
|
+
class SpeechFlowNodeKokoro extends speechflow_node_1.default {
|
|
20
|
+
/* declare official node name */
|
|
21
|
+
static name = "kokoro";
|
|
22
|
+
/* internal state */
|
|
23
|
+
kokoro = null;
|
|
24
|
+
resampler = null;
|
|
25
|
+
static speexInitialized = false;
|
|
26
|
+
/* construct node */
|
|
27
|
+
constructor(id, cfg, opts, args) {
|
|
28
|
+
super(id, cfg, opts, args);
|
|
29
|
+
/* declare node configuration parameters */
|
|
30
|
+
this.configure({
|
|
31
|
+
voice: { type: "string", val: "Aoede", pos: 0, match: /^(?:Aoede|Heart|Puck|Fenrir)$/ },
|
|
32
|
+
language: { type: "string", val: "en", pos: 1, match: /^(?:en)$/ },
|
|
33
|
+
speed: { type: "number", val: 1.25, pos: 2, match: (n) => n >= 1.0 && n <= 1.30 },
|
|
34
|
+
});
|
|
35
|
+
/* declare node input/output format */
|
|
36
|
+
this.input = "text";
|
|
37
|
+
this.output = "audio";
|
|
38
|
+
}
|
|
39
|
+
/* open node */
|
|
40
|
+
async open() {
|
|
41
|
+
/* establish Kokoro */
|
|
42
|
+
const model = "onnx-community/Kokoro-82M-v1.0-ONNX";
|
|
43
|
+
const progressState = new Map();
|
|
44
|
+
const progressCallback = (progress) => {
|
|
45
|
+
let artifact = model;
|
|
46
|
+
if (typeof progress.file === "string")
|
|
47
|
+
artifact += `:${progress.file}`;
|
|
48
|
+
let percent = 0;
|
|
49
|
+
if (typeof progress.loaded === "number" && typeof progress.total === "number")
|
|
50
|
+
percent = progress.loaded / progress.total * 100;
|
|
51
|
+
else if (typeof progress.progress === "number")
|
|
52
|
+
percent = progress.progress;
|
|
53
|
+
if (percent > 0)
|
|
54
|
+
progressState.set(artifact, percent);
|
|
55
|
+
};
|
|
56
|
+
const interval = setInterval(() => {
|
|
57
|
+
for (const [artifact, percent] of progressState) {
|
|
58
|
+
this.log("info", `downloaded ${percent.toFixed(2)}% of artifact "${artifact}"`);
|
|
59
|
+
if (percent >= 100.0)
|
|
60
|
+
progressState.delete(artifact);
|
|
61
|
+
}
|
|
62
|
+
if (progressState.size === 0)
|
|
63
|
+
clearInterval(interval);
|
|
64
|
+
}, 1000);
|
|
65
|
+
this.kokoro = await kokoro_js_1.KokoroTTS.from_pretrained(model, {
|
|
66
|
+
dtype: "q4f16",
|
|
67
|
+
progress_callback: progressCallback
|
|
68
|
+
});
|
|
69
|
+
clearInterval(interval);
|
|
70
|
+
if (this.kokoro === null)
|
|
71
|
+
throw new Error("failed to instantiate Kokoro");
|
|
72
|
+
/* establish resampler from Kokoro's maximum 24Khz
|
|
73
|
+
output to our standard audio sample rate (48KHz) */
|
|
74
|
+
if (!SpeechFlowNodeKokoro.speexInitialized) {
|
|
75
|
+
/* at least once initialize resampler */
|
|
76
|
+
await speex_resampler_1.default.initPromise;
|
|
77
|
+
SpeechFlowNodeKokoro.speexInitialized = true;
|
|
78
|
+
}
|
|
79
|
+
this.resampler = new speex_resampler_1.default(1, 24000, this.config.audioSampleRate, 7);
|
|
80
|
+
/* determine voice for text-to-speech operation */
|
|
81
|
+
const voices = {
|
|
82
|
+
"Aoede": "af_aoede",
|
|
83
|
+
"Heart": "af_heart",
|
|
84
|
+
"Puck": "am_puck",
|
|
85
|
+
"Fenrir": "am_fenrir"
|
|
86
|
+
};
|
|
87
|
+
const voice = (voices[this.params.voice]);
|
|
88
|
+
if (voice === undefined)
|
|
89
|
+
throw new Error(`invalid Kokoro voice "${this.params.voice}"`);
|
|
90
|
+
/* perform text-to-speech operation with Kokoro API */
|
|
91
|
+
const text2speech = async (text) => {
|
|
92
|
+
this.log("info", `Kokoro: input: "${text}"`);
|
|
93
|
+
const audio = await this.kokoro.generate(text, {
|
|
94
|
+
speed: this.params.speed,
|
|
95
|
+
voice: voice
|
|
96
|
+
});
|
|
97
|
+
if (audio.sampling_rate !== 24000)
|
|
98
|
+
throw new Error("expected 24KHz sampling rate in Kokoro output");
|
|
99
|
+
/* convert audio samples from PCM/F32/24Khz to PCM/I16/24KHz */
|
|
100
|
+
const samples = audio.audio;
|
|
101
|
+
const buffer1 = Buffer.alloc(samples.length * 2);
|
|
102
|
+
for (let i = 0; i < samples.length; i++) {
|
|
103
|
+
const sample = Math.max(-1, Math.min(1, samples[i]));
|
|
104
|
+
buffer1.writeInt16LE(sample * 0x7FFF, i * 2);
|
|
105
|
+
}
|
|
106
|
+
/* resample audio samples from PCM/I16/24Khz to PCM/I16/48KHz */
|
|
107
|
+
const buffer2 = this.resampler.processChunk(buffer1);
|
|
108
|
+
return buffer2;
|
|
109
|
+
};
|
|
110
|
+
/* create transform stream and connect it to the Kokoro API */
|
|
111
|
+
const log = (level, msg) => { this.log(level, msg); };
|
|
112
|
+
this.stream = new node_stream_1.default.Transform({
|
|
113
|
+
writableObjectMode: true,
|
|
114
|
+
readableObjectMode: true,
|
|
115
|
+
decodeStrings: false,
|
|
116
|
+
highWaterMark: 1,
|
|
117
|
+
transform(chunk, encoding, callback) {
|
|
118
|
+
if (Buffer.isBuffer(chunk.payload))
|
|
119
|
+
callback(new Error("invalid chunk payload type"));
|
|
120
|
+
else {
|
|
121
|
+
text2speech(chunk.payload).then((buffer) => {
|
|
122
|
+
log("info", `Kokoro: received audio (buffer length: ${buffer.byteLength})`);
|
|
123
|
+
chunk = chunk.clone();
|
|
124
|
+
chunk.type = "audio";
|
|
125
|
+
chunk.payload = buffer;
|
|
126
|
+
this.push(chunk);
|
|
127
|
+
callback();
|
|
128
|
+
}).catch((err) => {
|
|
129
|
+
callback(err);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
final(callback) {
|
|
134
|
+
this.push(null);
|
|
135
|
+
callback();
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/* close node */
|
|
140
|
+
async close() {
|
|
141
|
+
/* destroy stream */
|
|
142
|
+
if (this.stream !== null) {
|
|
143
|
+
this.stream.destroy();
|
|
144
|
+
this.stream = null;
|
|
145
|
+
}
|
|
146
|
+
/* destroy resampler */
|
|
147
|
+
if (this.resampler !== null)
|
|
148
|
+
this.resampler = null;
|
|
149
|
+
/* destroy Kokoro API */
|
|
150
|
+
if (this.kokoro !== null)
|
|
151
|
+
this.kokoro = null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.default = SpeechFlowNodeKokoro;
|
|
155
|
+
//# sourceMappingURL=speechflow-node-t2a-kokoro.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"speechflow-node-t2a-kokoro.js","sourceRoot":"","sources":["../src/speechflow-node-t2a-kokoro.ts"],"names":[],"mappings":";AAAA;;;;EAIE;;;;;AAEF,6BAA6B;AAC7B,8DAAgC;AAEhC,6BAA6B;AAC7B,yCAAsC;AACtC,sEAA4C;AAE5C,6BAA6B;AAC7B,wEAAmE;AAEnE,4DAA4D;AAC5D,MAAqB,oBAAqB,SAAQ,yBAAc;IAC5D,kCAAkC;IAC3B,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAA;IAE7B,sBAAsB;IACd,MAAM,GAAqB,IAAI,CAAA;IAC/B,SAAS,GAA0B,IAAI,CAAA;IACvC,MAAM,CAAC,gBAAgB,GAAG,KAAK,CAAA;IAEvC,sBAAsB;IACtB,Y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;gBACN,CAAC;YACL,CAAC;YACD,KAAK,CAAE,QAAQ;gBACX,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBACf,QAAQ,EAAE,CAAA;YACd,CAAC;SACJ,CAAC,CAAA;IACN,CAAC;IAED,kBAAkB;IAClB,KAAK,CAAC,KAAK;QACP,sBAAsB;QACtB,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAA;YACrB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;QACtB,CAAC;QAED,yBAAyB;QACzB,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI;YACvB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;QAEzB,0BAA0B;QAC1B,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI;YACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;IAC1B,CAAC;;AApJL,uCAqJC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import SpeechFlowNode from "./speechflow-node";
|
|
2
|
+
export default class SpeechFlowNodeDeepL extends SpeechFlowNode {
|
|
3
|
+
static name: string;
|
|
4
|
+
private deepl;
|
|
5
|
+
constructor(id: string, cfg: {
|
|
6
|
+
[id: string]: any;
|
|
7
|
+
}, opts: {
|
|
8
|
+
[id: string]: any;
|
|
9
|
+
}, args: any[]);
|
|
10
|
+
status(): Promise<{
|
|
11
|
+
usage: string;
|
|
12
|
+
}>;
|
|
13
|
+
open(): Promise<void>;
|
|
14
|
+
close(): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
** SpeechFlow - Speech Processing Flow Graph
|
|
4
|
+
** Copyright (c) 2024-2025 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
5
|
+
** Licensed under GPL 3.0 <https://spdx.org/licenses/GPL-3.0-only>
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
/* standard dependencies */
|
|
45
|
+
const node_stream_1 = __importDefault(require("node:stream"));
|
|
46
|
+
/* external dependencies */
|
|
47
|
+
const DeepL = __importStar(require("deepl-node"));
|
|
48
|
+
/* internal dependencies */
|
|
49
|
+
const speechflow_node_1 = __importDefault(require("./speechflow-node"));
|
|
50
|
+
/* SpeechFlow node for DeepL text-to-text translations */
|
|
51
|
+
class SpeechFlowNodeDeepL extends speechflow_node_1.default {
|
|
52
|
+
/* declare official node name */
|
|
53
|
+
static name = "deepl";
|
|
54
|
+
/* internal state */
|
|
55
|
+
deepl = null;
|
|
56
|
+
/* construct node */
|
|
57
|
+
constructor(id, cfg, opts, args) {
|
|
58
|
+
super(id, cfg, opts, args);
|
|
59
|
+
/* declare node configuration parameters */
|
|
60
|
+
this.configure({
|
|
61
|
+
key: { type: "string", val: process.env.SPEECHFLOW_DEEPL_KEY ?? "" },
|
|
62
|
+
src: { type: "string", pos: 0, val: "de", match: /^(?:de|en)$/ },
|
|
63
|
+
dst: { type: "string", pos: 1, val: "en", match: /^(?:de|en)$/ },
|
|
64
|
+
optimize: { type: "string", pos: 2, val: "latency", match: /^(?:latency|quality)$/ }
|
|
65
|
+
});
|
|
66
|
+
/* validate API key */
|
|
67
|
+
if (this.params.key === "")
|
|
68
|
+
throw new Error("DeepL API key is required");
|
|
69
|
+
/* sanity check situation */
|
|
70
|
+
if (this.params.src === this.params.dst)
|
|
71
|
+
throw new Error("source and destination languages cannot be the same");
|
|
72
|
+
/* declare node input/output format */
|
|
73
|
+
this.input = "text";
|
|
74
|
+
this.output = "text";
|
|
75
|
+
}
|
|
76
|
+
/* one-time status of node */
|
|
77
|
+
async status() {
|
|
78
|
+
const deepl = new DeepL.Translator(this.params.key);
|
|
79
|
+
const usage = await deepl.getUsage();
|
|
80
|
+
const limit = usage?.character?.limit ?? 1;
|
|
81
|
+
const percent = limit > 0 ? ((usage?.character?.count ?? 0) / limit * 100) : 0;
|
|
82
|
+
return { usage: `${percent.toFixed(8)}%` };
|
|
83
|
+
}
|
|
84
|
+
/* open node */
|
|
85
|
+
async open() {
|
|
86
|
+
/* instantiate DeepL API SDK */
|
|
87
|
+
this.deepl = new DeepL.Translator(this.params.key);
|
|
88
|
+
/* provide text-to-text translation */
|
|
89
|
+
const translate = async (text) => {
|
|
90
|
+
const src = this.params.src === "en" ? "en-US" : this.params.src;
|
|
91
|
+
const dst = this.params.dst === "en" ? "en-US" : this.params.dst;
|
|
92
|
+
const result = await this.deepl.translateText(text, src, dst, {
|
|
93
|
+
splitSentences: "off",
|
|
94
|
+
modelType: this.params.optimize === "latency" ?
|
|
95
|
+
"latency_optimized" : "prefer_quality_optimized",
|
|
96
|
+
preserveFormatting: true,
|
|
97
|
+
formality: "prefer_more"
|
|
98
|
+
});
|
|
99
|
+
return (result?.text ?? text);
|
|
100
|
+
};
|
|
101
|
+
/* establish a duplex stream and connect it to DeepL translation */
|
|
102
|
+
this.stream = new node_stream_1.default.Transform({
|
|
103
|
+
readableObjectMode: true,
|
|
104
|
+
writableObjectMode: true,
|
|
105
|
+
decodeStrings: false,
|
|
106
|
+
highWaterMark: 1,
|
|
107
|
+
transform(chunk, encoding, callback) {
|
|
108
|
+
if (Buffer.isBuffer(chunk.payload))
|
|
109
|
+
callback(new Error("invalid chunk payload type"));
|
|
110
|
+
else {
|
|
111
|
+
if (chunk.payload === "") {
|
|
112
|
+
this.push(chunk);
|
|
113
|
+
callback();
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
translate(chunk.payload).then((payload) => {
|
|
117
|
+
const chunkNew = chunk.clone();
|
|
118
|
+
chunkNew.payload = payload;
|
|
119
|
+
this.push(chunkNew);
|
|
120
|
+
callback();
|
|
121
|
+
}).catch((err) => {
|
|
122
|
+
callback(err);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
final(callback) {
|
|
128
|
+
this.push(null);
|
|
129
|
+
callback();
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/* close node */
|
|
134
|
+
async close() {
|
|
135
|
+
/* close stream */
|
|
136
|
+
if (this.stream !== null) {
|
|
137
|
+
this.stream.destroy();
|
|
138
|
+
this.stream = null;
|
|
139
|
+
}
|
|
140
|
+
/* shutdown DeepL API */
|
|
141
|
+
if (this.deepl !== null)
|
|
142
|
+
this.deepl = null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.default = SpeechFlowNodeDeepL;
|
|
146
|
+
//# sourceMappingURL=speechflow-node-t2t-deepl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"speechflow-node-t2t-deepl.js","sourceRoot":"","sources":["../src/speechflow-node-t2t-deepl.ts"],"names":[],"mappings":";AAAA;;;;EAIE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,6BAA6B;AAC7B,8DAAgC;AAEhC,6BAA6B;AAC7B,kDAAmC;AAEnC,6BAA6B;AAC7B,wEAAmE;AAEnE,2DAA2D;AAC3D,MAAqB,mBAAoB,SAAQ,yBAAc;IAC3D,kCAAkC;IAC3B,MAAM,CAAC,IAAI,GAAG,OAAO,CAAA;IAE5B,sBAAsB;IACd,KAAK,GAA4B,IAAI,CAAA;IAE7C,sBAAsB;IACtB,YAAa,EAAU,EAAE,GAA4B,EAAE,IAA6B,EAAE,IAAW;QAC7F,KAAK,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;QAE1B,6CAA6C;QAC7C,IAAI,CAAC,SAAS,CAAC;YACX,GAAG,EAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,EAAE,EAAE;YACzE,GAAG,EAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAO,KAAK,EAAE,aAAa,EAAE;YAC1E,GAAG,EAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,G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EAAE,CAAC;wBACvB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;wBAChB,QAAQ,EAAE,CAAA;oBACd,CAAC;yBACI,CAAC;wBACF,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;4BACtC,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,EAAE,CAAA;4BAC9B,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAA;4BAC1B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;4BACnB,QAAQ,EAAE,CAAA;wBACd,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;4BACb,QAAQ,CAAC,GAAG,CAAC,CAAA;wBACjB,CAAC,CAAC,CAAA;oBACN,CAAC;gBACL,CAAC;YACL,CAAC;YACD,KAAK,CAAE,QAAQ;gBACX,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBACf,QAAQ,EAAE,CAAA;YACd,CAAC;SACJ,CAAC,CAAA;IACN,CAAC;IAED,kBAAkB;IAClB,KAAK,CAAC,KAAK;QACP,oBAAoB;QACpB,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAA;YACrB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;QACtB,CAAC;QAED,0BAA0B;QAC1B,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI;YACnB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;IACzB,CAAC;;AAxGL,sCAyGC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import SpeechFlowNode from "./speechflow-node";
|
|
2
|
+
export default class SpeechFlowNodeFormat extends SpeechFlowNode {
|
|
3
|
+
static name: string;
|
|
4
|
+
constructor(id: string, cfg: {
|
|
5
|
+
[id: string]: any;
|
|
6
|
+
}, opts: {
|
|
7
|
+
[id: string]: any;
|
|
8
|
+
}, args: any[]);
|
|
9
|
+
open(): Promise<void>;
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
** SpeechFlow - Speech Processing Flow Graph
|
|
4
|
+
** Copyright (c) 2024-2025 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
5
|
+
** Licensed under GPL 3.0 <https://spdx.org/licenses/GPL-3.0-only>
|
|
6
|
+
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
/* standard dependencies */
|
|
12
|
+
const node_stream_1 = __importDefault(require("node:stream"));
|
|
13
|
+
/* external dependencies */
|
|
14
|
+
const wrap_text_1 = __importDefault(require("wrap-text"));
|
|
15
|
+
/* internal dependencies */
|
|
16
|
+
const speechflow_node_1 = __importDefault(require("./speechflow-node"));
|
|
17
|
+
/* SpeechFlow node for text-to-text formatting */
|
|
18
|
+
class SpeechFlowNodeFormat extends speechflow_node_1.default {
|
|
19
|
+
/* declare official node name */
|
|
20
|
+
static name = "format";
|
|
21
|
+
/* construct node */
|
|
22
|
+
constructor(id, cfg, opts, args) {
|
|
23
|
+
super(id, cfg, opts, args);
|
|
24
|
+
/* declare node configuration parameters */
|
|
25
|
+
this.configure({
|
|
26
|
+
width: { type: "number", val: 80 }
|
|
27
|
+
});
|
|
28
|
+
/* declare node input/output format */
|
|
29
|
+
this.input = "text";
|
|
30
|
+
this.output = "text";
|
|
31
|
+
}
|
|
32
|
+
/* open node */
|
|
33
|
+
async open() {
|
|
34
|
+
/* provide text-to-text formatter */
|
|
35
|
+
const format = async (text) => {
|
|
36
|
+
text = (0, wrap_text_1.default)(text, this.params.width);
|
|
37
|
+
text = text.replace(/([^\n])$/, "$1\n");
|
|
38
|
+
return text;
|
|
39
|
+
};
|
|
40
|
+
/* establish a duplex stream and connect it to text formatting */
|
|
41
|
+
this.stream = new node_stream_1.default.Transform({
|
|
42
|
+
readableObjectMode: true,
|
|
43
|
+
writableObjectMode: true,
|
|
44
|
+
decodeStrings: false,
|
|
45
|
+
highWaterMark: 1,
|
|
46
|
+
transform(chunk, encoding, callback) {
|
|
47
|
+
if (Buffer.isBuffer(chunk.payload))
|
|
48
|
+
callback(new Error("invalid chunk payload type"));
|
|
49
|
+
else {
|
|
50
|
+
if (chunk.payload === "") {
|
|
51
|
+
this.push(chunk);
|
|
52
|
+
callback();
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
format(chunk.payload).then((payload) => {
|
|
56
|
+
const chunkNew = chunk.clone();
|
|
57
|
+
chunkNew.payload = payload;
|
|
58
|
+
this.push(chunkNew);
|
|
59
|
+
callback();
|
|
60
|
+
}).catch((err) => {
|
|
61
|
+
callback(err);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
final(callback) {
|
|
67
|
+
this.push(null);
|
|
68
|
+
callback();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/* close node */
|
|
73
|
+
async close() {
|
|
74
|
+
/* close stream */
|
|
75
|
+
if (this.stream !== null) {
|
|
76
|
+
this.stream.destroy();
|
|
77
|
+
this.stream = null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.default = SpeechFlowNodeFormat;
|
|
82
|
+
//# sourceMappingURL=speechflow-node-t2t-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"speechflow-node-t2t-format.js","sourceRoot":"","sources":["../src/speechflow-node-t2t-format.ts"],"names":[],"mappings":";AAAA;;;;EAIE;;;;;AAEF,6BAA6B;AAC7B,8DAAkC;AAElC,6BAA6B;AAC7B,0DAAgC;AAEhC,6BAA6B;AAC7B,wEAAmE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AE,CAAC;wBACvB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;wBAChB,QAAQ,EAAE,CAAA;oBACd,CAAC;yBACI,CAAC;wBACF,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;4BACnC,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,EAAE,CAAA;4BAC9B,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAA;4BAC1B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;4BACnB,QAAQ,EAAE,CAAA;wBACd,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;4BACb,QAAQ,CAAC,GAAG,CAAC,CAAA;wBACjB,CAAC,CAAC,CAAA;oBACN,CAAC;gBACL,CAAC;YACL,CAAC;YACD,KAAK,CAAE,QAAQ;gBACX,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBACf,QAAQ,EAAE,CAAA;YACd,CAAC;SACJ,CAAC,CAAA;IACN,CAAC;IAED,kBAAkB;IAClB,KAAK,CAAC,KAAK;QACP,oBAAoB;QACpB,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAA;YACrB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;QACtB,CAAC;IACL,CAAC;;AAnEL,uCAoEC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import SpeechFlowNode from "./speechflow-node";
|
|
2
|
+
export default class SpeechFlowNodeOllama extends SpeechFlowNode {
|
|
3
|
+
static name: string;
|
|
4
|
+
private ollama;
|
|
5
|
+
private setup;
|
|
6
|
+
constructor(id: string, cfg: {
|
|
7
|
+
[id: string]: any;
|
|
8
|
+
}, opts: {
|
|
9
|
+
[id: string]: any;
|
|
10
|
+
}, args: any[]);
|
|
11
|
+
open(): Promise<void>;
|
|
12
|
+
close(): Promise<void>;
|
|
13
|
+
}
|