From 6f8c52efe8216f7bf634b8076a4f4291d4f6becb Mon Sep 17 00:00:00 2001 From: JT Date: Fri, 20 Jun 2025 20:19:37 +0100 Subject: [PATCH] dynamic elevenlabs voice fetching in setup after api key provided --- utils/settings.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/utils/settings.py b/utils/settings.py index 6b8242b..62f0ea1 100755 --- a/utils/settings.py +++ b/utils/settings.py @@ -6,6 +6,7 @@ import toml from rich.console import Console from utils.console import handle_input +from TTS.elevenlabs import elevenlabs console = Console() config = dict # autocomplete @@ -25,6 +26,21 @@ def check(value, checks, name): def get_check_value(key, default_result): return checks[key] if key in checks else default_result + # Dynamically fetch ElevenLabs voices if the API key is present + if name == "elevenlabs_voice_name": + # This relies on elevenlabs_api_key being processed first in the .toml file + api_key = config.get("settings", {}).get("tts", {}).get("elevenlabs_api_key") + if api_key: + console.print("\n[blue]Attempting to fetch your ElevenLabs voices...[/blue]") + # Use a static method to get voices without initializing the full class + available_voices = elevenlabs.get_available_voices(api_key) + if available_voices: + console.print("[green]Successfully fetched voices![/green]") + checks["options"] = available_voices + checks["explanation"] = "Select a voice from your ElevenLabs account. Leave blank for random." + else: + console.print("[yellow]Could not fetch voices. Check your API key. You can enter a voice name manually.[/yellow]") + incorrect = False if value == {}: incorrect = True