Spaces:
Build error
Build error
Commit ·
8c2d6d8
1
Parent(s): bab35e1
Fix speaker2refs parsing (dict) and ref path
Browse files
app.py
CHANGED
|
@@ -44,12 +44,11 @@ SPEAKER_CHOICES = sorted(SPEAKER2REFS.keys())
|
|
| 44 |
if not SPEAKER_CHOICES:
|
| 45 |
raise RuntimeError("speaker2refs.json is empty (no speakers found).")
|
| 46 |
|
| 47 |
-
# def _abs_audio(p: str) -> str:
|
| 48 |
-
# return p if os.path.isabs(p) else os.path.join(DATA_ROOT, p)
|
| 49 |
|
| 50 |
def _abs_audio(p: str) -> str:
|
| 51 |
# p trong json đang là "demo_data/refs/id_k.wav" => join theo repo root
|
| 52 |
return p if os.path.isabs(p) else os.path.join(repo_dir, p)
|
|
|
|
| 53 |
# =========================
|
| 54 |
# LOAD MODEL
|
| 55 |
# =========================
|
|
@@ -73,60 +72,6 @@ def _cache_set(key, val):
|
|
| 73 |
STYLE_CACHE.pop(next(iter(STYLE_CACHE)))
|
| 74 |
STYLE_CACHE[key] = val
|
| 75 |
|
| 76 |
-
# @torch.inference_mode()
|
| 77 |
-
# def synth_one_speaker(speaker_name: str, text_prompt: str,
|
| 78 |
-
# denoise: float, avg_style: bool, stabilize: bool):
|
| 79 |
-
# try:
|
| 80 |
-
# if not speaker_name:
|
| 81 |
-
# return None, "Bạn chưa chọn speaker."
|
| 82 |
-
|
| 83 |
-
# refs = SPEAKER2REFS.get(speaker_name, [])
|
| 84 |
-
# if not refs:
|
| 85 |
-
# return None, f"Speaker '{speaker_name}' không có ref trong speaker2refs.json."
|
| 86 |
-
|
| 87 |
-
# ref_path = _abs_audio(refs[0])
|
| 88 |
-
# if not os.path.isfile(ref_path):
|
| 89 |
-
# return None, f"Ref audio not found: {ref_path}"
|
| 90 |
-
|
| 91 |
-
# if not text_prompt or not text_prompt.strip():
|
| 92 |
-
# return None, "Bạn chưa nhập text."
|
| 93 |
-
|
| 94 |
-
# speakers = {
|
| 95 |
-
# "id_1": {"path": ref_path, "lang": "vi", "speed": 1.0}
|
| 96 |
-
# }
|
| 97 |
-
|
| 98 |
-
# cache_key = (speaker_name, float(denoise), bool(avg_style))
|
| 99 |
-
# styles = _cache_get(cache_key)
|
| 100 |
-
# if styles is None:
|
| 101 |
-
# styles = model.get_styles(speakers, denoise, avg_style)
|
| 102 |
-
# _cache_set(cache_key, styles)
|
| 103 |
-
|
| 104 |
-
# # Neu user khong them tag [id_1] thi tu them
|
| 105 |
-
# text_prompt = text_prompt.strip()
|
| 106 |
-
# if "[id_" not in text_prompt:
|
| 107 |
-
# text_prompt = "[id_1] " + text_prompt
|
| 108 |
-
|
| 109 |
-
# r = model.generate(text_prompt, styles, stabilize, 18, "[id_1]")
|
| 110 |
-
|
| 111 |
-
# r = np.asarray(r, dtype=np.float32)
|
| 112 |
-
# m = float(np.max(np.abs(r))) if r.size else 0.0
|
| 113 |
-
# if m > 1e-9:
|
| 114 |
-
# r = r / m
|
| 115 |
-
|
| 116 |
-
# out_f = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
|
| 117 |
-
# out_path = out_f.name
|
| 118 |
-
# out_f.close()
|
| 119 |
-
# sf.write(out_path, r, samplerate=24000)
|
| 120 |
-
|
| 121 |
-
# status = (
|
| 122 |
-
# "OK\n"
|
| 123 |
-
# f"speaker: {speaker_name}\n"
|
| 124 |
-
# f"device: {device}"
|
| 125 |
-
# )
|
| 126 |
-
# return out_path, status
|
| 127 |
-
|
| 128 |
-
# except Exception:
|
| 129 |
-
# return None, traceback.format_exc()
|
| 130 |
|
| 131 |
@torch.inference_mode()
|
| 132 |
def synth_one_speaker(speaker_name: str, text_prompt: str,
|
|
@@ -228,7 +173,7 @@ with gr.Blocks() as demo:
|
|
| 228 |
)
|
| 229 |
if __name__ == "__main__":
|
| 230 |
try:
|
| 231 |
-
demo.queue(
|
| 232 |
except TypeError:
|
| 233 |
demo.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)
|
| 234 |
|
|
|
|
| 44 |
if not SPEAKER_CHOICES:
|
| 45 |
raise RuntimeError("speaker2refs.json is empty (no speakers found).")
|
| 46 |
|
|
|
|
|
|
|
| 47 |
|
| 48 |
def _abs_audio(p: str) -> str:
|
| 49 |
# p trong json đang là "demo_data/refs/id_k.wav" => join theo repo root
|
| 50 |
return p if os.path.isabs(p) else os.path.join(repo_dir, p)
|
| 51 |
+
|
| 52 |
# =========================
|
| 53 |
# LOAD MODEL
|
| 54 |
# =========================
|
|
|
|
| 72 |
STYLE_CACHE.pop(next(iter(STYLE_CACHE)))
|
| 73 |
STYLE_CACHE[key] = val
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
@torch.inference_mode()
|
| 77 |
def synth_one_speaker(speaker_name: str, text_prompt: str,
|
|
|
|
| 173 |
)
|
| 174 |
if __name__ == "__main__":
|
| 175 |
try:
|
| 176 |
+
demo.queue().launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)
|
| 177 |
except TypeError:
|
| 178 |
demo.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)
|
| 179 |
|