Initial commit: Korean voice-cloning TTS prototype
FastAPI backend, web UI, CosyVoice3/F5-TTS setup scripts, and handoff docs for GPU PC continuation. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
73
scripts/workers/cosy_infer.py
Normal file
73
scripts/workers/cosy_infer.py
Normal file
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env python3
|
||||
"""CosyVoice3 zero-shot 추론 워커 (cosyvoice venv에서 실행)."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description="CosyVoice3 inference worker")
|
||||
parser.add_argument("--ref-audio", required=True)
|
||||
parser.add_argument("--prompt-text", default="", help="Text spoken in ref audio (with prefix)")
|
||||
parser.add_argument("--gen-text", required=True)
|
||||
parser.add_argument("--out", required=True)
|
||||
parser.add_argument(
|
||||
"--model-dir",
|
||||
default=None,
|
||||
help="Path to Fun-CosyVoice3-0.5B (default: PROJECT/models/Fun-CosyVoice3-0.5B)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--prompt-prefix",
|
||||
default="You are a helpful assistant.<|endofprompt|>",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
root = Path(__file__).resolve().parents[2]
|
||||
repo = root / "external" / "CosyVoice"
|
||||
model_dir = Path(args.model_dir or root / "models" / "Fun-CosyVoice3-0.5B")
|
||||
ref = Path(args.ref_audio)
|
||||
out = Path(args.out)
|
||||
|
||||
if not repo.is_dir():
|
||||
print(f"CosyVoice repo missing: {repo}. Run ./scripts/setup_cosyvoice.sh", file=sys.stderr)
|
||||
return 1
|
||||
if not model_dir.is_dir():
|
||||
print(f"Model dir missing: {model_dir}", file=sys.stderr)
|
||||
return 1
|
||||
if not ref.is_file():
|
||||
print(f"ref audio not found: {ref}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
sys.path.insert(0, str(repo))
|
||||
sys.path.append(str(repo / "third_party" / "Matcha-TTS"))
|
||||
|
||||
try:
|
||||
import torchaudio
|
||||
from cosyvoice.cli.cosyvoice import AutoModel
|
||||
except ImportError as e:
|
||||
print("CosyVoice import failed. Run ./scripts/setup_cosyvoice.sh", file=sys.stderr)
|
||||
print(e, file=sys.stderr)
|
||||
return 1
|
||||
|
||||
prompt = args.prompt_prefix + (args.prompt_text or "")
|
||||
out.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
cosyvoice = AutoModel(model_dir=str(model_dir))
|
||||
for i, result in enumerate(
|
||||
cosyvoice.inference_zero_shot(
|
||||
args.gen_text,
|
||||
prompt,
|
||||
str(ref),
|
||||
stream=False,
|
||||
)
|
||||
):
|
||||
path = out if i == 0 else out.with_stem(f"{out.stem}_{i}")
|
||||
torchaudio.save(str(path), result["tts_speech"], cosyvoice.sample_rate)
|
||||
print(f"OK: {path}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
47
scripts/workers/f5_infer.py
Normal file
47
scripts/workers/f5_infer.py
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
"""F5-TTS 추론 워커 (f5tts venv에서 실행)."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description="F5-TTS inference worker")
|
||||
parser.add_argument("--ref-audio", required=True, help="Reference WAV path")
|
||||
parser.add_argument("--ref-text", required=True, help="Transcript of reference audio")
|
||||
parser.add_argument("--gen-text", required=True, help="Text to synthesize")
|
||||
parser.add_argument("--out", required=True, help="Output WAV path")
|
||||
parser.add_argument("--model", default="F5TTS_v1_Base")
|
||||
args = parser.parse_args()
|
||||
|
||||
ref = Path(args.ref_audio)
|
||||
if not ref.is_file():
|
||||
print(f"ref audio not found: {ref}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
out = Path(args.out)
|
||||
out.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
try:
|
||||
from f5_tts.api import F5TTS
|
||||
except ImportError as e:
|
||||
print("f5-tts not installed. Run: ./scripts/setup_f5tts.sh", file=sys.stderr)
|
||||
print(e, file=sys.stderr)
|
||||
return 1
|
||||
|
||||
tts = F5TTS(model=args.model)
|
||||
tts.infer(
|
||||
ref_file=str(ref),
|
||||
ref_text=args.ref_text,
|
||||
gen_text=args.gen_text,
|
||||
file_wave=str(out),
|
||||
remove_silence=True,
|
||||
)
|
||||
print(f"OK: {out}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user