speechflow 0.9.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +48 -1
- package/dst/speechflow-node-a2a-ffmpeg.js +1 -0
- package/dst/speechflow-node-a2a-ffmpeg.js.map +1 -0
- package/dst/{speechflow-node-gemma.d.ts → speechflow-node-a2a-meter.d.ts} +2 -3
- package/dst/speechflow-node-a2a-meter.js +147 -0
- package/dst/speechflow-node-a2a-meter.js.map +1 -0
- package/dst/speechflow-node-a2a-mute.d.ts +16 -0
- package/dst/speechflow-node-a2a-mute.js +90 -0
- package/dst/speechflow-node-a2a-mute.js.map +1 -0
- package/dst/speechflow-node-a2a-vad.js +130 -289
- package/dst/speechflow-node-a2a-vad.js.map +1 -0
- package/dst/speechflow-node-a2a-wav.js +1 -0
- package/dst/speechflow-node-a2a-wav.js.map +1 -0
- package/dst/speechflow-node-a2t-deepgram.js +2 -1
- package/dst/speechflow-node-a2t-deepgram.js.map +1 -0
- package/dst/speechflow-node-t2a-elevenlabs.js +1 -0
- package/dst/speechflow-node-t2a-elevenlabs.js.map +1 -0
- package/dst/speechflow-node-t2a-kokoro.js +1 -0
- package/dst/speechflow-node-t2a-kokoro.js.map +1 -0
- package/dst/speechflow-node-t2t-deepl.js +1 -0
- package/dst/speechflow-node-t2t-deepl.js.map +1 -0
- package/dst/speechflow-node-t2t-format.js +1 -0
- package/dst/speechflow-node-t2t-format.js.map +1 -0
- package/dst/speechflow-node-t2t-ollama.js +1 -0
- package/dst/speechflow-node-t2t-ollama.js.map +1 -0
- package/dst/speechflow-node-t2t-openai.js +1 -0
- package/dst/speechflow-node-t2t-openai.js.map +1 -0
- package/dst/speechflow-node-t2t-subtitle.js +1 -0
- package/dst/speechflow-node-t2t-subtitle.js.map +1 -0
- package/dst/speechflow-node-t2t-transformers.js +10 -6
- package/dst/speechflow-node-t2t-transformers.js.map +1 -0
- package/dst/speechflow-node-x2x-trace.js +1 -0
- package/dst/speechflow-node-x2x-trace.js.map +1 -0
- package/dst/speechflow-node-xio-device.js +1 -0
- package/dst/speechflow-node-xio-device.js.map +1 -0
- package/dst/speechflow-node-xio-file.js +1 -0
- package/dst/speechflow-node-xio-file.js.map +1 -0
- package/dst/speechflow-node-xio-mqtt.js +1 -0
- package/dst/speechflow-node-xio-mqtt.js.map +1 -0
- package/dst/speechflow-node-xio-websocket.js +1 -0
- package/dst/speechflow-node-xio-websocket.js.map +1 -0
- package/dst/speechflow-node.d.ts +3 -0
- package/dst/speechflow-node.js +10 -0
- package/dst/speechflow-node.js.map +1 -0
- package/dst/speechflow-utils.d.ts +33 -0
- package/dst/speechflow-utils.js +183 -1
- package/dst/speechflow-utils.js.map +1 -0
- package/dst/speechflow.js +209 -6
- package/dst/speechflow.js.map +1 -0
- package/etc/speechflow.yaml +5 -3
- package/etc/stx.conf +1 -1
- package/etc/tsconfig.json +2 -2
- package/package.json +14 -8
- package/src/speechflow-node-a2a-meter.ts +125 -0
- package/src/speechflow-node-a2a-mute.ts +101 -0
- package/src/speechflow-node-a2a-vad.ts +266 -0
- package/src/speechflow-node-a2t-deepgram.ts +1 -1
- package/src/speechflow-node-t2t-transformers.ts +12 -7
- package/src/speechflow-node-xio-websocket.ts +5 -5
- package/src/speechflow-node.ts +12 -0
- package/src/speechflow-utils.ts +195 -0
- package/src/speechflow.ts +193 -6
- package/dst/speechflow-node-deepgram.d.ts +0 -12
- package/dst/speechflow-node-deepgram.js +0 -220
- package/dst/speechflow-node-deepl.d.ts +0 -12
- package/dst/speechflow-node-deepl.js +0 -128
- package/dst/speechflow-node-device.d.ts +0 -13
- package/dst/speechflow-node-device.js +0 -205
- package/dst/speechflow-node-elevenlabs.d.ts +0 -13
- package/dst/speechflow-node-elevenlabs.js +0 -182
- package/dst/speechflow-node-ffmpeg.d.ts +0 -13
- package/dst/speechflow-node-ffmpeg.js +0 -152
- package/dst/speechflow-node-file.d.ts +0 -11
- package/dst/speechflow-node-file.js +0 -176
- package/dst/speechflow-node-format.d.ts +0 -11
- package/dst/speechflow-node-format.js +0 -80
- package/dst/speechflow-node-gemma.js +0 -213
- package/dst/speechflow-node-mqtt.d.ts +0 -13
- package/dst/speechflow-node-mqtt.js +0 -181
- package/dst/speechflow-node-opus.d.ts +0 -12
- package/dst/speechflow-node-opus.js +0 -135
- package/dst/speechflow-node-subtitle.d.ts +0 -12
- package/dst/speechflow-node-subtitle.js +0 -96
- package/dst/speechflow-node-t2t-gemma.d.ts +0 -13
- package/dst/speechflow-node-t2t-gemma.js +0 -233
- package/dst/speechflow-node-t2t-opus.d.ts +0 -12
- package/dst/speechflow-node-t2t-opus.js +0 -135
- package/dst/speechflow-node-trace.d.ts +0 -11
- package/dst/speechflow-node-trace.js +0 -88
- package/dst/speechflow-node-wav.d.ts +0 -11
- package/dst/speechflow-node-wav.js +0 -170
- package/dst/speechflow-node-websocket.d.ts +0 -13
- package/dst/speechflow-node-websocket.js +0 -275
- package/dst/speechflow-node-whisper-common.d.ts +0 -34
- package/dst/speechflow-node-whisper-common.js +0 -7
- package/dst/speechflow-node-whisper-ggml.d.ts +0 -1
- package/dst/speechflow-node-whisper-ggml.js +0 -97
- package/dst/speechflow-node-whisper-onnx.d.ts +0 -1
- package/dst/speechflow-node-whisper-onnx.js +0 -131
- package/dst/speechflow-node-whisper-worker-ggml.d.ts +0 -1
- package/dst/speechflow-node-whisper-worker-ggml.js +0 -97
- package/dst/speechflow-node-whisper-worker-onnx.d.ts +0 -1
- package/dst/speechflow-node-whisper-worker-onnx.js +0 -131
- package/dst/speechflow-node-whisper-worker.d.ts +0 -1
- package/dst/speechflow-node-whisper-worker.js +0 -116
- package/dst/speechflow-node-whisper-worker2.d.ts +0 -1
- package/dst/speechflow-node-whisper-worker2.js +0 -82
- package/dst/speechflow-node-whisper.d.ts +0 -19
- package/dst/speechflow-node-whisper.js +0 -604
|
@@ -1,233 +0,0 @@
|
|
|
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 ollama_1 = require("ollama");
|
|
15
|
-
/* internal dependencies */
|
|
16
|
-
const speechflow_node_1 = __importDefault(require("./speechflow-node"));
|
|
17
|
-
/* SpeechFlow node for Gemma/Ollama text-to-text translation */
|
|
18
|
-
class SpeechFlowNodeGemma extends speechflow_node_1.default {
|
|
19
|
-
/* declare official node name */
|
|
20
|
-
static name = "gemma";
|
|
21
|
-
/* internal state */
|
|
22
|
-
ollama = null;
|
|
23
|
-
/* internal LLM setup */
|
|
24
|
-
setup = {
|
|
25
|
-
/* English (EN) spellchecking only */
|
|
26
|
-
"en-en": {
|
|
27
|
-
systemPrompt: "You are a proofreader and spellchecker for English.\n" +
|
|
28
|
-
"Output only the corrected text.\n" +
|
|
29
|
-
"Do NOT use markdown.\n" +
|
|
30
|
-
"Do NOT give any explanations.\n" +
|
|
31
|
-
"Do NOT give any introduction.\n" +
|
|
32
|
-
"Do NOT give any comments.\n" +
|
|
33
|
-
"Do NOT give any preamble.\n" +
|
|
34
|
-
"Do NOT give any prolog.\n" +
|
|
35
|
-
"Do NOT give any epilog.\n" +
|
|
36
|
-
"Do NOT change the gammar.\n" +
|
|
37
|
-
"Do NOT use synonyms for words.\n" +
|
|
38
|
-
"Keep all words.\n" +
|
|
39
|
-
"Fill in missing commas.\n" +
|
|
40
|
-
"Fill in missing points.\n" +
|
|
41
|
-
"Fill in missing question marks.\n" +
|
|
42
|
-
"Fill in missing hyphens.\n" +
|
|
43
|
-
"Focus ONLY on the word spelling.\n" +
|
|
44
|
-
"The text you have to correct is:\n",
|
|
45
|
-
chat: [
|
|
46
|
-
{ role: "user", content: "I luve my wyfe" },
|
|
47
|
-
{ role: "system", content: "I love my wife." },
|
|
48
|
-
{ role: "user", content: "The weether is wunderfull!" },
|
|
49
|
-
{ role: "system", content: "The weather is wonderful!" },
|
|
50
|
-
{ role: "user", content: "The live awesome but I'm hungry." },
|
|
51
|
-
{ role: "system", content: "The live is awesome, but I'm hungry." }
|
|
52
|
-
]
|
|
53
|
-
},
|
|
54
|
-
/* German (DE) spellchecking only */
|
|
55
|
-
"de-de": {
|
|
56
|
-
systemPrompt: "Du bist ein Korrekturleser und Rechtschreibprüfer für Deutsch.\n" +
|
|
57
|
-
"Gib nur den korrigierten Text aus.\n" +
|
|
58
|
-
"Benutze KEIN Markdown.\n" +
|
|
59
|
-
"Gib KEINE Erklärungen.\n" +
|
|
60
|
-
"Gib KEINE Einleitung.\n" +
|
|
61
|
-
"Gib KEINE Kommentare.\n" +
|
|
62
|
-
"Gib KEINE Preamble.\n" +
|
|
63
|
-
"Gib KEINEN Prolog.\n" +
|
|
64
|
-
"Gib KEINEN Epilog.\n" +
|
|
65
|
-
"Ändere NICHT die Grammatik.\n" +
|
|
66
|
-
"Verwende KEINE Synonyme für Wörter.\n" +
|
|
67
|
-
"Behalte alle Wörter bei.\n" +
|
|
68
|
-
"Füge fehlende Kommas ein.\n" +
|
|
69
|
-
"Füge fehlende Punkte ein.\n" +
|
|
70
|
-
"Füge fehlende Fragezeichen ein.\n" +
|
|
71
|
-
"Füge fehlende Bindestriche ein.\n" +
|
|
72
|
-
"Füge fehlende Gedankenstriche ein.\n" +
|
|
73
|
-
"Fokussiere dich NUR auf die Rechtschreibung der Wörter.\n" +
|
|
74
|
-
"Der von dir zu korrigierende Text ist:\n",
|
|
75
|
-
chat: [
|
|
76
|
-
{ role: "user", content: "Ich ljebe meine Frao" },
|
|
77
|
-
{ role: "system", content: "Ich liebe meine Frau." },
|
|
78
|
-
{ role: "user", content: "Die Wedter ist wunderschoen." },
|
|
79
|
-
{ role: "system", content: "Das Wetter ist wunderschön." },
|
|
80
|
-
{ role: "user", content: "Das Leben einfach großartig aber ich bin hungrig." },
|
|
81
|
-
{ role: "system", content: "Das Leben ist einfach großartig, aber ich bin hungrig." }
|
|
82
|
-
]
|
|
83
|
-
},
|
|
84
|
-
/* English (EN) to German (DE) translation */
|
|
85
|
-
"en-de": {
|
|
86
|
-
systemPrompt: "You are a translator.\n" +
|
|
87
|
-
"Output only the requested text.\n" +
|
|
88
|
-
"Do not use markdown.\n" +
|
|
89
|
-
"Do not chat.\n" +
|
|
90
|
-
"Do not show any explanations.\n" +
|
|
91
|
-
"Do not show any introduction.\n" +
|
|
92
|
-
"Do not show any preamble.\n" +
|
|
93
|
-
"Do not show any prolog.\n" +
|
|
94
|
-
"Do not show any epilog.\n" +
|
|
95
|
-
"Get to the point.\n" +
|
|
96
|
-
"Preserve the original meaning, tone, and nuance.\n" +
|
|
97
|
-
"Directly translate text from English (EN) to fluent and natural German (DE) language.\n",
|
|
98
|
-
chat: [
|
|
99
|
-
{ role: "user", content: "I love my wife." },
|
|
100
|
-
{ role: "system", content: "Ich liebe meine Frau." },
|
|
101
|
-
{ role: "user", content: "The weather is wonderful." },
|
|
102
|
-
{ role: "system", content: "Das Wetter ist wunderschön." },
|
|
103
|
-
{ role: "user", content: "The live is awesome." },
|
|
104
|
-
{ role: "system", content: "Das Leben ist einfach großartig." }
|
|
105
|
-
]
|
|
106
|
-
},
|
|
107
|
-
/* German (DE) to English (EN) translation */
|
|
108
|
-
"de-en": {
|
|
109
|
-
systemPrompt: "You are a translator.\n" +
|
|
110
|
-
"Output only the requested text.\n" +
|
|
111
|
-
"Do not use markdown.\n" +
|
|
112
|
-
"Do not chat.\n" +
|
|
113
|
-
"Do not show any explanations. \n" +
|
|
114
|
-
"Do not show any introduction.\n" +
|
|
115
|
-
"Do not show any preamble. \n" +
|
|
116
|
-
"Do not show any prolog. \n" +
|
|
117
|
-
"Do not show any epilog. \n" +
|
|
118
|
-
"Get to the point.\n" +
|
|
119
|
-
"Preserve the original meaning, tone, and nuance.\n" +
|
|
120
|
-
"Directly translate text from German (DE) to fluent and natural English (EN) language.\n",
|
|
121
|
-
chat: [
|
|
122
|
-
{ role: "user", content: "Ich liebe meine Frau." },
|
|
123
|
-
{ role: "system", content: "I love my wife." },
|
|
124
|
-
{ role: "user", content: "Das Wetter ist wunderschön." },
|
|
125
|
-
{ role: "system", content: "The weather is wonderful." },
|
|
126
|
-
{ role: "user", content: "Das Leben ist einfach großartig." },
|
|
127
|
-
{ role: "system", content: "The live is awesome." }
|
|
128
|
-
]
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
/* construct node */
|
|
132
|
-
constructor(id, cfg, opts, args) {
|
|
133
|
-
super(id, cfg, opts, args);
|
|
134
|
-
/* declare node configuration parameters */
|
|
135
|
-
this.configure({
|
|
136
|
-
api: { type: "string", val: "http://127.0.0.1:11434", match: /^https?:\/\/.+?:\d+$/ },
|
|
137
|
-
model: { type: "string", val: "gemma3:4b-it-q4_K_M", match: /^.+$/ },
|
|
138
|
-
src: { type: "string", pos: 0, val: "de", match: /^(?:de|en)$/ },
|
|
139
|
-
dst: { type: "string", pos: 1, val: "en", match: /^(?:de|en)$/ }
|
|
140
|
-
});
|
|
141
|
-
/* tell effective mode */
|
|
142
|
-
if (this.params.src === this.params.dst)
|
|
143
|
-
this.log("info", `Gemma/Ollama: operation mode: spellchecking for language "${this.params.src}"`);
|
|
144
|
-
else
|
|
145
|
-
this.log("info", `Gemma/Ollama: operation mode: translation from language "${this.params.src}"` +
|
|
146
|
-
` to language "${this.params.dst}"`);
|
|
147
|
-
/* declare node input/output format */
|
|
148
|
-
this.input = "text";
|
|
149
|
-
this.output = "text";
|
|
150
|
-
}
|
|
151
|
-
/* open node */
|
|
152
|
-
async open() {
|
|
153
|
-
/* instantiate Ollama API */
|
|
154
|
-
this.ollama = new ollama_1.Ollama({ host: this.params.api });
|
|
155
|
-
/* ensure the model is available */
|
|
156
|
-
const model = this.params.model;
|
|
157
|
-
const models = await this.ollama.list();
|
|
158
|
-
const exists = models.models.some((m) => m.name === model);
|
|
159
|
-
if (!exists) {
|
|
160
|
-
this.log("info", `Gemma/Ollama: model "${model}" still not present in Ollama -- ` +
|
|
161
|
-
"automatically downloading model");
|
|
162
|
-
await this.ollama.pull({ model });
|
|
163
|
-
}
|
|
164
|
-
else
|
|
165
|
-
this.log("info", `Gemma/Ollama: model "${model}" already present in Ollama`);
|
|
166
|
-
/* provide text-to-text translation */
|
|
167
|
-
const translate = async (text) => {
|
|
168
|
-
const key = `${this.params.src}-${this.params.dst}`;
|
|
169
|
-
const cfg = this.setup[key];
|
|
170
|
-
const response = await this.ollama.chat({
|
|
171
|
-
model,
|
|
172
|
-
messages: [
|
|
173
|
-
{ role: "system", content: cfg.systemPrompt },
|
|
174
|
-
...cfg.chat,
|
|
175
|
-
{ role: "user", content: text }
|
|
176
|
-
],
|
|
177
|
-
keep_alive: "10m",
|
|
178
|
-
options: {
|
|
179
|
-
repeat_penalty: 1.1,
|
|
180
|
-
temperature: 0.7,
|
|
181
|
-
seed: 1,
|
|
182
|
-
top_k: 10,
|
|
183
|
-
top_p: 0.5
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
return response.message.content;
|
|
187
|
-
};
|
|
188
|
-
/* establish a duplex stream and connect it to Ollama */
|
|
189
|
-
this.stream = new node_stream_1.default.Transform({
|
|
190
|
-
readableObjectMode: true,
|
|
191
|
-
writableObjectMode: true,
|
|
192
|
-
decodeStrings: false,
|
|
193
|
-
transform(chunk, encoding, callback) {
|
|
194
|
-
if (Buffer.isBuffer(chunk.payload))
|
|
195
|
-
callback(new Error("invalid chunk payload type"));
|
|
196
|
-
else {
|
|
197
|
-
if (chunk.payload === "") {
|
|
198
|
-
this.push(chunk);
|
|
199
|
-
callback();
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
translate(chunk.payload).then((payload) => {
|
|
203
|
-
const chunkNew = chunk.clone();
|
|
204
|
-
chunkNew.payload = payload;
|
|
205
|
-
this.push(chunkNew);
|
|
206
|
-
callback();
|
|
207
|
-
}).catch((err) => {
|
|
208
|
-
callback(err);
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
final(callback) {
|
|
214
|
-
this.push(null);
|
|
215
|
-
callback();
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
/* close node */
|
|
220
|
-
async close() {
|
|
221
|
-
/* close stream */
|
|
222
|
-
if (this.stream !== null) {
|
|
223
|
-
this.stream.destroy();
|
|
224
|
-
this.stream = null;
|
|
225
|
-
}
|
|
226
|
-
/* shutdown Ollama */
|
|
227
|
-
if (this.ollama !== null) {
|
|
228
|
-
this.ollama.abort();
|
|
229
|
-
this.ollama = null;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
exports.default = SpeechFlowNodeGemma;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import SpeechFlowNode from "./speechflow-node";
|
|
2
|
-
export default class SpeechFlowNodeOPUS extends SpeechFlowNode {
|
|
3
|
-
static name: string;
|
|
4
|
-
private translator;
|
|
5
|
-
constructor(id: string, cfg: {
|
|
6
|
-
[id: string]: any;
|
|
7
|
-
}, opts: {
|
|
8
|
-
[id: string]: any;
|
|
9
|
-
}, args: any[]);
|
|
10
|
-
open(): Promise<void>;
|
|
11
|
-
close(): Promise<void>;
|
|
12
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
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_path_1 = __importDefault(require("node:path"));
|
|
46
|
-
const node_stream_1 = __importDefault(require("node:stream"));
|
|
47
|
-
/* external dependencies */
|
|
48
|
-
const Transformers = __importStar(require("@huggingface/transformers"));
|
|
49
|
-
/* internal dependencies */
|
|
50
|
-
const speechflow_node_1 = __importDefault(require("./speechflow-node"));
|
|
51
|
-
/* SpeechFlow node for OPUS text-to-text translation */
|
|
52
|
-
class SpeechFlowNodeOPUS extends speechflow_node_1.default {
|
|
53
|
-
/* declare official node name */
|
|
54
|
-
static name = "opus";
|
|
55
|
-
/* internal state */
|
|
56
|
-
translator = null;
|
|
57
|
-
/* construct node */
|
|
58
|
-
constructor(id, cfg, opts, args) {
|
|
59
|
-
super(id, cfg, opts, args);
|
|
60
|
-
/* declare node configuration parameters */
|
|
61
|
-
this.configure({
|
|
62
|
-
src: { type: "string", pos: 0, val: "de", match: /^(?:de|en)$/ },
|
|
63
|
-
dst: { type: "string", pos: 1, val: "en", match: /^(?:de|en)$/ }
|
|
64
|
-
});
|
|
65
|
-
/* sanity check situation */
|
|
66
|
-
if (this.params.src === this.params.dst)
|
|
67
|
-
throw new Error("source and destination languages cannot be the same");
|
|
68
|
-
/* declare node input/output format */
|
|
69
|
-
this.input = "text";
|
|
70
|
-
this.output = "text";
|
|
71
|
-
}
|
|
72
|
-
/* open node */
|
|
73
|
-
async open() {
|
|
74
|
-
/* instantiate OPUS */
|
|
75
|
-
const model = `onnx-community/opus-mt-${this.params.src}-${this.params.dst}`;
|
|
76
|
-
this.translator = await Transformers.pipeline("translation", model, {
|
|
77
|
-
cache_dir: node_path_1.default.join(this.config.cacheDir, "opus"),
|
|
78
|
-
dtype: "q4",
|
|
79
|
-
device: "gpu"
|
|
80
|
-
});
|
|
81
|
-
if (this.translator === null)
|
|
82
|
-
throw new Error("failed to instantiate translator pipeline");
|
|
83
|
-
/* provide text-to-text translation */
|
|
84
|
-
const translate = async (text) => {
|
|
85
|
-
const result = await this.translator(text);
|
|
86
|
-
return Array.isArray(result) ?
|
|
87
|
-
result[0].translation_text :
|
|
88
|
-
result.translation_text;
|
|
89
|
-
};
|
|
90
|
-
/* establish a duplex stream and connect it to OPUS */
|
|
91
|
-
this.stream = new node_stream_1.default.Transform({
|
|
92
|
-
readableObjectMode: true,
|
|
93
|
-
writableObjectMode: true,
|
|
94
|
-
decodeStrings: false,
|
|
95
|
-
transform(chunk, encoding, callback) {
|
|
96
|
-
if (Buffer.isBuffer(chunk.payload))
|
|
97
|
-
callback(new Error("invalid chunk payload type"));
|
|
98
|
-
else {
|
|
99
|
-
if (chunk.payload === "") {
|
|
100
|
-
this.push(chunk);
|
|
101
|
-
callback();
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
translate(chunk.payload).then((payload) => {
|
|
105
|
-
const chunkNew = chunk.clone();
|
|
106
|
-
chunkNew.payload = payload;
|
|
107
|
-
this.push(chunkNew);
|
|
108
|
-
callback();
|
|
109
|
-
}).catch((err) => {
|
|
110
|
-
callback(err);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
final(callback) {
|
|
116
|
-
this.push(null);
|
|
117
|
-
callback();
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
/* close node */
|
|
122
|
-
async close() {
|
|
123
|
-
/* close stream */
|
|
124
|
-
if (this.stream !== null) {
|
|
125
|
-
this.stream.destroy();
|
|
126
|
-
this.stream = null;
|
|
127
|
-
}
|
|
128
|
-
/* shutdown OPUS */
|
|
129
|
-
if (this.translator !== null) {
|
|
130
|
-
this.translator.dispose();
|
|
131
|
-
this.translator = null;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
exports.default = SpeechFlowNodeOPUS;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import SpeechFlowNode from "./speechflow-node";
|
|
2
|
-
export default class SpeechFlowNodeTrace 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
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
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
|
-
/* internal dependencies */
|
|
14
|
-
const speechflow_node_1 = __importDefault(require("./speechflow-node"));
|
|
15
|
-
/* SpeechFlow node for data flow tracing */
|
|
16
|
-
class SpeechFlowNodeTrace extends speechflow_node_1.default {
|
|
17
|
-
/* declare official node name */
|
|
18
|
-
static name = "trace";
|
|
19
|
-
/* construct node */
|
|
20
|
-
constructor(id, cfg, opts, args) {
|
|
21
|
-
super(id, cfg, opts, args);
|
|
22
|
-
/* declare node configuration parameters */
|
|
23
|
-
this.configure({
|
|
24
|
-
type: { type: "string", pos: 0, val: "audio", match: /^(?:audio|text)$/ },
|
|
25
|
-
name: { type: "string", pos: 1 }
|
|
26
|
-
});
|
|
27
|
-
/* declare node input/output format */
|
|
28
|
-
this.input = this.params.type;
|
|
29
|
-
this.output = this.params.type;
|
|
30
|
-
}
|
|
31
|
-
/* open node */
|
|
32
|
-
async open() {
|
|
33
|
-
/* wrapper for local logging */
|
|
34
|
-
const log = (level, msg) => {
|
|
35
|
-
if (this.params.name !== undefined)
|
|
36
|
-
this.log(level, `[${this.params.name}]: ${msg}`);
|
|
37
|
-
else
|
|
38
|
-
this.log(level, msg);
|
|
39
|
-
};
|
|
40
|
-
/* provide Duplex stream and internally attach to Deepgram API */
|
|
41
|
-
const type = this.params.type;
|
|
42
|
-
this.stream = new node_stream_1.default.Transform({
|
|
43
|
-
writableObjectMode: true,
|
|
44
|
-
readableObjectMode: true,
|
|
45
|
-
decodeStrings: false,
|
|
46
|
-
transform(chunk, encoding, callback) {
|
|
47
|
-
let error;
|
|
48
|
-
const fmt = (t) => t.toFormat("hh:mm:ss.SSS");
|
|
49
|
-
if (Buffer.isBuffer(chunk.payload)) {
|
|
50
|
-
if (type === "audio")
|
|
51
|
-
log("info", `writing ${type} chunk: start=${fmt(chunk.timestampStart)} ` +
|
|
52
|
-
`end=${fmt(chunk.timestampEnd)} kind=${chunk.kind} type=${chunk.type} ` +
|
|
53
|
-
`payload-type=Buffer payload-bytes=${chunk.payload.byteLength}`);
|
|
54
|
-
else
|
|
55
|
-
error = new Error(`writing ${type} chunk: seen Buffer instead of String chunk type`);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
if (type === "text")
|
|
59
|
-
log("info", `writing ${type} chunk: start=${fmt(chunk.timestampStart)} ` +
|
|
60
|
-
`end=${fmt(chunk.timestampEnd)} kind=${chunk.kind} type=${chunk.type}` +
|
|
61
|
-
`payload-type=String payload-length=${chunk.payload.length} ` +
|
|
62
|
-
`payload-encoding=${encoding} payload-content="${chunk.payload.toString()}"`);
|
|
63
|
-
else
|
|
64
|
-
error = new Error(`writing ${type} chunk: seen String instead of Buffer chunk type`);
|
|
65
|
-
}
|
|
66
|
-
if (error !== undefined)
|
|
67
|
-
callback(error);
|
|
68
|
-
else {
|
|
69
|
-
this.push(chunk, encoding);
|
|
70
|
-
callback();
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
final(callback) {
|
|
74
|
-
this.push(null);
|
|
75
|
-
callback();
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
/* close node */
|
|
80
|
-
async close() {
|
|
81
|
-
/* close stream */
|
|
82
|
-
if (this.stream !== null) {
|
|
83
|
-
this.stream.destroy();
|
|
84
|
-
this.stream = null;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.default = SpeechFlowNodeTrace;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import SpeechFlowNode from "./speechflow-node";
|
|
2
|
-
export default class SpeechFlowNodeWAV 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
|
-
}
|
|
@@ -1,170 +0,0 @@
|
|
|
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 wav_1 = __importDefault(require("wav"));
|
|
48
|
-
/* internal dependencies */
|
|
49
|
-
const speechflow_node_1 = __importDefault(require("./speechflow-node"));
|
|
50
|
-
const utils = __importStar(require("./speechflow-utils"));
|
|
51
|
-
/* utility class for wrapping a custom stream into a regular Transform stream */
|
|
52
|
-
class StreamWrapper extends node_stream_1.default.Transform {
|
|
53
|
-
foreignStream;
|
|
54
|
-
constructor(foreignStream, options = {}) {
|
|
55
|
-
options.readableObjectMode = true;
|
|
56
|
-
options.writableObjectMode = true;
|
|
57
|
-
super(options);
|
|
58
|
-
this.foreignStream = foreignStream;
|
|
59
|
-
this.foreignStream.on("data", (chunk) => {
|
|
60
|
-
this.push(chunk);
|
|
61
|
-
});
|
|
62
|
-
this.foreignStream.on("error", (err) => {
|
|
63
|
-
this.emit("error", err);
|
|
64
|
-
});
|
|
65
|
-
this.foreignStream.on("end", () => {
|
|
66
|
-
this.push(null);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
_transform(chunk, encoding, callback) {
|
|
70
|
-
try {
|
|
71
|
-
const canContinue = this.foreignStream.write(chunk);
|
|
72
|
-
if (canContinue)
|
|
73
|
-
callback();
|
|
74
|
-
else
|
|
75
|
-
this.foreignStream.once("drain", callback);
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
callback(err);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
_flush(callback) {
|
|
82
|
-
try {
|
|
83
|
-
if (typeof this.foreignStream.end === "function")
|
|
84
|
-
this.foreignStream.end();
|
|
85
|
-
callback();
|
|
86
|
-
}
|
|
87
|
-
catch (err) {
|
|
88
|
-
callback(err);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
/* SpeechFlow node for WAV format conversion */
|
|
93
|
-
class SpeechFlowNodeWAV extends speechflow_node_1.default {
|
|
94
|
-
/* declare official node name */
|
|
95
|
-
static name = "wav";
|
|
96
|
-
/* construct node */
|
|
97
|
-
constructor(id, cfg, opts, args) {
|
|
98
|
-
super(id, cfg, opts, args);
|
|
99
|
-
/* declare node configuration parameters */
|
|
100
|
-
this.configure({
|
|
101
|
-
mode: { type: "string", pos: 1, val: "encode", match: /^(?:encode|decode)$/ }
|
|
102
|
-
});
|
|
103
|
-
/* declare node input/output format */
|
|
104
|
-
this.input = "audio";
|
|
105
|
-
this.output = "audio";
|
|
106
|
-
}
|
|
107
|
-
/* open node */
|
|
108
|
-
async open() {
|
|
109
|
-
if (this.params.mode === "encode") {
|
|
110
|
-
/* convert raw/PCM to WAV/PCM */
|
|
111
|
-
/* NOTICE: as this is a continuous stream, the resulting WAV header is not 100%
|
|
112
|
-
conforming to the WAV standard, as it has to use a zero duration information.
|
|
113
|
-
This cannot be changed in a stream-based processing. */
|
|
114
|
-
const writer = new wav_1.default.Writer({
|
|
115
|
-
format: 0x0001 /* PCM */,
|
|
116
|
-
channels: this.config.audioChannels,
|
|
117
|
-
sampleRate: this.config.audioSampleRate,
|
|
118
|
-
bitDepth: this.config.audioBitDepth
|
|
119
|
-
});
|
|
120
|
-
this.stream = new StreamWrapper(writer);
|
|
121
|
-
}
|
|
122
|
-
else if (this.params.mode === "decode") {
|
|
123
|
-
/* convert WAV/PCM to raw/PCM */
|
|
124
|
-
const reader = new wav_1.default.Reader();
|
|
125
|
-
reader.on("format", (format) => {
|
|
126
|
-
this.log("info", `WAV audio stream: format=${format.audioFormat === 0x0001 ? "PCM" :
|
|
127
|
-
"0x" + format.audioFormat.toString(16).padStart(4, "0")} ` +
|
|
128
|
-
`bitDepth=${format.bitDepth} ` +
|
|
129
|
-
`signed=${format.signed ? "yes" : "no"} ` +
|
|
130
|
-
`endian=${format.endianness} ` +
|
|
131
|
-
`sampleRate=${format.sampleRate} ` +
|
|
132
|
-
`channels=${format.channels}`);
|
|
133
|
-
if (format.audioFormat !== 0x0001 /* PCM */)
|
|
134
|
-
throw new Error("WAV not based on PCM format");
|
|
135
|
-
if (format.bitDepth !== 16)
|
|
136
|
-
throw new Error("WAV not based on 16 bit samples");
|
|
137
|
-
if (!format.signed)
|
|
138
|
-
throw new Error("WAV not based on signed integers");
|
|
139
|
-
if (format.endianness !== "LE")
|
|
140
|
-
throw new Error("WAV not based on little endianness");
|
|
141
|
-
if (format.sampleRate !== 48000)
|
|
142
|
-
throw new Error("WAV not based on 48Khz sample rate");
|
|
143
|
-
if (format.channels !== 1)
|
|
144
|
-
throw new Error("WAV not based on mono channel");
|
|
145
|
-
});
|
|
146
|
-
this.stream = new StreamWrapper(reader);
|
|
147
|
-
}
|
|
148
|
-
else
|
|
149
|
-
throw new Error(`invalid operation mode "${this.params.mode}"`);
|
|
150
|
-
/* convert regular stream into object-mode stream */
|
|
151
|
-
const wrapper1 = utils.createTransformStreamForWritableSide();
|
|
152
|
-
const wrapper2 = utils.createTransformStreamForReadableSide("audio", () => this.timeZero);
|
|
153
|
-
this.stream = node_stream_1.default.compose(wrapper1, this.stream, wrapper2);
|
|
154
|
-
}
|
|
155
|
-
/* close node */
|
|
156
|
-
async close() {
|
|
157
|
-
/* shutdown stream */
|
|
158
|
-
if (this.stream !== null) {
|
|
159
|
-
await new Promise((resolve) => {
|
|
160
|
-
if (this.stream instanceof node_stream_1.default.Duplex)
|
|
161
|
-
this.stream.end(() => { resolve(); });
|
|
162
|
-
else
|
|
163
|
-
resolve();
|
|
164
|
-
});
|
|
165
|
-
this.stream.destroy();
|
|
166
|
-
this.stream = null;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
exports.default = SpeechFlowNodeWAV;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import SpeechFlowNode from "./speechflow-node";
|
|
2
|
-
export default class SpeechFlowNodeWebsocket extends SpeechFlowNode {
|
|
3
|
-
static name: string;
|
|
4
|
-
private server;
|
|
5
|
-
private client;
|
|
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
|
-
}
|