Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
|
@@ -128,24 +128,60 @@ PRESET_VOICES = [
|
|
| 128 |
"Mia -- Young, versatile", "Aiden -- Young, lively",
|
| 129 |
]
|
| 130 |
|
| 131 |
-
# YourVoic voices
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
"
|
| 136 |
-
"
|
| 137 |
-
"
|
| 138 |
-
|
| 139 |
-
"
|
| 140 |
-
"
|
| 141 |
-
"
|
| 142 |
-
"
|
| 143 |
-
"
|
| 144 |
-
"
|
| 145 |
-
"
|
| 146 |
-
"
|
| 147 |
-
"
|
| 148 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
YOURVOIC_MODELS = [
|
| 151 |
"aura-prime -- Balanced quality and speed (recommended)",
|
|
@@ -425,14 +461,17 @@ def generate_speech_yourvoic(client, text, voice, yv_model, emotion, language, l
|
|
| 425 |
except Exception as e:
|
| 426 |
print(f"[YourVoic] Translation failed, using English: {e}")
|
| 427 |
|
| 428 |
-
# Build request
|
| 429 |
yourvoic_lang = lang_config.get("yourvoic", "en-US")
|
|
|
|
|
|
|
|
|
|
| 430 |
payload = {
|
| 431 |
"text": final_text,
|
| 432 |
-
"voice":
|
| 433 |
"language": yourvoic_lang,
|
| 434 |
"model": yv_model,
|
| 435 |
-
"speed": 0.9,
|
| 436 |
}
|
| 437 |
# Add emotion if not neutral
|
| 438 |
if emotion and emotion != "neutral":
|
|
@@ -770,7 +809,7 @@ with gr.Blocks(title="Audiobook Generator") as demo:
|
|
| 770 |
)
|
| 771 |
|
| 772 |
# YourVoic controls
|
| 773 |
-
yv_voice = gr.Dropdown(choices=YOURVOIC_VOICES, value="
|
| 774 |
label="YourVoic Voice", visible=False, allow_custom_value=True,
|
| 775 |
info="Type any voice name or pick from the list")
|
| 776 |
yv_model = gr.Dropdown(choices=YOURVOIC_MODELS, value="aura-prime -- Balanced quality and speed (recommended)",
|
|
|
|
| 128 |
"Mia -- Young, versatile", "Aiden -- Young, lively",
|
| 129 |
]
|
| 130 |
|
| 131 |
+
# YourVoic voices mapped by language
|
| 132 |
+
# Each language has specific voice names on YourVoic
|
| 133 |
+
YOURVOIC_VOICE_MAP = {
|
| 134 |
+
# African
|
| 135 |
+
"Afrikaans": ["Annika", "Willem"],
|
| 136 |
+
"Amharic": ["Abebe", "Meron"],
|
| 137 |
+
"Swahili": ["Jabari", "Amara"],
|
| 138 |
+
# Indian
|
| 139 |
+
"Hindi": ["Natasha", "Rahul", "Deepika", "Aditya"],
|
| 140 |
+
"Marathi": ["Anjali", "Rohan"],
|
| 141 |
+
"Bengali": ["Sneha", "Aryan"],
|
| 142 |
+
"Telugu": ["Arjun", "Lakshmi"],
|
| 143 |
+
"Tamil": ["Priya", "Kumar"],
|
| 144 |
+
"Gujarati": ["Rahul", "Meera"],
|
| 145 |
+
"Kannada": ["Divya", "Karthik"],
|
| 146 |
+
"Malayalam": ["Nikhil", "Ammu"],
|
| 147 |
+
"Punjabi": ["Vikram", "Simran"],
|
| 148 |
+
"Odia": ["Kavya", "Subham"],
|
| 149 |
+
"Assamese": ["Jyoti", "Bikash"],
|
| 150 |
+
"Maithili": ["Priya", "Rahul"],
|
| 151 |
+
"Kashmiri": ["Priya", "Rahul"],
|
| 152 |
+
"Sindhi": ["Priya", "Rahul"],
|
| 153 |
+
"Konkani": ["Priya", "Rahul"],
|
| 154 |
+
"Dogri": ["Priya", "Rahul"],
|
| 155 |
+
"Manipuri": ["Priya", "Rahul"],
|
| 156 |
+
"Bodo": ["Priya", "Rahul"],
|
| 157 |
+
"Sanskrit": ["Priya", "Rahul"],
|
| 158 |
+
# South Asian
|
| 159 |
+
"Urdu": ["Natasha", "Rahul"],
|
| 160 |
+
"Nepali": ["Priya", "Rahul"],
|
| 161 |
+
"Sinhala": ["Priya", "Rahul"],
|
| 162 |
+
# Fallback
|
| 163 |
+
"English": ["Peter", "Sarah", "Caleb"],
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
# Build voice dropdown choices from the map
|
| 167 |
+
YOURVOIC_VOICES = []
|
| 168 |
+
for lang, voices in YOURVOIC_VOICE_MAP.items():
|
| 169 |
+
for v in voices:
|
| 170 |
+
entry = f"{v} -- {lang}"
|
| 171 |
+
if entry not in YOURVOIC_VOICES:
|
| 172 |
+
YOURVOIC_VOICES.append(entry)
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def get_yourvoic_voice_for_language(language, selected_voice):
|
| 176 |
+
"""Get a valid voice name for the given language.
|
| 177 |
+
If the selected voice is valid for this language, use it.
|
| 178 |
+
Otherwise, fall back to the first voice for that language."""
|
| 179 |
+
voice_name = get_voice_name(selected_voice)
|
| 180 |
+
valid_voices = YOURVOIC_VOICE_MAP.get(language, YOURVOIC_VOICE_MAP.get("English", ["Peter"]))
|
| 181 |
+
if voice_name in valid_voices:
|
| 182 |
+
return voice_name
|
| 183 |
+
# Return first valid voice for this language
|
| 184 |
+
return valid_voices[0]
|
| 185 |
|
| 186 |
YOURVOIC_MODELS = [
|
| 187 |
"aura-prime -- Balanced quality and speed (recommended)",
|
|
|
|
| 461 |
except Exception as e:
|
| 462 |
print(f"[YourVoic] Translation failed, using English: {e}")
|
| 463 |
|
| 464 |
+
# Build request - auto-map voice to language
|
| 465 |
yourvoic_lang = lang_config.get("yourvoic", "en-US")
|
| 466 |
+
valid_voice = get_yourvoic_voice_for_language(language, voice)
|
| 467 |
+
print(f"[YourVoic] Language: {language}, requested voice: {voice}, using: {valid_voice}")
|
| 468 |
+
|
| 469 |
payload = {
|
| 470 |
"text": final_text,
|
| 471 |
+
"voice": valid_voice,
|
| 472 |
"language": yourvoic_lang,
|
| 473 |
"model": yv_model,
|
| 474 |
+
"speed": 0.9,
|
| 475 |
}
|
| 476 |
# Add emotion if not neutral
|
| 477 |
if emotion and emotion != "neutral":
|
|
|
|
| 809 |
)
|
| 810 |
|
| 811 |
# YourVoic controls
|
| 812 |
+
yv_voice = gr.Dropdown(choices=YOURVOIC_VOICES, value="Natasha -- Hindi",
|
| 813 |
label="YourVoic Voice", visible=False, allow_custom_value=True,
|
| 814 |
info="Type any voice name or pick from the list")
|
| 815 |
yv_model = gr.Dropdown(choices=YOURVOIC_MODELS, value="aura-prime -- Balanced quality and speed (recommended)",
|