speechflow
Version:
Speech Processing Flow Graph
77 lines • 2.81 kB
JavaScript
;
/*
** SpeechFlow - Speech Processing Flow Graph
** Copyright (c) 2024-2025 Dr. Ralf S. Engelschall <rse@engelschall.com>
** Licensed under GPL 3.0 <https://spdx.org/licenses/GPL-3.0-only>
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* standard dependencies */
const node_stream_1 = __importDefault(require("node:stream"));
/* external dependencies */
const wrap_text_1 = __importDefault(require("wrap-text"));
/* internal dependencies */
const speechflow_node_1 = __importDefault(require("./speechflow-node"));
/* SpeechFlow node for text-to-text formatting */
class SpeechFlowNodeT2TFormat extends speechflow_node_1.default {
/* declare official node name */
static name = "t2t-format";
/* construct node */
constructor(id, cfg, opts, args) {
super(id, cfg, opts, args);
/* declare node configuration parameters */
this.configure({
width: { type: "number", val: 80 }
});
/* declare node input/output format */
this.input = "text";
this.output = "text";
}
/* open node */
async open() {
/* provide text-to-text formatter */
const format = (text) => {
text = (0, wrap_text_1.default)(text, this.params.width);
text = text.replace(/([^\n])$/, "$1\n");
return text;
};
/* establish a duplex stream and connect it to text formatting */
this.stream = new node_stream_1.default.Transform({
readableObjectMode: true,
writableObjectMode: true,
decodeStrings: false,
highWaterMark: 1,
transform(chunk, encoding, callback) {
if (Buffer.isBuffer(chunk.payload))
callback(new Error("invalid chunk payload type"));
else if (chunk.payload === "") {
this.push(chunk);
callback();
}
else {
const payload = format(chunk.payload);
const chunkNew = chunk.clone();
chunkNew.payload = payload;
this.push(chunkNew);
callback();
}
},
final(callback) {
this.push(null);
callback();
}
});
}
/* close node */
async close() {
/* close stream */
if (this.stream !== null) {
this.stream.destroy();
this.stream = null;
}
}
}
exports.default = SpeechFlowNodeT2TFormat;
//# sourceMappingURL=speechflow-node-t2t-format.js.map