Add X-VC voice conversion mode
This commit is contained in:
1 parent
17f1a08d7d
commit
87a2ae5704
15 files changed
+544
-28
No files matched your search
@@ -34,6 +34,8 @@ SEPARATOR_LABEL_KEY = "com.mike-ai.stem-separator"
|
||||
SEPARATOR_WORKER = os.environ.get("SEPARATOR_WORKER", "").strip()
|
||||
VOICE_LABEL_KEY = "com.mike-ai.voice-worker"
|
||||
VOICE_WORKER = os.environ.get("VOICE_WORKER", "").strip()
|
||||
VOICE_CHANGE_LABEL_KEY = "com.mike-ai.voice-change-worker"
|
||||
VOICE_CHANGE_WORKER = os.environ.get("VOICE_CHANGE_WORKER", "").strip()
|
||||
LOCK = threading.Lock()
|
||||
log = logging.getLogger("profile-controller")
|
||||
|
||||
@@ -135,6 +137,17 @@ def voice_container() -> dict:
|
||||
return matches[0]
|
||||
|
||||
|
||||
def voice_change_container() -> dict:
|
||||
if not VOICE_CHANGE_WORKER:
|
||||
raise RuntimeError("voice-change worker is not configured")
|
||||
matches = [item for item in labelled_containers(VOICE_CHANGE_LABEL_KEY)
|
||||
if item.get("Labels", {}).get(VOICE_CHANGE_LABEL_KEY) == VOICE_CHANGE_WORKER]
|
||||
if len(matches) != 1:
|
||||
raise RuntimeError(
|
||||
f"expected exactly one voice-change worker {VOICE_CHANGE_WORKER!r}, found {len(matches)}")
|
||||
return matches[0]
|
||||
|
||||
|
||||
def stop_music_if_configured() -> None:
|
||||
if MUSIC_WORKER:
|
||||
stop_container(music_container(), timeout=30)
|
||||
@@ -150,6 +163,11 @@ def stop_voice_if_configured() -> None:
|
||||
stop_container(voice_container(), timeout=30)
|
||||
|
||||
|
||||
def stop_voice_change_if_configured() -> None:
|
||||
if VOICE_CHANGE_WORKER:
|
||||
stop_container(voice_change_container(), timeout=30)
|
||||
|
||||
|
||||
def stop_container(item: dict, timeout: int = 120) -> None:
|
||||
if item.get("State") != "running":
|
||||
return
|
||||
@@ -190,6 +208,7 @@ def set_image_worker(running: bool, kind: str = IMAGE_WORKER) -> dict:
|
||||
stop_music_if_configured()
|
||||
stop_separator_if_configured()
|
||||
stop_voice_if_configured()
|
||||
stop_voice_change_if_configured()
|
||||
for other in image_containers():
|
||||
if other["Id"] != item["Id"]:
|
||||
stop_container(other, timeout=20)
|
||||
@@ -217,6 +236,7 @@ def set_music_worker(running: bool) -> dict:
|
||||
stop_container(tts_container(), timeout=30)
|
||||
stop_separator_if_configured()
|
||||
stop_voice_if_configured()
|
||||
stop_voice_change_if_configured()
|
||||
start_container(item)
|
||||
else:
|
||||
stop_container(item, timeout=30)
|
||||
@@ -236,6 +256,7 @@ def set_separator_worker(running: bool) -> dict:
|
||||
stop_container(tts_container(), timeout=30)
|
||||
stop_music_if_configured()
|
||||
stop_voice_if_configured()
|
||||
stop_voice_change_if_configured()
|
||||
start_container(item)
|
||||
else:
|
||||
stop_container(item, timeout=30)
|
||||
@@ -244,7 +265,7 @@ def set_separator_worker(running: bool) -> dict:
|
||||
|
||||
|
||||
def set_voice_worker(running: bool) -> dict:
|
||||
"""Start Vevo2 exclusively, or stop it before LLM restoration."""
|
||||
"""Start OmniVoice exclusively, or stop it before LLM restoration."""
|
||||
with LOCK:
|
||||
item = voice_container()
|
||||
if running:
|
||||
@@ -255,6 +276,7 @@ def set_voice_worker(running: bool) -> dict:
|
||||
stop_container(tts_container(), timeout=30)
|
||||
stop_music_if_configured()
|
||||
stop_separator_if_configured()
|
||||
stop_voice_change_if_configured()
|
||||
start_container(item)
|
||||
else:
|
||||
stop_container(item, timeout=30)
|
||||
@@ -262,6 +284,26 @@ def set_voice_worker(running: bool) -> dict:
|
||||
"state": "running" if running else "stopped"}
|
||||
|
||||
|
||||
def set_voice_change_worker(running: bool) -> dict:
|
||||
"""Start X-VC exclusively, or stop it before another mode is loaded."""
|
||||
with LOCK:
|
||||
item = voice_change_container()
|
||||
if running:
|
||||
for profile_item in containers().values():
|
||||
stop_container(profile_item)
|
||||
for worker in image_containers():
|
||||
stop_container(worker, timeout=20)
|
||||
stop_container(tts_container(), timeout=30)
|
||||
stop_music_if_configured()
|
||||
stop_separator_if_configured()
|
||||
stop_voice_if_configured()
|
||||
start_container(item)
|
||||
else:
|
||||
stop_container(item, timeout=30)
|
||||
return {"voice_change_worker": VOICE_CHANGE_WORKER,
|
||||
"state": "running" if running else "stopped"}
|
||||
|
||||
|
||||
def active_profile(items: dict[str, dict] | None = None) -> str | None:
|
||||
items = items or containers()
|
||||
active = [name for name, item in items.items() if item.get("State") == "running"]
|
||||
@@ -280,6 +322,7 @@ def activate(profile: str) -> dict:
|
||||
stop_music_if_configured()
|
||||
stop_separator_if_configured()
|
||||
stop_voice_if_configured()
|
||||
stop_voice_change_if_configured()
|
||||
start_container(tts_container())
|
||||
items = containers()
|
||||
missing = [name for name in ALLOWED if name not in items]
|
||||
@@ -365,6 +408,13 @@ class Handler(BaseHTTPRequestHandler):
|
||||
"unhealthy" if "(unhealthy)" in voice_status else
|
||||
"starting" if voice.get("State") == "running" else
|
||||
"stopped")
|
||||
voice_change = voice_change_container() if VOICE_CHANGE_WORKER else {}
|
||||
voice_change_status = voice_change.get("Status", "")
|
||||
voice_change_health = ("disabled" if not VOICE_CHANGE_WORKER else
|
||||
"healthy" if "(healthy)" in voice_change_status else
|
||||
"unhealthy" if "(unhealthy)" in voice_change_status else
|
||||
"starting" if voice_change.get("State") == "running" else
|
||||
"stopped")
|
||||
self.reply(200, {"active_profile": active_profile(items),
|
||||
"music_worker": music.get("State", "disabled"),
|
||||
"music_health": music_health,
|
||||
@@ -372,6 +422,8 @@ class Handler(BaseHTTPRequestHandler):
|
||||
"separator_health": separator_health,
|
||||
"voice_worker": voice.get("State", "disabled"),
|
||||
"voice_health": voice_health,
|
||||
"voice_change_worker": voice_change.get("State", "disabled"),
|
||||
"voice_change_health": voice_change_health,
|
||||
"profiles": {name: items.get(name, {}).get(
|
||||
"State", "missing") for name in ALLOWED}})
|
||||
except Exception as exc:
|
||||
@@ -410,6 +462,13 @@ class Handler(BaseHTTPRequestHandler):
|
||||
log.exception("voice worker transition failed")
|
||||
self.reply(503, {"error": str(exc)})
|
||||
return
|
||||
if self.path in {"/workers/voice-change/start", "/workers/voice-change/stop"}:
|
||||
try:
|
||||
self.reply(200, set_voice_change_worker(self.path.endswith("/start")))
|
||||
except Exception as exc:
|
||||
log.exception("voice-change worker transition failed")
|
||||
self.reply(503, {"error": str(exc)})
|
||||
return
|
||||
worker_paths = {
|
||||
"/workers/image/start": (IMAGE_WORKER, True),
|
||||
"/workers/image/stop": (IMAGE_WORKER, False),
|
||||
|
||||
Reference in new issue
Block a user