lmc/tts.ts

43 lines
934 B
TypeScript

import os from "node:os";
import chalk from "chalk";
const text = await Bun.stdin.text();
if (!text) process.exit(1);
const home = os.homedir();
const koko = Bun.spawn({
cmd: ["uv", "run", "--", "python", "-u", "main.py"],
cwd: `${home}/.ttsc/`,
stdin: Buffer.from(text),
stdout: "pipe",
stderr: "inherit",
});
const decoder = new TextDecoder();
for await (const line of koko.stdout) {
const decoded = decoder.decode(line).trim();
let infos: { file: number; text: string }[];
try {
infos = Bun.JSONL.parse(decoded) as { file: number; text: string }[];
} catch {
console.log(decoded);
continue;
}
for (const info of infos) {
console.log(`\n${chalk.blue(info.file)}: ${info.text}\n`);
await Bun.spawn({
cmd: ["mpv", `${info.file}.wav`],
cwd: `${home}/.ttsc/`,
stdin: "ignore",
stdout: "inherit",
stderr: "inherit",
}).exited;
}
}
await koko.exited;