Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -91,27 +91,59 @@ import edge_tts
|
|
| 91 |
from pydub import AudioSegment
|
| 92 |
import soundfile as sf
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
"
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
def get_edge_voices(lang="fr"):
|
| 108 |
-
"""Retourne les voix
|
|
|
|
|
|
|
| 109 |
if lang == "fr":
|
| 110 |
-
return [v for k, v in EDGE_VOICES.items() if
|
| 111 |
elif lang == "nl":
|
| 112 |
-
return [v for k, v in EDGE_VOICES.items() if
|
| 113 |
return list(EDGE_VOICES.values())
|
| 114 |
|
|
|
|
| 115 |
async def _edge_tts_async(text, voice, outfile):
|
| 116 |
communicate = edge_tts.Communicate(text, voice)
|
| 117 |
await communicate.save(outfile)
|
|
@@ -511,12 +543,15 @@ with gr.Blocks(title="Créateur de Capsules CPAS – SadTalker + Kokoro",
|
|
| 511 |
except Exception as e:
|
| 512 |
return gr.update(choices=[], value=None)
|
| 513 |
|
|
|
|
|
|
|
| 514 |
speaker_id = gr.Dropdown(
|
| 515 |
label="🎙 Voix Edge-TTS",
|
| 516 |
choices=get_edge_voices("fr"),
|
| 517 |
value="fr-FR-DeniseNeural",
|
| 518 |
-
info="
|
| 519 |
)
|
|
|
|
| 520 |
langue.change(maj_voix, [langue], [speaker_id])
|
| 521 |
|
| 522 |
voix_type = gr.Radio(["Féminine","Masculine"], label="Voix IA", value="Féminine")
|
|
|
|
| 91 |
from pydub import AudioSegment
|
| 92 |
import soundfile as sf
|
| 93 |
|
| 94 |
+
# ============================================================
|
| 95 |
+
# 🔊 CHARGEMENT DYNAMIQUE DES VOIX EDGE-TTS (FR/NL)
|
| 96 |
+
# ============================================================
|
| 97 |
+
|
| 98 |
+
EDGE_VOICES = {} # dictionnaire rempli dynamiquement
|
| 99 |
+
|
| 100 |
+
async def _fetch_edge_voices():
|
| 101 |
+
"""Charge dynamiquement toutes les voix FR/NL depuis Microsoft Edge-TTS."""
|
| 102 |
+
global EDGE_VOICES
|
| 103 |
+
try:
|
| 104 |
+
voices = await edge_tts.list_voices()
|
| 105 |
+
filtered = [
|
| 106 |
+
v for v in voices
|
| 107 |
+
if v["Locale"].startswith(("fr", "nl"))
|
| 108 |
+
]
|
| 109 |
+
filtered.sort(key=lambda v: (v["Locale"], v["Gender"], v["ShortName"]))
|
| 110 |
+
EDGE_VOICES = {
|
| 111 |
+
f"{'🇫🇷' if v['Locale'].startswith('fr') else '🇳🇱'} {v['DisplayName']} ({v['Gender']}, {v['Locale']})": v["ShortName"]
|
| 112 |
+
for v in filtered
|
| 113 |
+
}
|
| 114 |
+
print(f"[Edge-TTS] {len(EDGE_VOICES)} voix FR/NL chargées.")
|
| 115 |
+
except Exception as e:
|
| 116 |
+
print(f"[Edge-TTS] Erreur chargement voix dynamiques : {e}")
|
| 117 |
+
# fallback minimal
|
| 118 |
+
EDGE_VOICES.update({
|
| 119 |
+
"🇫🇷 Denise (Femme, France)": "fr-FR-DeniseNeural",
|
| 120 |
+
"🇳🇱 Maaike (Femme, NL)": "nl-NL-MaaikeNeural",
|
| 121 |
+
})
|
| 122 |
+
|
| 123 |
+
def init_edge_voices():
|
| 124 |
+
"""Initialise les voix Edge-TTS (pour appel dans Gradio, compatible asyncio)."""
|
| 125 |
+
try:
|
| 126 |
+
loop = asyncio.get_event_loop()
|
| 127 |
+
if loop.is_running():
|
| 128 |
+
import nest_asyncio
|
| 129 |
+
nest_asyncio.apply()
|
| 130 |
+
loop.run_until_complete(_fetch_edge_voices())
|
| 131 |
+
else:
|
| 132 |
+
asyncio.run(_fetch_edge_voices())
|
| 133 |
+
except Exception as e:
|
| 134 |
+
print(f"[Edge-TTS] Impossible de charger les voix dynamiquement : {e}")
|
| 135 |
|
| 136 |
def get_edge_voices(lang="fr"):
|
| 137 |
+
"""Retourne les voix FR/NL disponibles après initialisation."""
|
| 138 |
+
if not EDGE_VOICES:
|
| 139 |
+
init_edge_voices()
|
| 140 |
if lang == "fr":
|
| 141 |
+
return [v for k, v in EDGE_VOICES.items() if "🇫🇷" in k]
|
| 142 |
elif lang == "nl":
|
| 143 |
+
return [v for k, v in EDGE_VOICES.items() if "🇳🇱" in k]
|
| 144 |
return list(EDGE_VOICES.values())
|
| 145 |
|
| 146 |
+
|
| 147 |
async def _edge_tts_async(text, voice, outfile):
|
| 148 |
communicate = edge_tts.Communicate(text, voice)
|
| 149 |
await communicate.save(outfile)
|
|
|
|
| 543 |
except Exception as e:
|
| 544 |
return gr.update(choices=[], value=None)
|
| 545 |
|
| 546 |
+
init_edge_voices() # précharger les voix Edge au lancement
|
| 547 |
+
|
| 548 |
speaker_id = gr.Dropdown(
|
| 549 |
label="🎙 Voix Edge-TTS",
|
| 550 |
choices=get_edge_voices("fr"),
|
| 551 |
value="fr-FR-DeniseNeural",
|
| 552 |
+
info="Liste dynamique des voix Edge-TTS (FR & NL)"
|
| 553 |
)
|
| 554 |
+
|
| 555 |
langue.change(maj_voix, [langue], [speaker_id])
|
| 556 |
|
| 557 |
voix_type = gr.Radio(["Féminine","Masculine"], label="Voix IA", value="Féminine")
|