40 lines
864 B
TypeScript
40 lines
864 B
TypeScript
import chalk from "chalk";
|
|
|
|
const text = await Bun.stdin.text();
|
|
|
|
if (!text) process.exit(1);
|
|
|
|
const koko = Bun.spawn({
|
|
cmd: ["uv", "run", "--", "python", "-u", "main.py"],
|
|
cwd: "./tts/",
|
|
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: "./tts/",
|
|
stdin: "ignore",
|
|
stdout: "inherit",
|
|
stderr: "inherit",
|
|
}).exited;
|
|
}
|
|
}
|
|
|
|
await koko.exited;
|