Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,36 +49,39 @@ def ensure_model() -> str:
|
|
| 49 |
# ---------------------------------------
|
| 50 |
# Piper: rely on the PyPI wheel (piper-tts)
|
| 51 |
# ---------------------------------------
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
"""
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
# No PIPER_BIN provided → try PATH
|
| 84 |
resolved = which("piper")
|
|
@@ -109,11 +112,7 @@ def main():
|
|
| 109 |
# Ensure model exists locally
|
| 110 |
ensure_model()
|
| 111 |
|
| 112 |
-
|
| 113 |
-
piper_bin = ensure_piper_bin()
|
| 114 |
-
if piper_bin:
|
| 115 |
-
# Export to env so tts_router can pick it up
|
| 116 |
-
os.environ["PIPER_BIN"] = piper_bin
|
| 117 |
|
| 118 |
# Launch Gradio
|
| 119 |
demo = build_demo()
|
|
|
|
| 49 |
# ---------------------------------------
|
| 50 |
# Piper: rely on the PyPI wheel (piper-tts)
|
| 51 |
# ---------------------------------------
|
| 52 |
+
# --- keep your existing imports ---
|
| 53 |
+
import os
|
| 54 |
+
from huggingface_hub import hf_hub_download
|
| 55 |
|
| 56 |
+
def ensure_piper_voice():
|
| 57 |
+
"""
|
| 58 |
+
Make sure the Piper voice model exists at PIPER_MODEL.
|
| 59 |
+
Defaults to Amy-medium English if none specified.
|
| 60 |
"""
|
| 61 |
+
target_path = os.getenv("PIPER_MODEL", "models/piper/en_US-amy-medium.onnx")
|
| 62 |
+
repo_id = os.getenv("PIPER_VOICE_REPO", "rhasspy/piper-voices")
|
| 63 |
+
hf_file = os.getenv("PIPER_VOICE_FILE",
|
| 64 |
+
"en/en_US/en_US-amy-medium.onnx") # path inside the repo
|
| 65 |
+
|
| 66 |
+
# If already present, we're done.
|
| 67 |
+
if os.path.exists(target_path):
|
| 68 |
+
print(f"[PIPER] Voice model present: {target_path}")
|
| 69 |
+
return target_path
|
| 70 |
+
|
| 71 |
+
os.makedirs(os.path.dirname(target_path), exist_ok=True)
|
| 72 |
+
print(f"[PIPER] Downloading voice {hf_file} from {repo_id} …")
|
| 73 |
+
local = hf_hub_download(
|
| 74 |
+
repo_id=repo_id,
|
| 75 |
+
filename=hf_file,
|
| 76 |
+
local_dir=os.path.dirname(target_path),
|
| 77 |
+
local_dir_use_symlinks=False,
|
| 78 |
+
)
|
| 79 |
+
# Move/rename to the exact target filename if the name differs
|
| 80 |
+
if os.path.abspath(local) != os.path.abspath(target_path):
|
| 81 |
+
import shutil
|
| 82 |
+
shutil.copyfile(local, target_path)
|
| 83 |
+
print(f"[PIPER] Voice ready at: {target_path}")
|
| 84 |
+
return target_path
|
| 85 |
|
| 86 |
# No PIPER_BIN provided → try PATH
|
| 87 |
resolved = which("piper")
|
|
|
|
| 112 |
# Ensure model exists locally
|
| 113 |
ensure_model()
|
| 114 |
|
| 115 |
+
ensure_piper_voice()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
# Launch Gradio
|
| 118 |
demo = build_demo()
|