aivox
Version:
A lightweight CLI tool for translating voice to text using Whisper, seamlessly piping the transcribed text to any Unix-like command for versatile integration.
94 lines (92 loc) • 3.22 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __async = (__this, __arguments, generator) => {
return new Promise((resolve2, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve2(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// src/main.ts
var import_child_process = require("child_process");
var path = __toESM(require("path"));
function runTranscription() {
return __async(this, null, function* () {
return new Promise((resolve2, reject) => {
const workerScript = path.resolve(__dirname, "worker.js");
const child = (0, import_child_process.spawn)("node", [workerScript], {
stdio: ["inherit", "pipe", "pipe"]
});
let result = "";
child.stdout.on("data", (data) => {
result += data.toString();
});
child.stderr.on("data", (data) => {
});
child.on("close", (code) => {
if (code === 0) {
resolve2(result);
} else {
reject(new Error(`Worker process exited with code ${code}`));
}
});
});
});
}
function showRecordingMessage() {
const messageProcess = (0, import_child_process.fork)(path.resolve(__dirname, "recording.js"), {
stdio: ["ignore", "ignore", "inherit", "ipc"]
// Use IPC channel and inherit stderr
});
return messageProcess;
}
(() => __async(exports, null, function* () {
const recordingProcess = showRecordingMessage();
try {
const result = yield runTranscription();
recordingProcess.send("exit");
recordingProcess.on("exit", () => {
console.log(result.trim());
});
} catch (error) {
recordingProcess.send("exit");
recordingProcess.on("exit", () => {
console.error("Error:", error);
});
}
}))();