Auto-update: Thu Aug 8 19:37:46 PDT 2024
This commit is contained in:
parent
b3068d8118
commit
74547d9121
2 changed files with 28 additions and 15 deletions
|
@ -166,6 +166,10 @@ class Configuration(BaseModel):
|
||||||
replacement = getattr(self, parts[1], str(Path.home() / parts[1].lower()))
|
replacement = getattr(self, parts[1], str(Path.home() / parts[1].lower()))
|
||||||
elif len(parts) == 2 and parts[0] == 'ENV':
|
elif len(parts) == 2 and parts[0] == 'ENV':
|
||||||
replacement = os.getenv(parts[1], '')
|
replacement = os.getenv(parts[1], '')
|
||||||
|
elif len(parts) == 2 and parts[0] == 'SECRET':
|
||||||
|
replacement = getattr(self, parts[1].strip(), '')
|
||||||
|
if not replacement:
|
||||||
|
warn(f"Secret '{parts[1].strip()}' not found in secrets file")
|
||||||
else:
|
else:
|
||||||
replacement = value
|
replacement = value
|
||||||
|
|
||||||
|
@ -176,6 +180,7 @@ class Configuration(BaseModel):
|
||||||
return Path(value).expanduser()
|
return Path(value).expanduser()
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_dynamic_model(cls, **data):
|
def create_dynamic_model(cls, **data):
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
|
|
|
@ -214,15 +214,19 @@ async def determine_voice_id(voice_name: str) -> str:
|
||||||
debug(f"Searching for voice id for {voice_name}")
|
debug(f"Searching for voice id for {voice_name}")
|
||||||
debug(f"Tts.elevenlabs.voices: {Tts.elevenlabs.voices}")
|
debug(f"Tts.elevenlabs.voices: {Tts.elevenlabs.voices}")
|
||||||
|
|
||||||
# Check if the voice is in the configured voices
|
voices = Tts.elevenlabs.voices
|
||||||
if voice_name in Tts.elevenlabs.voices:
|
if isinstance(voices, dict):
|
||||||
voice_id = Tts.elevenlabs.voices[voice_name]
|
if voice_name in voices:
|
||||||
debug(f"Found voice ID in config - {voice_id}")
|
return voices[voice_name]
|
||||||
return voice_id
|
elif hasattr(voices, '__dict__'):
|
||||||
|
voices_dict = voices.__dict__
|
||||||
|
if voice_name in voices_dict:
|
||||||
|
return voices_dict[voice_name]
|
||||||
|
|
||||||
debug(f"Requested voice not among the voices specified in config/tts.yaml. Checking with ElevenLabs API using api_key: {Tts.elevenlabs.key}.")
|
debug(f"Requested voice not among the voices specified in config/tts.yaml. Checking with ElevenLabs API.")
|
||||||
url = "https://api.elevenlabs.io/v1/voices"
|
url = "https://api.elevenlabs.io/v1/voices"
|
||||||
headers = {"xi-api-key": Tts.elevenlabs.key}
|
headers = {"xi-api-key": Tts.elevenlabs.api_key}
|
||||||
|
debug(f"Using api_key: {Tts.elevenlabs.api_key}")
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
try:
|
try:
|
||||||
response = await client.get(url, headers=headers)
|
response = await client.get(url, headers=headers)
|
||||||
|
@ -230,7 +234,7 @@ async def determine_voice_id(voice_name: str) -> str:
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
voices_data = response.json().get("voices", [])
|
voices_data = response.json().get("voices", [])
|
||||||
for voice in voices_data:
|
for voice in voices_data:
|
||||||
if voice_name == voice["voice_id"] or voice_name.lower() == voice["name"].lower():
|
if voice_name == voice["voice_id"] or (voice_name and voice_name.lower() == voice["name"].lower()):
|
||||||
debug(f"Found voice ID from API - {voice['voice_id']}")
|
debug(f"Found voice ID from API - {voice['voice_id']}")
|
||||||
return voice["voice_id"]
|
return voice["voice_id"]
|
||||||
else:
|
else:
|
||||||
|
@ -240,11 +244,15 @@ async def determine_voice_id(voice_name: str) -> str:
|
||||||
err(f"Error determining voice ID: {str(e)}")
|
err(f"Error determining voice ID: {str(e)}")
|
||||||
|
|
||||||
warn(f"Voice '{voice_name}' not found; using the default specified in config/tts.yaml: {Tts.elevenlabs.default}")
|
warn(f"Voice '{voice_name}' not found; using the default specified in config/tts.yaml: {Tts.elevenlabs.default}")
|
||||||
if Tts.elevenlabs.default in Tts.elevenlabs.voices:
|
if isinstance(voices, dict):
|
||||||
return Tts.elevenlabs.voices[Tts.elevenlabs.default]
|
return voices.get(Tts.elevenlabs.default, next(iter(voices.values())))
|
||||||
|
elif hasattr(voices, '__dict__'):
|
||||||
|
voices_dict = voices.__dict__
|
||||||
|
return voices_dict.get(Tts.elevenlabs.default, next(iter(voices_dict.values())))
|
||||||
else:
|
else:
|
||||||
err(f"Default voice '{Tts.elevenlabs.default}' not found in configuration. Using first available voice.")
|
err(f"Unexpected type for Tts.elevenlabs.voices: {type(voices)}")
|
||||||
return next(iter(Tts.elevenlabs.voices.values()))
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue