zach commited on
Commit
7f69677
·
1 Parent(s): 557e7ca

Update design to accomodate easily adding other TTS providers in the future

Browse files
Files changed (2) hide show
  1. src/app.py +16 -11
  2. src/constants.py +4 -0
src/app.py CHANGED
@@ -28,6 +28,7 @@ from src.constants import (
28
  PROMPT_MIN_LENGTH,
29
  SAMPLE_PROMPTS,
30
  TROPHY_EMOJI,
 
31
  VOTE_FOR_OPTION_A,
32
  VOTE_FOR_OPTION_B,
33
  )
@@ -108,24 +109,28 @@ def text_to_speech(
108
  logger.warning("Skipping text-to-speech due to empty text.")
109
  raise gr.Error("Please generate or enter text to synthesize.")
110
 
 
 
111
  # If not using generated text, then only compare Hume to Hume
112
- compare_hume_with_elevenlabs = (text == generated_text_state) and (
113
- random.random() < 0.5
114
  )
115
 
116
  try:
117
  with ThreadPoolExecutor(max_workers=2) as executor:
118
- provider_a = HUME_AI
119
  future_audio_a = executor.submit(text_to_speech_with_hume, prompt, text)
120
 
121
- if compare_hume_with_elevenlabs:
122
- provider_b = ELEVENLABS
123
- future_audio_b = executor.submit(
124
- text_to_speech_with_elevenlabs, prompt, text
125
- )
126
- else:
127
- provider_b = HUME_AI
128
- future_audio_b = executor.submit(text_to_speech_with_hume, prompt, text)
 
 
 
129
 
130
  audio_a = future_audio_a.result()
131
  audio_b = future_audio_b.result()
 
28
  PROMPT_MIN_LENGTH,
29
  SAMPLE_PROMPTS,
30
  TROPHY_EMOJI,
31
+ TTS_PROVIDERS,
32
  VOTE_FOR_OPTION_A,
33
  VOTE_FOR_OPTION_B,
34
  )
 
109
  logger.warning("Skipping text-to-speech due to empty text.")
110
  raise gr.Error("Please generate or enter text to synthesize.")
111
 
112
+ # Hume AI always included in comparison
113
+ provider_a = HUME_AI
114
  # If not using generated text, then only compare Hume to Hume
115
+ provider_b = (
116
+ HUME_AI if text != generated_text_state else random.choice(TTS_PROVIDERS)
117
  )
118
 
119
  try:
120
  with ThreadPoolExecutor(max_workers=2) as executor:
 
121
  future_audio_a = executor.submit(text_to_speech_with_hume, prompt, text)
122
 
123
+ match provider_b:
124
+ case ELEVENLABS:
125
+ future_audio_b = executor.submit(
126
+ text_to_speech_with_elevenlabs, prompt, text
127
+ )
128
+ case HUME_AI:
129
+ future_audio_b = executor.submit(
130
+ text_to_speech_with_hume, prompt, text
131
+ )
132
+ case _:
133
+ raise ValueError(f"Unsupported provider: {provider_b}")
134
 
135
  audio_a = future_audio_a.result()
136
  audio_b = future_audio_b.result()
src/constants.py CHANGED
@@ -4,6 +4,9 @@ constants.py
4
  This module defines global constants used throughout the project.
5
  """
6
 
 
 
 
7
  # Third-Party Library Imports
8
  from src.types import OptionKey, TTSProviderName
9
 
@@ -11,6 +14,7 @@ from src.types import OptionKey, TTSProviderName
11
  # UI constants
12
  HUME_AI: TTSProviderName = "Hume AI"
13
  ELEVENLABS: TTSProviderName = "ElevenLabs"
 
14
 
15
  PROMPT_MIN_LENGTH: int = 20
16
  PROMPT_MAX_LENGTH: int = 800
 
4
  This module defines global constants used throughout the project.
5
  """
6
 
7
+ # Standard Library Imports
8
+ from typing import List
9
+
10
  # Third-Party Library Imports
11
  from src.types import OptionKey, TTSProviderName
12
 
 
14
  # UI constants
15
  HUME_AI: TTSProviderName = "Hume AI"
16
  ELEVENLABS: TTSProviderName = "ElevenLabs"
17
+ TTS_PROVIDERS: List[TTSProviderName]
18
 
19
  PROMPT_MIN_LENGTH: int = 20
20
  PROMPT_MAX_LENGTH: int = 800