speechflow 1.4.2 → 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.
Files changed (115) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/etc/stx.conf +17 -11
  3. package/package.json +7 -4
  4. package/speechflow-cli/dst/speechflow-node-a2a-ffmpeg.d.ts +13 -0
  5. package/speechflow-cli/dst/speechflow-node-a2a-ffmpeg.js +153 -0
  6. package/speechflow-cli/dst/speechflow-node-a2a-ffmpeg.js.map +1 -0
  7. package/speechflow-cli/dst/speechflow-node-a2a-gender.d.ts +20 -0
  8. package/speechflow-cli/dst/speechflow-node-a2a-gender.js +349 -0
  9. package/speechflow-cli/dst/speechflow-node-a2a-gender.js.map +1 -0
  10. package/speechflow-cli/dst/speechflow-node-a2a-meter.d.ts +16 -0
  11. package/speechflow-cli/dst/speechflow-node-a2a-meter.js +232 -0
  12. package/speechflow-cli/dst/speechflow-node-a2a-meter.js.map +1 -0
  13. package/speechflow-cli/dst/speechflow-node-a2a-mute.d.ts +17 -0
  14. package/speechflow-cli/dst/speechflow-node-a2a-mute.js +117 -0
  15. package/speechflow-cli/dst/speechflow-node-a2a-mute.js.map +1 -0
  16. package/speechflow-cli/dst/speechflow-node-a2a-vad.d.ts +19 -0
  17. package/speechflow-cli/dst/speechflow-node-a2a-vad.js +374 -0
  18. package/speechflow-cli/dst/speechflow-node-a2a-vad.js.map +1 -0
  19. package/speechflow-cli/dst/speechflow-node-a2a-wav.d.ts +11 -0
  20. package/speechflow-cli/dst/speechflow-node-a2a-wav.js +211 -0
  21. package/speechflow-cli/dst/speechflow-node-a2a-wav.js.map +1 -0
  22. package/speechflow-cli/dst/speechflow-node-a2t-deepgram.d.ts +19 -0
  23. package/speechflow-cli/dst/speechflow-node-a2t-deepgram.js +328 -0
  24. package/speechflow-cli/dst/speechflow-node-a2t-deepgram.js.map +1 -0
  25. package/speechflow-cli/dst/speechflow-node-t2a-elevenlabs.d.ts +18 -0
  26. package/speechflow-cli/dst/speechflow-node-t2a-elevenlabs.js +238 -0
  27. package/speechflow-cli/dst/speechflow-node-t2a-elevenlabs.js.map +1 -0
  28. package/speechflow-cli/dst/speechflow-node-t2a-kokoro.d.ts +14 -0
  29. package/speechflow-cli/dst/speechflow-node-t2a-kokoro.js +155 -0
  30. package/speechflow-cli/dst/speechflow-node-t2a-kokoro.js.map +1 -0
  31. package/speechflow-cli/dst/speechflow-node-t2t-deepl.d.ts +15 -0
  32. package/speechflow-cli/dst/speechflow-node-t2t-deepl.js +146 -0
  33. package/speechflow-cli/dst/speechflow-node-t2t-deepl.js.map +1 -0
  34. package/speechflow-cli/dst/speechflow-node-t2t-format.d.ts +11 -0
  35. package/speechflow-cli/dst/speechflow-node-t2t-format.js +82 -0
  36. package/speechflow-cli/dst/speechflow-node-t2t-format.js.map +1 -0
  37. package/speechflow-cli/dst/speechflow-node-t2t-ollama.d.ts +13 -0
  38. package/speechflow-cli/dst/speechflow-node-t2t-ollama.js +247 -0
  39. package/speechflow-cli/dst/speechflow-node-t2t-ollama.js.map +1 -0
  40. package/speechflow-cli/dst/speechflow-node-t2t-openai.d.ts +13 -0
  41. package/speechflow-cli/dst/speechflow-node-t2t-openai.js +227 -0
  42. package/speechflow-cli/dst/speechflow-node-t2t-openai.js.map +1 -0
  43. package/speechflow-cli/dst/speechflow-node-t2t-sentence.d.ts +17 -0
  44. package/speechflow-cli/dst/speechflow-node-t2t-sentence.js +250 -0
  45. package/speechflow-cli/dst/speechflow-node-t2t-sentence.js.map +1 -0
  46. package/speechflow-cli/dst/speechflow-node-t2t-subtitle.d.ts +13 -0
  47. package/speechflow-cli/dst/speechflow-node-t2t-subtitle.js +278 -0
  48. package/speechflow-cli/dst/speechflow-node-t2t-subtitle.js.map +1 -0
  49. package/speechflow-cli/dst/speechflow-node-t2t-transformers.d.ts +14 -0
  50. package/speechflow-cli/dst/speechflow-node-t2t-transformers.js +265 -0
  51. package/speechflow-cli/dst/speechflow-node-t2t-transformers.js.map +1 -0
  52. package/speechflow-cli/dst/speechflow-node-x2x-filter.d.ts +11 -0
  53. package/speechflow-cli/dst/speechflow-node-x2x-filter.js +121 -0
  54. package/speechflow-cli/dst/speechflow-node-x2x-filter.js.map +1 -0
  55. package/speechflow-cli/dst/speechflow-node-x2x-trace.d.ts +11 -0
  56. package/speechflow-cli/dst/speechflow-node-x2x-trace.js +111 -0
  57. package/speechflow-cli/dst/speechflow-node-x2x-trace.js.map +1 -0
  58. package/speechflow-cli/dst/speechflow-node-xio-device.d.ts +13 -0
  59. package/speechflow-cli/dst/speechflow-node-xio-device.js +230 -0
  60. package/speechflow-cli/dst/speechflow-node-xio-device.js.map +1 -0
  61. package/speechflow-cli/dst/speechflow-node-xio-file.d.ts +11 -0
  62. package/speechflow-cli/dst/speechflow-node-xio-file.js +216 -0
  63. package/speechflow-cli/dst/speechflow-node-xio-file.js.map +1 -0
  64. package/speechflow-cli/dst/speechflow-node-xio-mqtt.d.ts +13 -0
  65. package/speechflow-cli/dst/speechflow-node-xio-mqtt.js +188 -0
  66. package/speechflow-cli/dst/speechflow-node-xio-mqtt.js.map +1 -0
  67. package/speechflow-cli/dst/speechflow-node-xio-websocket.d.ts +13 -0
  68. package/speechflow-cli/dst/speechflow-node-xio-websocket.js +278 -0
  69. package/speechflow-cli/dst/speechflow-node-xio-websocket.js.map +1 -0
  70. package/speechflow-cli/dst/speechflow-node.d.ts +65 -0
  71. package/speechflow-cli/dst/speechflow-node.js +180 -0
  72. package/speechflow-cli/dst/speechflow-node.js.map +1 -0
  73. package/speechflow-cli/dst/speechflow-utils.d.ts +74 -0
  74. package/speechflow-cli/dst/speechflow-utils.js +519 -0
  75. package/speechflow-cli/dst/speechflow-utils.js.map +1 -0
  76. package/speechflow-cli/dst/speechflow.d.ts +7 -0
  77. package/speechflow-cli/dst/speechflow.js +837 -0
  78. package/speechflow-cli/dst/speechflow.js.map +1 -0
  79. package/speechflow-cli/etc/stx.conf +13 -13
  80. package/speechflow-cli/package.json +7 -7
  81. package/speechflow-cli/src/speechflow.ts +5 -5
  82. package/speechflow-ui-db/dst/app-font-TypoPRO-SourceSansPro-Bold.eot +0 -0
  83. package/speechflow-ui-db/dst/app-font-TypoPRO-SourceSansPro-Bold.ttf +0 -0
  84. package/speechflow-ui-db/dst/app-font-TypoPRO-SourceSansPro-Bold.woff +0 -0
  85. package/speechflow-ui-db/dst/app-font-TypoPRO-SourceSansPro-Regular.eot +0 -0
  86. package/speechflow-ui-db/dst/app-font-TypoPRO-SourceSansPro-Regular.ttf +0 -0
  87. package/speechflow-ui-db/dst/app-font-TypoPRO-SourceSansPro-Regular.woff +0 -0
  88. package/speechflow-ui-db/dst/app-font-fa-brands-400.woff2 +0 -0
  89. package/speechflow-ui-db/dst/app-font-fa-regular-400.woff2 +0 -0
  90. package/speechflow-ui-db/dst/app-font-fa-solid-900.woff2 +0 -0
  91. package/speechflow-ui-db/dst/app-font-fa-v4compatibility.woff2 +0 -0
  92. package/speechflow-ui-db/dst/app-icon.svg +26 -0
  93. package/speechflow-ui-db/dst/index.css +5 -0
  94. package/speechflow-ui-db/dst/index.html +24 -0
  95. package/speechflow-ui-db/dst/index.js +616 -0
  96. package/speechflow-ui-db/etc/stx.conf +17 -17
  97. package/speechflow-ui-db/package.json +2 -2
  98. package/speechflow-ui-db/src/app.vue +14 -7
  99. package/speechflow-ui-st/dst/app-font-TypoPRO-SourceSansPro-Bold.eot +0 -0
  100. package/speechflow-ui-st/dst/app-font-TypoPRO-SourceSansPro-Bold.ttf +0 -0
  101. package/speechflow-ui-st/dst/app-font-TypoPRO-SourceSansPro-Bold.woff +0 -0
  102. package/speechflow-ui-st/dst/app-font-TypoPRO-SourceSansPro-Regular.eot +0 -0
  103. package/speechflow-ui-st/dst/app-font-TypoPRO-SourceSansPro-Regular.ttf +0 -0
  104. package/speechflow-ui-st/dst/app-font-TypoPRO-SourceSansPro-Regular.woff +0 -0
  105. package/speechflow-ui-st/dst/app-font-fa-brands-400.woff2 +0 -0
  106. package/speechflow-ui-st/dst/app-font-fa-regular-400.woff2 +0 -0
  107. package/speechflow-ui-st/dst/app-font-fa-solid-900.woff2 +0 -0
  108. package/speechflow-ui-st/dst/app-font-fa-v4compatibility.woff2 +0 -0
  109. package/speechflow-ui-st/dst/app-icon.svg +26 -0
  110. package/speechflow-ui-st/dst/index.css +5 -0
  111. package/speechflow-ui-st/dst/index.html +24 -0
  112. package/speechflow-ui-st/dst/index.js +610 -0
  113. package/speechflow-ui-st/etc/stx.conf +17 -17
  114. package/speechflow-ui-st/package.json +2 -2
  115. /package/{speechflow-cli/etc → etc}/speechflow.yaml +0 -0
@@ -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;AAEnE,mDAAmD;AACnD,MAAqB,oBAAqB,SAAQ,yBAAc;IAC5D,kCAAkC;IAC3B,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAA;IAE7B,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,KAAK,E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AAI,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
+ }
@@ -0,0 +1,247 @@
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 Ollama text-to-text translation */
18
+ class SpeechFlowNodeOllama extends speechflow_node_1.default {
19
+ /* declare official node name */
20
+ static name = "ollama";
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 grammar.\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", `Ollama: operation mode: spellchecking for language "${this.params.src}"`);
144
+ else
145
+ this.log("info", `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", `Ollama: model "${model}" still not present in Ollama -- ` +
161
+ "automatically downloading model");
162
+ let artifact = "";
163
+ let percent = 0;
164
+ const interval = setInterval(() => {
165
+ this.log("info", `downloaded ${percent.toFixed(2)}% of artifact "${artifact}"`);
166
+ }, 1000);
167
+ const progress = await this.ollama.pull({ model, stream: true });
168
+ for await (const event of progress) {
169
+ if (event.digest)
170
+ artifact = event.digest;
171
+ if (event.completed && event.total)
172
+ percent = (event.completed / event.total) * 100;
173
+ }
174
+ clearInterval(interval);
175
+ }
176
+ else
177
+ this.log("info", `Ollama: model "${model}" already present in Ollama`);
178
+ /* provide text-to-text translation */
179
+ const translate = async (text) => {
180
+ const key = `${this.params.src}-${this.params.dst}`;
181
+ const cfg = this.setup[key];
182
+ const response = await this.ollama.chat({
183
+ model,
184
+ messages: [
185
+ { role: "system", content: cfg.systemPrompt },
186
+ ...cfg.chat,
187
+ { role: "user", content: text }
188
+ ],
189
+ keep_alive: "10m",
190
+ options: {
191
+ repeat_penalty: 1.1,
192
+ temperature: 0.7,
193
+ seed: 1,
194
+ top_k: 10,
195
+ top_p: 0.5
196
+ }
197
+ });
198
+ return response.message.content;
199
+ };
200
+ /* establish a duplex stream and connect it to Ollama */
201
+ this.stream = new node_stream_1.default.Transform({
202
+ readableObjectMode: true,
203
+ writableObjectMode: true,
204
+ decodeStrings: false,
205
+ highWaterMark: 1,
206
+ transform(chunk, encoding, callback) {
207
+ if (Buffer.isBuffer(chunk.payload))
208
+ callback(new Error("invalid chunk payload type"));
209
+ else {
210
+ if (chunk.payload === "") {
211
+ this.push(chunk);
212
+ callback();
213
+ }
214
+ else {
215
+ translate(chunk.payload).then((payload) => {
216
+ const chunkNew = chunk.clone();
217
+ chunkNew.payload = payload;
218
+ this.push(chunkNew);
219
+ callback();
220
+ }).catch((err) => {
221
+ callback(err);
222
+ });
223
+ }
224
+ }
225
+ },
226
+ final(callback) {
227
+ this.push(null);
228
+ callback();
229
+ }
230
+ });
231
+ }
232
+ /* close node */
233
+ async close() {
234
+ /* close stream */
235
+ if (this.stream !== null) {
236
+ this.stream.destroy();
237
+ this.stream = null;
238
+ }
239
+ /* shutdown Ollama */
240
+ if (this.ollama !== null) {
241
+ this.ollama.abort();
242
+ this.ollama = null;
243
+ }
244
+ }
245
+ }
246
+ exports.default = SpeechFlowNodeOllama;
247
+ //# sourceMappingURL=speechflow-node-t2t-ollama.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speechflow-node-t2t-ollama.js","sourceRoot":"","sources":["../src/speechflow-node-t2t-ollama.ts"],"names":[],"mappings":";AAAA;;;;EAIE;;;;;AAEF,6BAA6B;AAC7B,8DAAoC;AAEpC,6BAA6B;AAC7B,mCAA+B;AAE/B,6BAA6B;AAC7B,wEAAmE;AAMnE,2DAA2D;AAC3D,MAAqB,oBAAqB,SAAQ,yBAAc;IAC5D,kCAAkC;IAC3B,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAA;IAE7B,sBAAsB;IACd,MAAM,GAAkB,IAAI,CAAA;IAEpC,0BAA0B;IAClB,KAAK,GAAW;QACpB,uCAAuC;QACvC,OAAO,EAAE;YACL,YAAY,EACR,uDAAuD;gBACvD,mCAAmC;gBACnC,wBAAwB;gBACxB,iCAAiC;gBACjC,iCAAiC;gBACjC,6BAA6B;gBAC7B,6BAA6B;gBAC7B,2BAA2B;gBAC3B,2BAA2B;gBAC3B,8BAA8B;gBAC9B,kCAAkC;gBAClC,mBAAmB;gBACnB,2BAA2B;gBAC3B,2BAA2B;gBAC3B,mCAAmC;gBACnC,4BAA4B;gBAC5B,oCAAoC;gBACpC,oCAAoC;YACxC,IAAI,EAAE;gBACF,EAAE,IAAI,EAAE,MAAM,EAAI,OAAO,EAAE,gBAAgB,EAAE;gBAC7C,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,EAAE;gBAC9C,EAAE,IAAI,EAAE,MAAM,EAAI,OAAO,EAAE,4BAA4B,EAAE;gBACzD,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,2BAA2B,EAAE;gBACxD,EAAE,IAAI,EAAE,MAAM,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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,uBAAuB;QACvB,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;YACnB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;QACtB,CAAC;IACL,CAAC;;AArPL,uCAsPC"}
@@ -0,0 +1,13 @@
1
+ import SpeechFlowNode from "./speechflow-node";
2
+ export default class SpeechFlowNodeOpenAI extends SpeechFlowNode {
3
+ static name: string;
4
+ private openai;
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
+ }
@@ -0,0 +1,227 @@
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 openai_1 = __importDefault(require("openai"));
15
+ /* internal dependencies */
16
+ const speechflow_node_1 = __importDefault(require("./speechflow-node"));
17
+ /* SpeechFlow node for OpenAI/GPT text-to-text translation */
18
+ class SpeechFlowNodeOpenAI extends speechflow_node_1.default {
19
+ /* declare official node name */
20
+ static name = "openai";
21
+ /* internal state */
22
+ openai = 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 grammar.\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
+ src: { type: "string", pos: 0, val: "de", match: /^(?:de|en)$/ },
137
+ dst: { type: "string", pos: 1, val: "en", match: /^(?:de|en)$/ },
138
+ key: { type: "string", val: process.env.SPEECHFLOW_OPENAI_KEY },
139
+ api: { type: "string", val: "https://api.openai.com/v1", match: /^https?:\/\/.+?:\d+$/ },
140
+ model: { type: "string", val: "gpt-4o-mini" }
141
+ });
142
+ /* tell effective mode */
143
+ if (this.params.src === this.params.dst)
144
+ this.log("info", `OpenAI: operation mode: spellchecking for language "${this.params.src}"`);
145
+ else
146
+ this.log("info", `OpenAI: operation mode: translation from language "${this.params.src}"` +
147
+ ` to language "${this.params.dst}"`);
148
+ /* declare node input/output format */
149
+ this.input = "text";
150
+ this.output = "text";
151
+ }
152
+ /* open node */
153
+ async open() {
154
+ /* instantiate OpenAI API */
155
+ this.openai = new openai_1.default({
156
+ baseURL: this.params.api,
157
+ apiKey: this.params.key,
158
+ dangerouslyAllowBrowser: true
159
+ });
160
+ /* provide text-to-text translation */
161
+ const translate = async (text) => {
162
+ const key = `${this.params.src}-${this.params.dst}`;
163
+ const cfg = this.setup[key];
164
+ const stream = this.openai.chat.completions.stream({
165
+ stream: true,
166
+ model: this.params.model,
167
+ seed: null,
168
+ temperature: 0.7,
169
+ n: 1,
170
+ messages: [
171
+ { role: "system", content: cfg.systemPrompt },
172
+ ...cfg.chat,
173
+ { role: "user", content: text }
174
+ ]
175
+ });
176
+ const completion = await stream.finalChatCompletion();
177
+ const translation = completion.choices[0].message.content;
178
+ if (!stream.ended)
179
+ stream.abort();
180
+ return translation;
181
+ };
182
+ /* establish a duplex stream and connect it to OpenAI */
183
+ this.stream = new node_stream_1.default.Transform({
184
+ readableObjectMode: true,
185
+ writableObjectMode: true,
186
+ decodeStrings: false,
187
+ highWaterMark: 1,
188
+ transform(chunk, encoding, callback) {
189
+ if (Buffer.isBuffer(chunk.payload))
190
+ callback(new Error("invalid chunk payload type"));
191
+ else {
192
+ if (chunk.payload === "") {
193
+ this.push(chunk);
194
+ callback();
195
+ }
196
+ else {
197
+ translate(chunk.payload).then((payload) => {
198
+ const chunkNew = chunk.clone();
199
+ chunkNew.payload = payload;
200
+ this.push(chunkNew);
201
+ callback();
202
+ }).catch((err) => {
203
+ callback(err);
204
+ });
205
+ }
206
+ }
207
+ },
208
+ final(callback) {
209
+ this.push(null);
210
+ callback();
211
+ }
212
+ });
213
+ }
214
+ /* close node */
215
+ async close() {
216
+ /* close stream */
217
+ if (this.stream !== null) {
218
+ this.stream.destroy();
219
+ this.stream = null;
220
+ }
221
+ /* shutdown OpenAI */
222
+ if (this.openai !== null)
223
+ this.openai = null;
224
+ }
225
+ }
226
+ exports.default = SpeechFlowNodeOpenAI;
227
+ //# sourceMappingURL=speechflow-node-t2t-openai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speechflow-node-t2t-openai.js","sourceRoot":"","sources":["../src/speechflow-node-t2t-openai.ts"],"names":[],"mappings":";AAAA;;;;EAIE;;;;;AAEF,6BAA6B;AAC7B,8DAAgC;AAEhC,6BAA6B;AAC7B,oDAA2B;AAE3B,6BAA6B;AAC7B,wEAAmE;AAMnE,+DAA+D;AAC/D,MAAqB,oBAAqB,SAAQ,yBAAc;IAC5D,kCAAkC;IAC3B,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAA;IAE7B,sBAAsB;IACd,MAAM,GAAkB,IAAI,CAAA;IAEpC,0BAA0B;IAClB,KAAK,GAAW;QACpB,uCAAuC;QACvC,OAAO,EAAE;YACL,YAAY,EACR,uDAAuD;gBACvD,mCAAmC;gBACnC,wBAAwB;gBACxB,iCAAiC;gBACjC,iCAAiC;gBACjC,6BAA6B;gBAC7B,6BAA6B;gBAC7B,2BAA2B;gBAC3B,2BAA2B;gBAC3B,8BAA8B;gBAC9B,kCAAkC;gBAClC,mBAAmB;gBACnB,2BAA2B;gBAC3B,2BAA2B;gBAC3B,mCAAmC;gBACnC,4BAA4B;gBAC5B,oCAAoC;gBACpC,oCAAoC;YACxC,IAAI,EAAE;gBACF,EAAE,IAAI,EAAE,MAAM,EAAI,OAAO,EAAE,gBAAgB,EAAE;gBAC7C,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,EAAE;gBAC9C,EAAE,IAAI,EAAE,MAAM,EAAI,OAAO,EAAE,4BAA4B,EAAE;gBACzD,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,2BAA2B,EAAE;gBACxD,EAAE,IAAI,EAAE,MAAM,EAAI,OAAO,EAAE,kCAAkC,EAAE;gBAC/D,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,sCAAsC,EAAE;aACtE;SACJ;QAED,sCAAsC;QACtC,OAAO,EAAE;YACL,YAAY,EACR,kE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d,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,uBAAuB;QACvB,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI;YACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;IAC1B,CAAC;;AAhOL,uCAiOC"}
@@ -0,0 +1,17 @@
1
+ import SpeechFlowNode from "./speechflow-node";
2
+ export default class SpeechFlowNodeSentence extends SpeechFlowNode {
3
+ static name: string;
4
+ private queue;
5
+ private queueRecv;
6
+ private queueSplit;
7
+ private queueSend;
8
+ private destroyed;
9
+ private workingOffTimer;
10
+ constructor(id: string, cfg: {
11
+ [id: string]: any;
12
+ }, opts: {
13
+ [id: string]: any;
14
+ }, args: any[]);
15
+ open(): Promise<void>;
16
+ close(): Promise<void>;
17
+ }