Spaces:
Sleeping
Sleeping
| import os, uuid, base64, requests | |
| from functools import lru_cache | |
| TTS_API = os.getenv( | |
| "TTS_API_URL", | |
| "https://rahul7star-Chatterbox-Multilingual-TTS-API.hf.space/tts" | |
| ) | |
| SESSION = requests.Session() | |
| def synthesize(text: str, lang: str) -> str: | |
| payload = { | |
| "text": text, | |
| "language_id": lang, | |
| "mode": "Speak 🗣️" | |
| } | |
| r = SESSION.post(TTS_API, json=payload, timeout=None) | |
| r.raise_for_status() | |
| path = f"/tmp/tts_{uuid.uuid4().hex}.wav" | |
| if r.headers.get("content-type", "").startswith("audio"): | |
| open(path, "wb").write(r.content) | |
| return path | |
| audio = r.json().get("audio") or r.json().get("audio_base64") | |
| open(path, "wb").write(base64.b64decode(audio)) | |
| return path | |