Percy3822 commited on
Commit
1042c9d
·
verified ·
1 Parent(s): fc9a048

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -11
app.py CHANGED
@@ -62,7 +62,7 @@ HF_REPO_BASE = "https://huggingface.co/rhasspy/piper-voices/resolve"
62
  HF_REV = os.getenv("PIPER_VOICES_REV", "main")
63
 
64
  # Sanity thresholds to detect corrupt downloads (bytes)
65
- MIN_ONNX_BYTES = int(os.getenv("MIN_ONNX_BYTES", "5000000")) # >= ~5MB (real models are tens/hundreds of MB)
66
  MIN_JSON_BYTES = int(os.getenv("MIN_JSON_BYTES", "1000")) # >= 1KB
67
 
68
  # Map short ids to their nested path in the repo: (lang, country, family, quality, basename)
@@ -90,7 +90,6 @@ def _download(url: str, dest: Path, timeout: int = 300):
90
  with http().get(url, timeout=timeout, stream=True, headers={"Accept": "application/octet-stream"}) as r:
91
  r.raise_for_status()
92
  ct = (r.headers.get("content-type") or "").lower()
93
- # If we get HTML, it's an error page (auth/rate-limit/etc) – abort
94
  if "text/html" in ct:
95
  raise RuntimeError(f"Bad content-type for {url}: {ct}")
96
  tmp = dest.with_suffix(dest.suffix + ".part")
@@ -218,8 +217,7 @@ async def piper_stream_stdout(text, voice, ws: WebSocket, length_scale, noise_sc
218
  chunk = await proc.stdout.read(4096)
219
  if not chunk:
220
  break
221
- total_bytes += len(chunk)
222
- # ↑ CAREFUL: keep indentation correct (inside loop)
223
  await ws.send_bytes(chunk)
224
 
225
  await proc.wait()
@@ -289,12 +287,6 @@ async def speak(request: Request):
289
  Body (JSON):
290
  {
291
  "text": "Hello",
292
- "voice": "en_US-libritts-high",
293
- "length_scale": 1.08,
294
- "noise_scale": 0.35,
295
- "noise_w": 0.90
296
- }
297
- => {"ok": true, "audio_url": "/file/tts-XXXX.wav"}
298
  """
299
  try:
300
  body = await request.json()
@@ -399,7 +391,6 @@ def debug_voices(redownload: bool = Query(False, description="Force re-download
399
  vdir.mkdir(parents=True, exist_ok=True)
400
  for p in vdir.glob("*"):
401
  p.unlink(missing_ok=True)
402
- # re-fetch
403
  ensure_voice(vid)
404
  info["redownloaded"] = True
405
  info["model_size"] = (model.stat().st_size if model.exists() else 0)
 
62
  HF_REV = os.getenv("PIPER_VOICES_REV", "main")
63
 
64
  # Sanity thresholds to detect corrupt downloads (bytes)
65
+ MIN_ONNX_BYTES = int(os.getenv("MIN_ONNX_BYTES", "5000000")) # >= ~5MB
66
  MIN_JSON_BYTES = int(os.getenv("MIN_JSON_BYTES", "1000")) # >= 1KB
67
 
68
  # Map short ids to their nested path in the repo: (lang, country, family, quality, basename)
 
90
  with http().get(url, timeout=timeout, stream=True, headers={"Accept": "application/octet-stream"}) as r:
91
  r.raise_for_status()
92
  ct = (r.headers.get("content-type") or "").lower()
 
93
  if "text/html" in ct:
94
  raise RuntimeError(f"Bad content-type for {url}: {ct}")
95
  tmp = dest.with_suffix(dest.suffix + ".part")
 
217
  chunk = await proc.stdout.read(4096)
218
  if not chunk:
219
  break
220
+ total_bytes += len(chunk)
 
221
  await ws.send_bytes(chunk)
222
 
223
  await proc.wait()
 
287
  Body (JSON):
288
  {
289
  "text": "Hello",
 
 
 
 
 
 
290
  """
291
  try:
292
  body = await request.json()
 
391
  vdir.mkdir(parents=True, exist_ok=True)
392
  for p in vdir.glob("*"):
393
  p.unlink(missing_ok=True)
 
394
  ensure_voice(vid)
395
  info["redownloaded"] = True
396
  info["model_size"] = (model.stat().st_size if model.exists() else 0)