mirror of
https://github.com/Nighthawk42/MioTTS.git
synced 2026-08-30 10:32:27 +00:00
120 lines
2.7 KiB
Python
120 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
import argparse
|
|
import subprocess
|
|
import sys
|
|
import os
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parent
|
|
|
|
# UPDATE: Point directly to 'recipes' folder
|
|
RECIPES_ROOT = ROOT / "recipes"
|
|
|
|
VENV_PYTHON = ROOT / ".venv" / "bin" / "python"
|
|
|
|
# These will now resolve to recipes/glow_tts/train_glowtts.py, etc.
|
|
RECIPES = {
|
|
"glowtts": RECIPES_ROOT / "glow_tts" / "train_glowtts.py",
|
|
"vits": RECIPES_ROOT / "vits_tts" / "train_vits.py",
|
|
"xtts": RECIPES_ROOT / "xtts_v2" / "train_gpt_xtts.py",
|
|
}
|
|
|
|
|
|
def interactive_select():
|
|
keys = list(RECIPES.keys())
|
|
|
|
print()
|
|
print("Select recipe to launch:")
|
|
for i, k in enumerate(keys, 1):
|
|
print(f" [{i}] {k}")
|
|
print()
|
|
|
|
while True:
|
|
choice = input("Enter number (or 'q' to quit): ").strip()
|
|
|
|
if choice.lower() in {"q", "quit", "exit"}:
|
|
return None
|
|
|
|
if not choice.isdigit():
|
|
print("Please enter a number.")
|
|
continue
|
|
|
|
idx = int(choice) - 1
|
|
if 0 <= idx < len(keys):
|
|
return keys[idx]
|
|
|
|
print("Invalid selection.")
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="Launch MioTTS recipes from this venv"
|
|
)
|
|
|
|
parser.add_argument(
|
|
"recipe",
|
|
nargs="?",
|
|
choices=RECIPES.keys(),
|
|
)
|
|
|
|
parser.add_argument(
|
|
"args",
|
|
nargs=argparse.REMAINDER,
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
recipe = args.recipe
|
|
if recipe is None:
|
|
recipe = interactive_select()
|
|
if recipe is None:
|
|
print("Aborted.")
|
|
return
|
|
|
|
script = RECIPES[recipe]
|
|
|
|
if not script.exists():
|
|
print(f"[launcher] Script not found: {script}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
# Always prefer the project venv python if it exists
|
|
python = VENV_PYTHON if VENV_PYTHON.exists() else Path(sys.executable)
|
|
|
|
env = os.environ.copy()
|
|
|
|
# Make sure the project root is importable (TTS/, trainer/, etc.)
|
|
env["PYTHONPATH"] = str(ROOT) + (
|
|
os.pathsep + env["PYTHONPATH"]
|
|
if "PYTHONPATH" in env
|
|
else ""
|
|
)
|
|
|
|
cmd = [
|
|
str(python),
|
|
str(script),
|
|
*args.args,
|
|
]
|
|
|
|
print()
|
|
print(f"[launcher] using python : {python}")
|
|
print(f"[launcher] PYTHONPATH : {env['PYTHONPATH']}")
|
|
print(f"[launcher] recipe : {recipe}")
|
|
print(f"[launcher] script : {script}")
|
|
print()
|
|
|
|
subprocess.run(
|
|
cmd,
|
|
cwd=script.parent,
|
|
env=env,
|
|
check=True,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
main()
|
|
except KeyboardInterrupt:
|
|
print("\n[launcher] Interrupted.")
|
|
sys.exit(130) # Standard exit code for SIGINT
|