Spaces:
Running
Running
Update app_qwen_tts_fast.py
Browse files- app_qwen_tts_fast.py +11 -2
app_qwen_tts_fast.py
CHANGED
|
@@ -116,6 +116,8 @@ def cached_answer(question: str) -> str:
|
|
| 116 |
# =========================================================
|
| 117 |
# TTS (CACHED)
|
| 118 |
# =========================================================
|
|
|
|
|
|
|
| 119 |
@lru_cache(maxsize=128)
|
| 120 |
def cached_tts(text: str) -> str:
|
| 121 |
payload = {
|
|
@@ -130,14 +132,21 @@ def cached_tts(text: str) -> str:
|
|
| 130 |
r = SESSION.post(TTS_API_URL, json=payload)
|
| 131 |
r.raise_for_status()
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
| 135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
with open(audio_path, "wb") as f:
|
| 137 |
f.write(audio_bytes)
|
| 138 |
|
| 139 |
return audio_path
|
| 140 |
|
|
|
|
| 141 |
# =========================================================
|
| 142 |
# PIPELINE
|
| 143 |
# =========================================================
|
|
|
|
| 116 |
# =========================================================
|
| 117 |
# TTS (CACHED)
|
| 118 |
# =========================================================
|
| 119 |
+
import base64
|
| 120 |
+
|
| 121 |
@lru_cache(maxsize=128)
|
| 122 |
def cached_tts(text: str) -> str:
|
| 123 |
payload = {
|
|
|
|
| 132 |
r = SESSION.post(TTS_API_URL, json=payload)
|
| 133 |
r.raise_for_status()
|
| 134 |
|
| 135 |
+
data = r.json()
|
| 136 |
+
|
| 137 |
+
if "audio" not in data:
|
| 138 |
+
raise RuntimeError("TTS API returned no audio field")
|
| 139 |
|
| 140 |
+
audio_b64 = data["audio"]
|
| 141 |
+
audio_bytes = base64.b64decode(audio_b64)
|
| 142 |
+
|
| 143 |
+
audio_path = f"/tmp/tts_{abs(hash(text))}.wav"
|
| 144 |
with open(audio_path, "wb") as f:
|
| 145 |
f.write(audio_bytes)
|
| 146 |
|
| 147 |
return audio_path
|
| 148 |
|
| 149 |
+
|
| 150 |
# =========================================================
|
| 151 |
# PIPELINE
|
| 152 |
# =========================================================
|