Spaces:
Running
Running
zach
commited on
Commit
·
8fc5d19
1
Parent(s):
fb9daf9
Update _synthesize_text to call APIs concurrently
Browse files- src/frontend.py +13 -9
src/frontend.py
CHANGED
@@ -126,19 +126,23 @@ class Frontend:
|
|
126 |
provider_a = constants.HUME_AI # always compare with Hume
|
127 |
provider_b = get_random_provider(text_modified)
|
128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
try:
|
130 |
logger.info(f"Starting speech synthesis with providers: {provider_a} and {provider_b}")
|
131 |
-
generation_id_a, audio_a = await text_to_speech_with_hume(character_description, text, self.config)
|
132 |
-
|
133 |
-
tts_provider_funcs = {
|
134 |
-
constants.HUME_AI: text_to_speech_with_hume,
|
135 |
-
constants.ELEVENLABS: text_to_speech_with_elevenlabs,
|
136 |
-
}
|
137 |
|
138 |
-
|
139 |
-
|
|
|
140 |
|
141 |
-
|
|
|
142 |
|
143 |
option_a = Option(provider=provider_a, audio=audio_a, generation_id=generation_id_a)
|
144 |
option_b = Option(provider=provider_b, audio=audio_b, generation_id=generation_id_b)
|
|
|
126 |
provider_a = constants.HUME_AI # always compare with Hume
|
127 |
provider_b = get_random_provider(text_modified)
|
128 |
|
129 |
+
tts_provider_funcs = {
|
130 |
+
constants.HUME_AI: text_to_speech_with_hume,
|
131 |
+
constants.ELEVENLABS: text_to_speech_with_elevenlabs,
|
132 |
+
}
|
133 |
+
|
134 |
+
if provider_b not in tts_provider_funcs:
|
135 |
+
raise ValueError(f"Unsupported provider: {provider_b}")
|
136 |
+
|
137 |
try:
|
138 |
logger.info(f"Starting speech synthesis with providers: {provider_a} and {provider_b}")
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
|
140 |
+
# Create two tasks for concurrent execution
|
141 |
+
task_a = text_to_speech_with_hume(character_description, text, self.config)
|
142 |
+
task_b = tts_provider_funcs[provider_b](character_description, text, self.config)
|
143 |
|
144 |
+
# Await both tasks concurrently using asyncio.gather()
|
145 |
+
(generation_id_a, audio_a), (generation_id_b, audio_b) = await asyncio.gather(task_a, task_b)
|
146 |
|
147 |
option_a = Option(provider=provider_a, audio=audio_a, generation_id=generation_id_a)
|
148 |
option_b = Option(provider=provider_b, audio=audio_b, generation_id=generation_id_b)
|