Spaces:
Running
Running
zach
commited on
Commit
·
e560bf3
1
Parent(s):
681c05f
Clean up ElevenLabsConfig
Browse files
src/integrations/elevenlabs_api.py
CHANGED
@@ -35,10 +35,14 @@ from src.utils import validate_env_var, truncate_text
|
|
35 |
class ElevenLabsConfig:
|
36 |
"""Immutable configuration for interacting with the ElevenLabs TTS API."""
|
37 |
api_key: str = validate_env_var("ELEVENLABS_API_KEY")
|
38 |
-
# voice_id: str = "pNInz6obpgDQGcFmaJgB" # Adam (popular ElevenLabs pre-made voice)
|
39 |
-
top_voices: list[str] = None # Predefined top default voices
|
40 |
model_id: str = "eleven_multilingual_v2" # ElevenLab's most emotionally expressive model
|
41 |
output_format: str = "mp3_44100_128" # Output format of the generated audio.
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
def __post_init__(self):
|
44 |
# Validate that required attributes are set
|
@@ -49,21 +53,8 @@ class ElevenLabsConfig:
|
|
49 |
if not self.output_format:
|
50 |
raise ValueError("ElevenLabs Output Format is not set.")
|
51 |
if not self.top_voices:
|
52 |
-
|
53 |
-
object.__setattr__(self, "top_voices", [
|
54 |
-
"pNInz6obpgDQGcFmaJgB", # Adam
|
55 |
-
"ErXwobaYiN019PkySvjV", # Antoni
|
56 |
-
"21m00Tcm4TlvDq8ikWAM", # Rachel
|
57 |
-
"txTPZhQpfI89VbqtG6v7", # Matilda
|
58 |
-
])
|
59 |
|
60 |
-
@property
|
61 |
-
def random_voice_id(self) -> str:
|
62 |
-
"""
|
63 |
-
Randomly selects a voice ID from the top default voices, ensuring different voices across calls.
|
64 |
-
"""
|
65 |
-
return random.choice(self.top_voices)
|
66 |
-
|
67 |
@property
|
68 |
def client(self) -> ElevenLabs:
|
69 |
"""
|
@@ -74,6 +65,13 @@ class ElevenLabsConfig:
|
|
74 |
"""
|
75 |
return ElevenLabs(api_key=self.api_key)
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
class ElevenLabsException(Exception):
|
79 |
"""Custom exception for errors related to the ElevenLabs TTS API."""
|
|
|
35 |
class ElevenLabsConfig:
|
36 |
"""Immutable configuration for interacting with the ElevenLabs TTS API."""
|
37 |
api_key: str = validate_env_var("ELEVENLABS_API_KEY")
|
|
|
|
|
38 |
model_id: str = "eleven_multilingual_v2" # ElevenLab's most emotionally expressive model
|
39 |
output_format: str = "mp3_44100_128" # Output format of the generated audio.
|
40 |
+
top_voices: list[str] = (
|
41 |
+
"pNInz6obpgDQGcFmaJgB", # Adam
|
42 |
+
"ErXwobaYiN019PkySvjV", # Antoni
|
43 |
+
"21m00Tcm4TlvDq8ikWAM", # Rachel
|
44 |
+
"XrExE9yKIg1WjnnlVkGX", # Matilda
|
45 |
+
)
|
46 |
|
47 |
def __post_init__(self):
|
48 |
# Validate that required attributes are set
|
|
|
53 |
if not self.output_format:
|
54 |
raise ValueError("ElevenLabs Output Format is not set.")
|
55 |
if not self.top_voices:
|
56 |
+
raise ValueError("ElevenLabs Top Voices are not set.")
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
@property
|
59 |
def client(self) -> ElevenLabs:
|
60 |
"""
|
|
|
65 |
"""
|
66 |
return ElevenLabs(api_key=self.api_key)
|
67 |
|
68 |
+
@property
|
69 |
+
def random_voice_id(self) -> str:
|
70 |
+
"""
|
71 |
+
Randomly selects a voice ID from the top default voices, ensuring different voices across calls.
|
72 |
+
"""
|
73 |
+
return random.choice(self.top_voices)
|
74 |
+
|
75 |
|
76 |
class ElevenLabsException(Exception):
|
77 |
"""Custom exception for errors related to the ElevenLabs TTS API."""
|