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;
|
||||
13
tts/main.py
Executable file
13
tts/main.py
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
from kokoro import KPipeline
|
||||
import soundfile as sf
|
||||
import sys
|
||||
import json
|
||||
|
||||
text = sys.stdin.read()
|
||||
|
||||
pipeline = KPipeline(lang_code="a", repo_id="hexgrad/Kokoro-82M")
|
||||
generator = pipeline(text, voice="af_heart", speed=1.2)
|
||||
|
||||
for i, (gs, ps, audio) in enumerate(generator):
|
||||
print(json.dumps({"file": i, "text": gs}))
|
||||
sf.write(f"{i}.wav", audio, 24000)
|
||||
8
tts/pyproject.toml
Normal file
8
tts/pyproject.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[project]
|
||||
name = "tts"
|
||||
version = "0.1.0"
|
||||
requires-python = ">=3.12"
|
||||
dependencies = [
|
||||
"kokoro>=0.9.4",
|
||||
"soundfile>=0.13.1",
|
||||
]
|
||||
2127
tts/uv.lock
generated
Normal file
2127
tts/uv.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue