randusertry commited on
Commit
d39f28b
·
verified ·
1 Parent(s): 60314d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
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
- wav_file.writeframes(chunk)
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
- return {"languages": VOICE_MAP}
 
 
 
 
 
 
 
 
 
 
 
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
+ }