feature: implement base tts with uv and kokoro
This commit is contained in:
parent
75a87218b0
commit
4112295144
4 changed files with 2188 additions and 0 deletions
40
tts.ts
Normal file
40
tts.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue