speechflow 0.9.8 → 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.
Files changed (114) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/LICENSE.txt +674 -0
  3. package/README.md +114 -17
  4. package/dst/speechflow-node-a2a-ffmpeg.js +1 -0
  5. package/dst/speechflow-node-a2a-ffmpeg.js.map +1 -0
  6. package/dst/{speechflow-node-deepl.d.ts → speechflow-node-a2a-meter.d.ts} +2 -2
  7. package/dst/speechflow-node-a2a-meter.js +147 -0
  8. package/dst/speechflow-node-a2a-meter.js.map +1 -0
  9. package/dst/speechflow-node-a2a-mute.d.ts +16 -0
  10. package/dst/speechflow-node-a2a-mute.js +90 -0
  11. package/dst/speechflow-node-a2a-mute.js.map +1 -0
  12. package/dst/{speechflow-node-whisper.d.ts → speechflow-node-a2a-vad.d.ts} +2 -5
  13. package/dst/speechflow-node-a2a-vad.js +272 -0
  14. package/dst/speechflow-node-a2a-vad.js.map +1 -0
  15. package/dst/speechflow-node-a2a-wav.js +1 -0
  16. package/dst/speechflow-node-a2a-wav.js.map +1 -0
  17. package/dst/speechflow-node-a2t-deepgram.js +2 -1
  18. package/dst/speechflow-node-a2t-deepgram.js.map +1 -0
  19. package/dst/speechflow-node-t2a-elevenlabs.js +1 -0
  20. package/dst/speechflow-node-t2a-elevenlabs.js.map +1 -0
  21. package/dst/{speechflow-node-elevenlabs.d.ts → speechflow-node-t2a-kokoro.d.ts} +2 -2
  22. package/dst/speechflow-node-t2a-kokoro.js +148 -0
  23. package/dst/speechflow-node-t2a-kokoro.js.map +1 -0
  24. package/dst/speechflow-node-t2t-deepl.js +1 -0
  25. package/dst/speechflow-node-t2t-deepl.js.map +1 -0
  26. package/dst/speechflow-node-t2t-format.js +1 -0
  27. package/dst/speechflow-node-t2t-format.js.map +1 -0
  28. package/dst/{speechflow-node-gemma.d.ts → speechflow-node-t2t-ollama.d.ts} +1 -1
  29. package/dst/{speechflow-node-gemma.js → speechflow-node-t2t-ollama.js} +41 -8
  30. package/dst/speechflow-node-t2t-ollama.js.map +1 -0
  31. package/dst/{speechflow-node-t2t-gemma.d.ts → speechflow-node-t2t-openai.d.ts} +2 -2
  32. package/dst/{speechflow-node-t2t-gemma.js → speechflow-node-t2t-openai.js} +43 -30
  33. package/dst/speechflow-node-t2t-openai.js.map +1 -0
  34. package/dst/speechflow-node-t2t-subtitle.js +1 -0
  35. package/dst/speechflow-node-t2t-subtitle.js.map +1 -0
  36. package/dst/{speechflow-node-opus.d.ts → speechflow-node-t2t-transformers.d.ts} +3 -1
  37. package/dst/speechflow-node-t2t-transformers.js +264 -0
  38. package/dst/speechflow-node-t2t-transformers.js.map +1 -0
  39. package/dst/speechflow-node-x2x-trace.js +3 -2
  40. package/dst/speechflow-node-x2x-trace.js.map +1 -0
  41. package/dst/speechflow-node-xio-device.js +1 -0
  42. package/dst/speechflow-node-xio-device.js.map +1 -0
  43. package/dst/speechflow-node-xio-file.js +1 -0
  44. package/dst/speechflow-node-xio-file.js.map +1 -0
  45. package/dst/speechflow-node-xio-mqtt.js +1 -0
  46. package/dst/speechflow-node-xio-mqtt.js.map +1 -0
  47. package/dst/speechflow-node-xio-websocket.js +1 -0
  48. package/dst/speechflow-node-xio-websocket.js.map +1 -0
  49. package/dst/speechflow-node.d.ts +3 -0
  50. package/dst/speechflow-node.js +10 -0
  51. package/dst/speechflow-node.js.map +1 -0
  52. package/dst/speechflow-utils.d.ts +33 -0
  53. package/dst/speechflow-utils.js +183 -1
  54. package/dst/speechflow-utils.js.map +1 -0
  55. package/dst/speechflow.js +295 -46
  56. package/dst/speechflow.js.map +1 -0
  57. package/etc/speechflow.yaml +14 -5
  58. package/etc/stx.conf +1 -1
  59. package/etc/tsconfig.json +2 -2
  60. package/package.json +17 -10
  61. package/src/speechflow-node-a2a-meter.ts +125 -0
  62. package/src/speechflow-node-a2a-mute.ts +101 -0
  63. package/src/speechflow-node-a2a-vad.ts +266 -0
  64. package/src/speechflow-node-a2t-deepgram.ts +1 -1
  65. package/src/speechflow-node-t2a-kokoro.ts +160 -0
  66. package/src/{speechflow-node-t2t-gemma.ts → speechflow-node-t2t-ollama.ts} +44 -10
  67. package/src/speechflow-node-t2t-openai.ts +246 -0
  68. package/src/speechflow-node-t2t-transformers.ts +249 -0
  69. package/src/speechflow-node-x2x-trace.ts +2 -2
  70. package/src/speechflow-node-xio-websocket.ts +5 -5
  71. package/src/speechflow-node.ts +12 -0
  72. package/src/speechflow-utils.ts +195 -0
  73. package/src/speechflow.ts +279 -46
  74. package/dst/speechflow-node-deepgram.d.ts +0 -12
  75. package/dst/speechflow-node-deepgram.js +0 -220
  76. package/dst/speechflow-node-deepl.js +0 -128
  77. package/dst/speechflow-node-device.d.ts +0 -13
  78. package/dst/speechflow-node-device.js +0 -205
  79. package/dst/speechflow-node-elevenlabs.js +0 -182
  80. package/dst/speechflow-node-ffmpeg.d.ts +0 -13
  81. package/dst/speechflow-node-ffmpeg.js +0 -152
  82. package/dst/speechflow-node-file.d.ts +0 -11
  83. package/dst/speechflow-node-file.js +0 -176
  84. package/dst/speechflow-node-format.d.ts +0 -11
  85. package/dst/speechflow-node-format.js +0 -80
  86. package/dst/speechflow-node-mqtt.d.ts +0 -13
  87. package/dst/speechflow-node-mqtt.js +0 -181
  88. package/dst/speechflow-node-opus.js +0 -135
  89. package/dst/speechflow-node-subtitle.d.ts +0 -12
  90. package/dst/speechflow-node-subtitle.js +0 -96
  91. package/dst/speechflow-node-t2t-opus.d.ts +0 -12
  92. package/dst/speechflow-node-t2t-opus.js +0 -135
  93. package/dst/speechflow-node-trace.d.ts +0 -11
  94. package/dst/speechflow-node-trace.js +0 -88
  95. package/dst/speechflow-node-wav.d.ts +0 -11
  96. package/dst/speechflow-node-wav.js +0 -170
  97. package/dst/speechflow-node-websocket.d.ts +0 -13
  98. package/dst/speechflow-node-websocket.js +0 -275
  99. package/dst/speechflow-node-whisper-common.d.ts +0 -34
  100. package/dst/speechflow-node-whisper-common.js +0 -7
  101. package/dst/speechflow-node-whisper-ggml.d.ts +0 -1
  102. package/dst/speechflow-node-whisper-ggml.js +0 -97
  103. package/dst/speechflow-node-whisper-onnx.d.ts +0 -1
  104. package/dst/speechflow-node-whisper-onnx.js +0 -131
  105. package/dst/speechflow-node-whisper-worker-ggml.d.ts +0 -1
  106. package/dst/speechflow-node-whisper-worker-ggml.js +0 -97
  107. package/dst/speechflow-node-whisper-worker-onnx.d.ts +0 -1
  108. package/dst/speechflow-node-whisper-worker-onnx.js +0 -131
  109. package/dst/speechflow-node-whisper-worker.d.ts +0 -1
  110. package/dst/speechflow-node-whisper-worker.js +0 -116
  111. package/dst/speechflow-node-whisper-worker2.d.ts +0 -1
  112. package/dst/speechflow-node-whisper-worker2.js +0 -82
  113. package/dst/speechflow-node-whisper.js +0 -604
  114. package/src/speechflow-node-t2t-opus.ts +0 -111
@@ -1,181 +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 mqtt_1 = __importDefault(require("mqtt"));
48
- const pure_uuid_1 = __importDefault(require("pure-uuid"));
49
- /* internal dependencies */
50
- const speechflow_node_1 = __importDefault(require("./speechflow-node"));
51
- const utils = __importStar(require("./speechflow-utils"));
52
- /* SpeechFlow node for MQTT networking */
53
- class SpeechFlowNodeMQTT extends speechflow_node_1.default {
54
- /* declare official node name */
55
- static name = "mqtt";
56
- /* internal state */
57
- broker = null;
58
- clientId = (new pure_uuid_1.default(1)).format();
59
- /* construct node */
60
- constructor(id, cfg, opts, args) {
61
- super(id, cfg, opts, args);
62
- /* declare node configuration parameters */
63
- this.configure({
64
- url: { type: "string", pos: 0, val: "", match: /^(?:|(?:ws|mqtt):\/\/(.+?):(\d+)(?:\/.*)?)$/ },
65
- username: { type: "string", pos: 1, val: "", match: /^.+$/ },
66
- password: { type: "string", pos: 2, val: "", match: /^.+$/ },
67
- topicRead: { type: "string", pos: 3, val: "", match: /^.+$/ },
68
- topicWrite: { type: "string", pos: 4, val: "", match: /^.+$/ },
69
- mode: { type: "string", pos: 5, val: "w", match: /^(?:r|w|rw)$/ },
70
- type: { type: "string", pos: 6, val: "text", match: /^(?:audio|text)$/ }
71
- });
72
- /* logical parameter sanity check */
73
- if ((this.params.mode === "w" || this.params.mode === "rw") && this.params.topicWrite === "")
74
- throw new Error("writing to MQTT requires a topicWrite parameter");
75
- if ((this.params.mode === "r" || this.params.mode === "rw") && this.params.topicRead === "")
76
- throw new Error("reading from MQTT requires a topicRead parameter");
77
- /* declare node input/output format */
78
- if (this.params.mode === "rw") {
79
- this.input = this.params.type;
80
- this.output = this.params.type;
81
- }
82
- else if (this.params.mode === "r") {
83
- this.input = "none";
84
- this.output = this.params.type;
85
- }
86
- else if (this.params.mode === "w") {
87
- this.input = this.params.type;
88
- this.output = "none";
89
- }
90
- }
91
- /* open node */
92
- async open() {
93
- /* connect remotely to a MQTT broker */
94
- this.broker = mqtt_1.default.connect(this.params.url, {
95
- protocolId: "MQTT",
96
- protocolVersion: 5,
97
- username: this.params.username,
98
- password: this.params.password,
99
- clientId: this.clientId,
100
- clean: true,
101
- resubscribe: true,
102
- keepalive: 60, /* 60s */
103
- reconnectPeriod: 2 * 1000, /* 2s */
104
- connectTimeout: 30 * 1000 /* 30s */
105
- });
106
- this.broker.on("error", (error) => {
107
- this.log("error", `error on MQTT ${this.params.url}: ${error.message}`);
108
- });
109
- this.broker.on("connect", (packet) => {
110
- this.log("info", `connection opened to MQTT ${this.params.url}`);
111
- if (this.params.mode !== "w" && !packet.sessionPresent)
112
- this.broker.subscribe([this.params.topicRead], () => { });
113
- });
114
- this.broker.on("reconnect", () => {
115
- this.log("info", `connection re-opened to MQTT ${this.params.url}`);
116
- });
117
- this.broker.on("disconnect", (packet) => {
118
- this.log("info", `connection closed to MQTT ${this.params.url}`);
119
- });
120
- const chunkQueue = new utils.SingleQueue();
121
- this.broker.on("message", (topic, payload, packet) => {
122
- if (topic !== this.params.topicRead)
123
- return;
124
- try {
125
- const chunk = utils.streamChunkDecode(payload);
126
- chunkQueue.write(chunk);
127
- }
128
- catch (_err) {
129
- this.log("warning", `received invalid CBOR chunk from MQTT ${this.params.url}`);
130
- }
131
- });
132
- const broker = this.broker;
133
- const topicWrite = this.params.topicWrite;
134
- const type = this.params.type;
135
- const mode = this.params.mode;
136
- this.stream = new node_stream_1.default.Duplex({
137
- writableObjectMode: true,
138
- readableObjectMode: true,
139
- decodeStrings: false,
140
- write(chunk, encoding, callback) {
141
- if (mode === "r")
142
- callback(new Error("write operation on read-only node"));
143
- else if (chunk.type !== type)
144
- callback(new Error(`written chunk is not of ${type} type`));
145
- else if (!broker.connected)
146
- callback(new Error("still no MQTT connection available"));
147
- else {
148
- const data = Buffer.from(utils.streamChunkEncode(chunk));
149
- broker.publish(topicWrite, data, { qos: 2, retain: false }, (err) => {
150
- if (err)
151
- callback(new Error(`failed to publish to MQTT topic "${topicWrite}": ${err}`));
152
- else
153
- callback();
154
- });
155
- }
156
- },
157
- read(size) {
158
- if (mode === "w")
159
- throw new Error("read operation on write-only node");
160
- chunkQueue.read().then((chunk) => {
161
- this.push(chunk, "binary");
162
- });
163
- }
164
- });
165
- }
166
- /* close node */
167
- async close() {
168
- /* close Websocket server */
169
- if (this.broker !== null) {
170
- if (this.broker.connected)
171
- this.broker.end();
172
- this.broker = null;
173
- }
174
- /* close stream */
175
- if (this.stream !== null) {
176
- this.stream.destroy();
177
- this.stream = null;
178
- }
179
- }
180
- }
181
- exports.default = SpeechFlowNodeMQTT;
@@ -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 Ollama */
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,12 +0,0 @@
1
- import SpeechFlowNode from "./speechflow-node";
2
- export default class SpeechFlowNodeSubtitle extends SpeechFlowNode {
3
- static name: string;
4
- private sequenceNo;
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,96 +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 subtitle (text-to-text) "translations" */
16
- class SpeechFlowNodeSubtitle extends speechflow_node_1.default {
17
- /* declare official node name */
18
- static name = "subtitle";
19
- /* internal state */
20
- sequenceNo = 1;
21
- /* construct node */
22
- constructor(id, cfg, opts, args) {
23
- super(id, cfg, opts, args);
24
- /* declare node configuration parameters */
25
- this.configure({
26
- format: { type: "string", pos: 0, val: "srt", match: /^(?:srt|vtt)$/ }
27
- });
28
- /* declare node input/output format */
29
- this.input = "text";
30
- this.output = "text";
31
- }
32
- /* open node */
33
- async open() {
34
- this.sequenceNo = 1;
35
- /* provide text-to-subtitle conversion */
36
- const convert = async (chunk) => {
37
- if (typeof chunk.payload !== "string")
38
- throw new Error("chunk payload type must be string");
39
- let text = chunk.payload;
40
- if (this.params.format === "srt") {
41
- const start = chunk.timestampStart.toFormat("hh:mm:ss,SSS");
42
- const end = chunk.timestampEnd.toFormat("hh:mm:ss,SSS");
43
- text = `${this.sequenceNo++}\n` +
44
- `${start} --> ${end}\n` +
45
- `${text}\n\n`;
46
- }
47
- else if (this.params.format === "vtt") {
48
- const start = chunk.timestampStart.toFormat("hh:mm:ss.SSS");
49
- const end = chunk.timestampEnd.toFormat("hh:mm:ss.SSS");
50
- text = `${this.sequenceNo++}\n` +
51
- `${start} --> ${end}\n` +
52
- `${text}\n\n`;
53
- }
54
- return text;
55
- };
56
- /* establish a duplex stream */
57
- this.stream = new node_stream_1.default.Transform({
58
- readableObjectMode: true,
59
- writableObjectMode: true,
60
- decodeStrings: false,
61
- transform(chunk, encoding, callback) {
62
- if (Buffer.isBuffer(chunk.payload))
63
- callback(new Error("invalid chunk payload type"));
64
- else {
65
- if (chunk.payload === "") {
66
- this.push(chunk);
67
- callback();
68
- }
69
- else {
70
- convert(chunk).then((payload) => {
71
- const chunkNew = chunk.clone();
72
- chunkNew.payload = payload;
73
- this.push(chunkNew);
74
- callback();
75
- }).catch((err) => {
76
- callback(err);
77
- });
78
- }
79
- }
80
- },
81
- final(callback) {
82
- this.push(null);
83
- callback();
84
- }
85
- });
86
- }
87
- /* open node */
88
- async close() {
89
- /* close stream */
90
- if (this.stream !== null) {
91
- this.stream.destroy();
92
- this.stream = null;
93
- }
94
- }
95
- }
96
- exports.default = SpeechFlowNodeSubtitle;
@@ -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 Ollama */
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;