Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -81,14 +81,16 @@ def tts_post(request: TTSRequest): # Removed 'async' to prevent event loop block
|
|
| 81 |
wav_buffer = io.BytesIO()
|
| 82 |
|
| 83 |
with wave.open(wav_buffer, "wb") as wav_file:
|
| 84 |
-
wav_file.setnchannels(1)
|
| 85 |
-
wav_file.setsampwidth(2)
|
| 86 |
wav_file.setframerate(voice.config.sample_rate)
|
| 87 |
|
| 88 |
-
# Use the generator directly
|
| 89 |
for chunk in voice.synthesize(request.text):
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
| 92 |
wav_buffer.seek(0)
|
| 93 |
return Response(content=wav_buffer.getvalue(), media_type="audio/wav")
|
| 94 |
|
|
@@ -103,4 +105,14 @@ def home():
|
|
| 103 |
|
| 104 |
@app.get("/")
|
| 105 |
def home():
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
wav_buffer = io.BytesIO()
|
| 82 |
|
| 83 |
with wave.open(wav_buffer, "wb") as wav_file:
|
| 84 |
+
wav_file.setnchannels(1)
|
| 85 |
+
wav_file.setsampwidth(2)
|
| 86 |
wav_file.setframerate(voice.config.sample_rate)
|
| 87 |
|
|
|
|
| 88 |
for chunk in voice.synthesize(request.text):
|
| 89 |
+
if hasattr(chunk, "__iter__") and not isinstance(chunk, (bytes, bytearray)):
|
| 90 |
+
import struct
|
| 91 |
+
wav_file.writeframes(struct.pack(f"{len(chunk)}h", *chunk))
|
| 92 |
+
else:
|
| 93 |
+
wav_file.writeframes(chunk)
|
| 94 |
wav_buffer.seek(0)
|
| 95 |
return Response(content=wav_buffer.getvalue(), media_type="audio/wav")
|
| 96 |
|
|
|
|
| 105 |
|
| 106 |
@app.get("/")
|
| 107 |
def home():
|
| 108 |
+
# List all files in the models directory
|
| 109 |
+
try:
|
| 110 |
+
files = os.listdir(MODEL_DIR)
|
| 111 |
+
except Exception as e:
|
| 112 |
+
files = [f"Error reading directory: {str(e)}"]
|
| 113 |
+
|
| 114 |
+
return {
|
| 115 |
+
"message": "Piper TTS API is running",
|
| 116 |
+
"models_in_folder": files,
|
| 117 |
+
"supported_languages": VOICE_MAP
|
| 118 |
+
}
|