feat(tools-pve/asr-pipeline): multi-backend ASR web app with LiteLLM routing
This commit is contained in:
@@ -185,7 +185,8 @@ def _voiceprint_name(value: str) -> str:
|
||||
|
||||
|
||||
def _confirm_voiceprint(draft_path: str, speaker_id: str, value: str) -> bool:
|
||||
"""Persist an explicit speaker identity and immediately enroll its session."""
|
||||
"""Persist an explicit speaker identity and, when a voiceprint session exists,
|
||||
enroll it against the acoustic voiceprint service."""
|
||||
name = _voiceprint_name(value)
|
||||
if not name:
|
||||
return False
|
||||
@@ -196,8 +197,6 @@ def _confirm_voiceprint(draft_path: str, speaker_id: str, value: str) -> bool:
|
||||
return False
|
||||
text = path.read_text(encoding="utf-8", errors="ignore")
|
||||
session_id = _frontmatter_value(text, "voiceprint_session")
|
||||
if not session_id:
|
||||
return False
|
||||
fm = re.match(r"(?s)^---\n(.*?)\n---", text)
|
||||
if not fm:
|
||||
return False
|
||||
@@ -205,27 +204,34 @@ def _confirm_voiceprint(draft_path: str, speaker_id: str, value: str) -> bool:
|
||||
speaker_line = rf"(?m)^(\s+{re.escape(speaker_id)}:)\s*.*$"
|
||||
if re.search(speaker_line, block):
|
||||
block = re.sub(speaker_line, rf"\1 {name}", block)
|
||||
elif re.search(r"(?m)^voiceprint_speakers:\s*(?:\{\})?\s*$", block):
|
||||
block = re.sub(
|
||||
r"(?m)^voiceprint_speakers:\s*(?:\{\})?\s*$",
|
||||
f"voiceprint_speakers:\n {speaker_id}: {name}", block, count=1)
|
||||
elif re.search(r"(?m)^voiceprint_speakers:\s*$", block):
|
||||
block = re.sub(
|
||||
r"(?m)^(voiceprint_speakers:\s*)$",
|
||||
rf"\1\n {speaker_id}: {name}", block, count=1)
|
||||
else:
|
||||
block += f"\nvoiceprint_speakers:\n {speaker_id}: {name}"
|
||||
if re.search(r"(?m)^voiceprint_enroll:", block):
|
||||
block = re.sub(r"(?m)^voiceprint_enroll:.*$",
|
||||
"voiceprint_enroll: true", block)
|
||||
else:
|
||||
block += "\nvoiceprint_enroll: true"
|
||||
if session_id:
|
||||
if re.search(r"(?m)^voiceprint_enroll:", block):
|
||||
block = re.sub(r"(?m)^voiceprint_enroll:.*$",
|
||||
"voiceprint_enroll: true", block)
|
||||
else:
|
||||
block += "\nvoiceprint_enroll: true"
|
||||
text = text[:fm.start()] + "---\n" + block + "\n---" + text[fm.end():]
|
||||
from . import vault
|
||||
vault.write_draft_file(path, text)
|
||||
|
||||
if not session_id or not CFG.voiceprint_enroll_url:
|
||||
return False
|
||||
body = json.dumps({
|
||||
"session_id": session_id, "speaker_id": int(speaker_id.split("_")[1]),
|
||||
"name": name,
|
||||
}).encode()
|
||||
req = urllib.request.Request(
|
||||
"http://192.168.50.100:10099/voiceprints/enroll", data=body,
|
||||
CFG.voiceprint_enroll_url, data=body,
|
||||
headers={"Content-Type": "application/json"})
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=20) as response:
|
||||
|
||||
Reference in New Issue
Block a user