IliaLarchenko commited on
Commit
b2d72b4
1 Parent(s): 11f6522

Empty text TTS fix

Browse files
Files changed (1) hide show
  1. api/audio.py +26 -26
api/audio.py CHANGED
@@ -174,38 +174,38 @@ class TTSManager:
174
 
175
  if not text:
176
  yield b""
 
177
 
178
- else:
179
- if stream is None:
180
- stream = self.streaming
 
 
181
 
182
- headers = {"Authorization": "Bearer " + self.config.tts.key}
183
- data = {"model": self.config.tts.name, "input": text, "voice": "alloy", "response_format": "opus"}
 
 
 
 
184
 
185
- try:
186
- if not stream:
187
- if self.config.tts.type == "OPENAI_API":
188
- response = requests.post(self.config.tts.url + "/audio/speech", headers=headers, json=data)
189
- elif self.config.tts.type == "HF_API":
190
- response = requests.post(self.config.tts.url, headers=headers, json={"inputs": text})
 
191
 
 
192
  if response.status_code != 200:
193
  error_details = response.json().get("error", "No error message provided")
194
- raise APIError(f"TTS Error: {self.config.tts.type} error", status_code=response.status_code, details=error_details)
195
- yield response.content
196
- else:
197
- if self.config.tts.type != "OPENAI_API":
198
- raise APIError("TTS Error: Streaming not supported for this TTS type")
199
-
200
- with requests.post(self.config.tts.url + "/audio/speech", headers=headers, json=data, stream=True) as response:
201
- if response.status_code != 200:
202
- error_details = response.json().get("error", "No error message provided")
203
- raise APIError("TTS Error: OPENAI API error", status_code=response.status_code, details=error_details)
204
- yield from response.iter_content(chunk_size=1024)
205
- except APIError:
206
- raise
207
- except Exception as e:
208
- raise APIError(f"TTS Error: Unexpected error: {e}")
209
 
210
  def read_last_message(self, chat_history: List[List[Optional[str]]]) -> Generator[bytes, None, None]:
211
  """
 
174
 
175
  if not text:
176
  yield b""
177
+ return
178
 
179
+ if stream is None:
180
+ stream = self.streaming
181
+
182
+ headers = {"Authorization": "Bearer " + self.config.tts.key}
183
+ data = {"model": self.config.tts.name, "input": text, "voice": "alloy", "response_format": "opus"}
184
 
185
+ try:
186
+ if not stream:
187
+ if self.config.tts.type == "OPENAI_API":
188
+ response = requests.post(self.config.tts.url + "/audio/speech", headers=headers, json=data)
189
+ elif self.config.tts.type == "HF_API":
190
+ response = requests.post(self.config.tts.url, headers=headers, json={"inputs": text})
191
 
192
+ if response.status_code != 200:
193
+ error_details = response.json().get("error", "No error message provided")
194
+ raise APIError(f"TTS Error: {self.config.tts.type} error", status_code=response.status_code, details=error_details)
195
+ yield response.content
196
+ else:
197
+ if self.config.tts.type != "OPENAI_API":
198
+ raise APIError("TTS Error: Streaming not supported for this TTS type")
199
 
200
+ with requests.post(self.config.tts.url + "/audio/speech", headers=headers, json=data, stream=True) as response:
201
  if response.status_code != 200:
202
  error_details = response.json().get("error", "No error message provided")
203
+ raise APIError("TTS Error: OPENAI API error", status_code=response.status_code, details=error_details)
204
+ yield from response.iter_content(chunk_size=1024)
205
+ except APIError:
206
+ raise
207
+ except Exception as e:
208
+ raise APIError(f"TTS Error: Unexpected error: {e}")
 
 
 
 
 
 
 
 
 
209
 
210
  def read_last_message(self, chat_history: List[List[Optional[str]]]) -> Generator[bytes, None, None]:
211
  """