added elevenlabs protection

This commit is contained in:
Saifeddine ALOUI 2024-12-07 20:30:47 +01:00
parent af27856ce6
commit 8e4bb4182b

View File

@ -144,8 +144,11 @@ class LollmsElevenLabsTTS(LollmsTTS):
else: else:
url = f"https://api.elevenlabs.io/v1/text-to-speech/{self.voice_id}" url = f"https://api.elevenlabs.io/v1/text-to-speech/{self.voice_id}"
response = requests.post(url, json=payload, headers=headers) response = requests.post(url, json=payload, headers=headers)
with open(speech_file_path, 'wb') as f: if response.status_code == 200:
f.write(response.content) with open(speech_file_path, 'wb') as f:
f.write(response.content)
else:
self.app.error(f"Couldn't generate speech, {response.reason}")
def play_audio(file_path): def play_audio(file_path):
# Read the audio file # Read the audio file