Skip to content

Commit

Permalink
Add some ElevenLabs error handling
Browse files Browse the repository at this point in the history
Now provides some more detail when ElevenLabs returns an error and stops the script from proceeding.
  • Loading branch information
ThioJoe committed Jan 12, 2024
1 parent 7057a2c commit 56cf830
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
11 changes: 9 additions & 2 deletions Scripts/TTS.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,15 @@ async def synthesize_text_elevenlabs_async_http(text, voiceID, modelID, apiKey=E
break
audio_bytes += chunk
else:
print(f"Error: {response.status}")
return None
print(f"\n\nERROR: ElevenLabs API returned code: {response.status} - Reason: {response.reason}")
if response.status == 401:
print(" > ElevenLabs did not accept the API key or you are unauthorized to use that voice.")
print(" > Did you set the correct ElevenLabs API key in the cloud_service_settings.ini file?")
elif response.status == 400:
print(" > Did you set the correct ElevenLabs API key in the cloud_service_settings.ini file?")
elif response.status == 429:
print(" > You may have exceeded the ElevenLabs API rate limit. Did you set the 'elevenlabs_max_concurrent' setting too high for your plan?")
exit()

return audio_bytes

Expand Down
4 changes: 3 additions & 1 deletion Scripts/shared_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
# ----- Validation Checks ------ (Add these to their own file eventually)
if config['skip_synthesize'] == True and cloudConfig['batch_tts_synthesize'] == True:
raise ValueError(f'\nERROR: Cannot skip voice synthesis when batch mode is enabled. Please disable batch_tts_synthesize or set skip_synthesize to False.')

if cloudConfig['tts_service'] == "elevenlabs":
if "yourkey" in cloudConfig['elevenlabs_api_key'].lower():
raise ValueError(f"\n\nERROR: You chose ElevenLabs as your TTS service, but didnt set your ElevenLabs API Key in cloud_service_settings.ini")

# ----- Create constants ------
ORIGINAL_VIDEO_PATH = batchConfig['SETTINGS']['original_video_file_path']
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# License: GPLv3
# NOTE: By contributing to this project, you agree to the terms of the GPLv3 license, and agree to grant the project owner the right to also provide or sell this software, including your contribution, to anyone under any other license, with no compensation to you.

version = '0.17.0'
version = '0.17.1'
print(f"------- 'Auto Synced Translated Dubs' script by ThioJoe - Release version {version} -------")

# Import other files
Expand Down Expand Up @@ -48,7 +48,7 @@
if not batchConfig.has_section(f'LANGUAGE-{num}'):
raise ValueError(f'Invalid language number in batch.ini: {num} - Make sure the section [LANGUAGE-{num}] exists')

# Validate the settings in each section
# Validate the settings in each batch section
for num in languageNums:
if not batchConfig.has_option(f'LANGUAGE-{num}', 'synth_language_code'):
raise ValueError(f'Invalid configuration in batch.ini: {num} - Make sure the option "synth_language_code" exists under [LANGUAGE-{num}]')
Expand Down

0 comments on commit 56cf830

Please # to comment.