Spaces:
Running on Zero
Running on Zero
File size: 4,781 Bytes
0c0ca23 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | r"""Ce que le moteur v2 peut dire en wolof sans avoir l'audio correspondant.
Une réponse dit des noms de ligne (« bus bu Tata, numero … ») et, pour un trajet
avec changement, des noms d'arrêt (« nga wàcc X », « moo lay yóbbu ba Y »). Tout
arrêt du réseau peut être un arrêt de descente ou de changement, dans un sens ou
dans l'autre. Le script ne génère aucun audio. Il écrit :
- ``data/audit/voix_manquantes.csv`` : chaque nom affiché sans audio ;
- ``data/audit/voix_a_generer.csv`` : un audio par prononciation, avec tous les
noms affichés qui s'en servent (les variantes d'orthographe sont regroupées
par les alias de ``tts.speak``).
Un audio compte comme présent dans ``data/tts_cache/`` ou ``data/tts_cache_ajouts/``.
.\.venv\Scripts\python.exe scripts\couverture_voix.py
"""
from __future__ import annotations
import csv
import sys
from pathlib import Path
RACINE = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(RACINE / "src"))
from intent.conversation import TOUTES as CONVERSATION
from matching.lieux import joli
from routing.adapter import _NETWORK
from tts.speak import (
CACHE_DIR,
chemin_audio,
nom_cache_match,
nom_fichier_lieu,
nom_lieu_parle,
phrase_reponse,
)
MANQUANTES = RACINE / "data" / "audit" / "voix_manquantes.csv"
A_GENERER = RACINE / "data" / "audit" / "voix_a_generer.csv"
def _present(fichier: str) -> bool:
return chemin_audio(CACHE_DIR, fichier).is_file()
def main() -> int:
manquantes: list[dict[str, str]] = []
# fichier -> (type, texte à prononcer, noms affichés)
a_generer: dict[str, tuple[str, str, list[str]]] = {}
lignes = sorted(_NETWORK.lines.values(), key=lambda l: (l.company, l.name))
for ligne in lignes:
match = {"compagnie": ligne.company, "ligne": ligne.name}
fichier = nom_cache_match(match)
if _present(fichier):
continue
nom = f"{ligne.company} {ligne.name}"
texte = phrase_reponse([match])
manquantes.append({"type": "ligne", "nom": nom, "dit": texte, "fichier": fichier})
a_generer.setdefault(fichier, ("ligne", texte, []))[2].append(nom)
for arret in sorted(_NETWORK.stop_names):
# La voix dit le nom affiché (joli), comme les cartes.
affiche = joli(arret)
dit = nom_lieu_parle(affiche)
if not dit:
# « (SCOA) » : rien à dire, la voix saute déjà ce lieu.
continue
fichier = nom_fichier_lieu(affiche)
if _present(fichier):
continue
manquantes.append({"type": "arret", "nom": affiche, "dit": dit, "fichier": fichier})
noms = a_generer.setdefault(fichier, ("arret", dit, []))[2]
if affiche not in noms:
noms.append(affiche)
# Les réponses de petite conversation (phrases validées par l'équipe).
for intention in CONVERSATION:
if not _present(intention.fichier):
a_generer.setdefault(
intention.fichier,
("conversation", intention.reponse, [f"conversation : {intention.nom}"]),
)
MANQUANTES.parent.mkdir(parents=True, exist_ok=True)
with MANQUANTES.open("w", encoding="utf-8", newline="") as sortie:
ecrivain = csv.DictWriter(sortie, fieldnames=("type", "nom", "dit", "fichier"))
ecrivain.writeheader()
ecrivain.writerows(manquantes)
with A_GENERER.open("w", encoding="utf-8", newline="") as sortie:
ecrivain = csv.DictWriter(
sortie,
fieldnames=("type", "texte_a_prononcer", "fichier_wav", "utilise_par"),
)
ecrivain.writeheader()
for fichier, (genre, texte, noms) in sorted(
a_generer.items(),
key=lambda item: (
("conversation", "ligne", "arret").index(item[1][0]),
item[1][1],
),
):
ecrivain.writerow(
{
"type": genre,
"texte_a_prononcer": texte,
"fichier_wav": fichier,
"utilise_par": " | ".join(noms),
}
)
compte = {
genre: sum(1 for g, _, _ in a_generer.values() if g == genre)
for genre in ("conversation", "ligne", "arret")
}
print(
f"Noms affichés sans audio : {len(manquantes)}\n"
f"Audios à générer : {len(a_generer)} ({compte['conversation']} conversation, "
f"{compte['ligne']} lignes, {compte['arret']} arrêts)\n"
f"Listes : {MANQUANTES} ; {A_GENERER}"
)
return 0
if __name__ == "__main__":
raise SystemExit(main())
|