UNPKG

@pr0gramm/fluester

Version:

Node.js bindings for OpenAI's Whisper. Optimized for CPU.

32 lines (31 loc) 939 B
import { spawn } from "node:child_process"; import * as fs from "node:fs/promises"; export async function execute(command, args, shell = false, signal) { const child = spawn(command, args, { shell, signal, }); return new Promise((resolve, reject) => { const stdOutChunks = []; const stdErrChunks = []; child.stdout.on("data", stdOutChunks.push.bind(stdOutChunks)); child.stderr.on("data", stdErrChunks.push.bind(stdErrChunks)); child.once("error", reject); child.once("close", () => { resolve({ exitCode: child.exitCode, stdout: Buffer.concat(stdOutChunks), stderr: Buffer.concat(stdErrChunks), }); }); }); } export async function canExecute(file) { try { await fs.access(file, fs.constants.X_OK); return true; } catch { return false; } }