plotagon-director 0.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. plotagon_director-0.6.0/LICENSE +21 -0
  2. plotagon_director-0.6.0/PKG-INFO +143 -0
  3. plotagon_director-0.6.0/README.md +117 -0
  4. plotagon_director-0.6.0/plotagon_director/__init__.py +3 -0
  5. plotagon_director-0.6.0/plotagon_director/audio/__init__.py +0 -0
  6. plotagon_director-0.6.0/plotagon_director/audio/phonemes.py +70 -0
  7. plotagon_director-0.6.0/plotagon_director/audio/tts.py +163 -0
  8. plotagon_director-0.6.0/plotagon_director/cli.py +308 -0
  9. plotagon_director-0.6.0/plotagon_director/core/__init__.py +0 -0
  10. plotagon_director-0.6.0/plotagon_director/core/archive.py +35 -0
  11. plotagon_director-0.6.0/plotagon_director/core/decompiler.py +120 -0
  12. plotagon_director-0.6.0/plotagon_director/core/diffplot.py +89 -0
  13. plotagon_director-0.6.0/plotagon_director/core/doctor.py +67 -0
  14. plotagon_director-0.6.0/plotagon_director/core/plotdoc.py +178 -0
  15. plotagon_director-0.6.0/plotagon_director/core/validator.py +165 -0
  16. plotagon_director-0.6.0/plotagon_director/library/__init__.py +14 -0
  17. plotagon_director-0.6.0/plotagon_director/library/builder.py +153 -0
  18. plotagon_director-0.6.0/plotagon_director/library/data/library.json +4819 -0
  19. plotagon_director-0.6.0/plotagon_director.egg-info/PKG-INFO +143 -0
  20. plotagon_director-0.6.0/plotagon_director.egg-info/SOURCES.txt +28 -0
  21. plotagon_director-0.6.0/plotagon_director.egg-info/dependency_links.txt +1 -0
  22. plotagon_director-0.6.0/plotagon_director.egg-info/entry_points.txt +2 -0
  23. plotagon_director-0.6.0/plotagon_director.egg-info/requires.txt +12 -0
  24. plotagon_director-0.6.0/plotagon_director.egg-info/top_level.txt +1 -0
  25. plotagon_director-0.6.0/pyproject.toml +41 -0
  26. plotagon_director-0.6.0/setup.cfg +4 -0
  27. plotagon_director-0.6.0/tests/test_actions.py +47 -0
  28. plotagon_director-0.6.0/tests/test_cli_extras.py +81 -0
  29. plotagon_director-0.6.0/tests/test_music_camera.py +66 -0
  30. plotagon_director-0.6.0/tests/test_validator.py +87 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mohamed Amine Ben Mallessa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,143 @@
1
+ Metadata-Version: 2.4
2
+ Name: plotagon-director
3
+ Version: 0.6.0
4
+ Summary: Génération de films Plotagon Studio Desktop (.plot) avec voix Edge TTS et synchro labiale
5
+ Author: Mohamed Amine Ben Mallessa
6
+ License: MIT
7
+ Project-URL: LinkedIn, https://www.linkedin.com/in/benmallessa/
8
+ Keywords: plotagon,tts,video,animation
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: pyyaml
16
+ Requires-Dist: edge-tts
17
+ Requires-Dist: soundfile
18
+ Requires-Dist: numpy
19
+ Requires-Dist: truststore
20
+ Provides-Extra: library
21
+ Requires-Dist: UnityPy; extra == "library"
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest; extra == "dev"
24
+ Requires-Dist: UnityPy; extra == "dev"
25
+ Dynamic: license-file
26
+
27
+ # Plotagon Director
28
+
29
+ Génération de films [Plotagon Studio Desktop](https://www.plotagon.com) de
30
+ bout en bout : écriture du scénario en YAML, validation contre la bibliothèque
31
+ de ressources réelle, génération d'un fichier `.plot` importable dans
32
+ l'application officielle — avec voix custom Edge TTS et synchro labiale.
33
+
34
+ Le format `.plot` a été entièrement rétro-ingénieré et confirmé par analyse
35
+ d'exports officiels (v1.11.0) : ZIP contenant un document JSON `.plotdoc`
36
+ (liste plate d'instructions `scene`, `dialogue`, `music`, `action`) et, par
37
+ réplique vocalisée, un WAV mono 44,1 kHz + un fichier `.phonemes` (protobuf)
38
+ pour la synchro labiale. Spécification complète : `docs/PLOT_FORMAT.md`.
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ pip install -e . # depuis un clone: commande `plotagon-director`
44
+ # ou directement depuis GitHub :
45
+ pip install git+https://github.com/mohamed-amine-ben-mallessa/plotagon-director.git
46
+ ```
47
+
48
+ La bibliothèque de ressources (`library.json`) est embarquée dans le package :
49
+ le générateur fonctionne sans installation Plotagon. L'extra `[library]`
50
+ (`pip install -e .[library]`, ajoute UnityPy) n'est nécessaire que pour
51
+ **reconstruire** la bibliothèque depuis une installation Plotagon.
52
+
53
+ ## Usage
54
+
55
+ ```bash
56
+ # Écrire un scénario
57
+ plotagon-director new "Mon film" # squelette commenté
58
+ plotagon-director list scenes --filter cafe # aussi: characters, expressions,
59
+ plotagon-director list actions # music, sounds, voices
60
+ plotagon-director positions restaurants.cafe # slots d'acteurs d'une scène
61
+ plotagon-director voices fr # voix Edge TTS disponibles
62
+ plotagon-director say "Bonjour" fr-FR-DeniseNeural # écouter une voix
63
+
64
+ # Valider puis générer
65
+ plotagon-director validate mon-film.yaml [--strict]
66
+ plotagon-director build mon-film.yaml mon-film.plot
67
+ # --no-voices : hors ligne | --srt subs.srt : sous-titres
68
+ # --no-cache : resynthétise tout (sinon cache TTS automatique)
69
+ plotagon-director batch scenarios/ sorties/ # tous les .yaml d'un dossier
70
+
71
+ # Importer mon-film.plot dans Plotagon Studio (menu import)
72
+
73
+ # Analyse / rétro-ingénierie
74
+ plotagon-director parse export.plot # JSON brut d'un .plot
75
+ plotagon-director decompile export.plot film.yaml # .plot -> YAML éditable
76
+ plotagon-director diff avant.plot apres.plot # isoler un format inconnu
77
+ plotagon-director doctor # diagnostic environnement
78
+
79
+ # (Reconstruire la bibliothèque depuis une installation Plotagon)
80
+ python -m plotagon_director.library.builder [chemin/builtincontentmanifest.json]
81
+ ```
82
+
83
+ ## Exemple de scénario
84
+
85
+ ```yaml
86
+ project:
87
+ title: "Conversation au café"
88
+
89
+ cast:
90
+ - ref: paul
91
+ character: news.paul
92
+ name: "Paul"
93
+ voice: fr-FR-HenriNeural # optionnel : voix Edge TTS (+ rate/pitch)
94
+ - ref: lucy
95
+ character: news.lucy
96
+ name: "Lucy"
97
+ voice: fr-FR-DeniseNeural
98
+
99
+ scenes:
100
+ - scene: restaurants.cafe
101
+ music: music.corny # optionnel (music.stopmusic pour arrêter)
102
+ actors:
103
+ - ref: paul
104
+ position: Table1 # `plotagon-director positions restaurants.cafe`
105
+ - ref: lucy
106
+ position: Table2
107
+ dialogue:
108
+ - actor: paul
109
+ expression: happy
110
+ text: "Bonjour Lucy !"
111
+ camera: wide shot # optionnel : 10 types (docs/PLOT_FORMAT.md)
112
+ - actor: paul # interaction à 2 personnages
113
+ action: handshake
114
+ target: lucy
115
+ ```
116
+
117
+ Bibliothèque embarquée : 205 scènes (953 positions), 53 personnages,
118
+ 88 expressions, 15 actions, 38 musiques, 132 sons.
119
+
120
+ ## Architecture
121
+
122
+ - `plotagon_director/core/` — modèle `.plotdoc`, conteneur ZIP, validateur,
123
+ décompilateur, diff
124
+ - `plotagon_director/audio/` — Edge TTS → WAV conforme (cache + parallèle),
125
+ phonèmes/lip-sync
126
+ - `plotagon_director/library/` — builder du catalogue + `data/library.json`
127
+ - `docs/` — rétro-ingénierie du format (`PLOT_FORMAT.md`), API interne de
128
+ l'appli (`APP_JS_ANALYSIS.md`), état des connaissances (`FINDINGS.md`)
129
+ - `SKILL.md` — utilisation comme skill Claude Code
130
+
131
+ ## Principes
132
+
133
+ - Aucun mod, aucun binaire tiers, aucun credential.
134
+ - Installation officielle en lecture seule.
135
+ - Seuls les éléments confirmés par un export officiel sont générés ; le
136
+ reste (effets visuels, sons importés) est documenté UNKNOWN dans
137
+ `docs/FINDINGS.md`.
138
+
139
+ ## Tests
140
+
141
+ ```bash
142
+ python -m pytest tests/ -q
143
+ ```
@@ -0,0 +1,117 @@
1
+ # Plotagon Director
2
+
3
+ Génération de films [Plotagon Studio Desktop](https://www.plotagon.com) de
4
+ bout en bout : écriture du scénario en YAML, validation contre la bibliothèque
5
+ de ressources réelle, génération d'un fichier `.plot` importable dans
6
+ l'application officielle — avec voix custom Edge TTS et synchro labiale.
7
+
8
+ Le format `.plot` a été entièrement rétro-ingénieré et confirmé par analyse
9
+ d'exports officiels (v1.11.0) : ZIP contenant un document JSON `.plotdoc`
10
+ (liste plate d'instructions `scene`, `dialogue`, `music`, `action`) et, par
11
+ réplique vocalisée, un WAV mono 44,1 kHz + un fichier `.phonemes` (protobuf)
12
+ pour la synchro labiale. Spécification complète : `docs/PLOT_FORMAT.md`.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pip install -e . # depuis un clone: commande `plotagon-director`
18
+ # ou directement depuis GitHub :
19
+ pip install git+https://github.com/mohamed-amine-ben-mallessa/plotagon-director.git
20
+ ```
21
+
22
+ La bibliothèque de ressources (`library.json`) est embarquée dans le package :
23
+ le générateur fonctionne sans installation Plotagon. L'extra `[library]`
24
+ (`pip install -e .[library]`, ajoute UnityPy) n'est nécessaire que pour
25
+ **reconstruire** la bibliothèque depuis une installation Plotagon.
26
+
27
+ ## Usage
28
+
29
+ ```bash
30
+ # Écrire un scénario
31
+ plotagon-director new "Mon film" # squelette commenté
32
+ plotagon-director list scenes --filter cafe # aussi: characters, expressions,
33
+ plotagon-director list actions # music, sounds, voices
34
+ plotagon-director positions restaurants.cafe # slots d'acteurs d'une scène
35
+ plotagon-director voices fr # voix Edge TTS disponibles
36
+ plotagon-director say "Bonjour" fr-FR-DeniseNeural # écouter une voix
37
+
38
+ # Valider puis générer
39
+ plotagon-director validate mon-film.yaml [--strict]
40
+ plotagon-director build mon-film.yaml mon-film.plot
41
+ # --no-voices : hors ligne | --srt subs.srt : sous-titres
42
+ # --no-cache : resynthétise tout (sinon cache TTS automatique)
43
+ plotagon-director batch scenarios/ sorties/ # tous les .yaml d'un dossier
44
+
45
+ # Importer mon-film.plot dans Plotagon Studio (menu import)
46
+
47
+ # Analyse / rétro-ingénierie
48
+ plotagon-director parse export.plot # JSON brut d'un .plot
49
+ plotagon-director decompile export.plot film.yaml # .plot -> YAML éditable
50
+ plotagon-director diff avant.plot apres.plot # isoler un format inconnu
51
+ plotagon-director doctor # diagnostic environnement
52
+
53
+ # (Reconstruire la bibliothèque depuis une installation Plotagon)
54
+ python -m plotagon_director.library.builder [chemin/builtincontentmanifest.json]
55
+ ```
56
+
57
+ ## Exemple de scénario
58
+
59
+ ```yaml
60
+ project:
61
+ title: "Conversation au café"
62
+
63
+ cast:
64
+ - ref: paul
65
+ character: news.paul
66
+ name: "Paul"
67
+ voice: fr-FR-HenriNeural # optionnel : voix Edge TTS (+ rate/pitch)
68
+ - ref: lucy
69
+ character: news.lucy
70
+ name: "Lucy"
71
+ voice: fr-FR-DeniseNeural
72
+
73
+ scenes:
74
+ - scene: restaurants.cafe
75
+ music: music.corny # optionnel (music.stopmusic pour arrêter)
76
+ actors:
77
+ - ref: paul
78
+ position: Table1 # `plotagon-director positions restaurants.cafe`
79
+ - ref: lucy
80
+ position: Table2
81
+ dialogue:
82
+ - actor: paul
83
+ expression: happy
84
+ text: "Bonjour Lucy !"
85
+ camera: wide shot # optionnel : 10 types (docs/PLOT_FORMAT.md)
86
+ - actor: paul # interaction à 2 personnages
87
+ action: handshake
88
+ target: lucy
89
+ ```
90
+
91
+ Bibliothèque embarquée : 205 scènes (953 positions), 53 personnages,
92
+ 88 expressions, 15 actions, 38 musiques, 132 sons.
93
+
94
+ ## Architecture
95
+
96
+ - `plotagon_director/core/` — modèle `.plotdoc`, conteneur ZIP, validateur,
97
+ décompilateur, diff
98
+ - `plotagon_director/audio/` — Edge TTS → WAV conforme (cache + parallèle),
99
+ phonèmes/lip-sync
100
+ - `plotagon_director/library/` — builder du catalogue + `data/library.json`
101
+ - `docs/` — rétro-ingénierie du format (`PLOT_FORMAT.md`), API interne de
102
+ l'appli (`APP_JS_ANALYSIS.md`), état des connaissances (`FINDINGS.md`)
103
+ - `SKILL.md` — utilisation comme skill Claude Code
104
+
105
+ ## Principes
106
+
107
+ - Aucun mod, aucun binaire tiers, aucun credential.
108
+ - Installation officielle en lecture seule.
109
+ - Seuls les éléments confirmés par un export officiel sont générés ; le
110
+ reste (effets visuels, sons importés) est documenté UNKNOWN dans
111
+ `docs/FINDINGS.md`.
112
+
113
+ ## Tests
114
+
115
+ ```bash
116
+ python -m pytest tests/ -q
117
+ ```
@@ -0,0 +1,3 @@
1
+ """plotagon_director — generation de films Plotagon Studio Desktop (.plot)."""
2
+
3
+ __version__ = "0.6.0"
@@ -0,0 +1,70 @@
1
+ """Fichiers .phonemes (synchro labiale) au format de Plotagon Studio.
2
+
3
+ Format CONFIRME par decodage d'un export officiel : messages protobuf
4
+ concatenes, un par trame de 2048 echantillons (~46.4 ms a 44100 Hz) :
5
+
6
+ champ 1 (tag 0x0d, float32 LE) : debut en secondes (omis si 0)
7
+ champ 2 (tag 0x15, float32 LE) : fin en secondes
8
+ champ 3 (tag 0x1a, string) : phoneme
9
+
10
+ Phonemes observes : sil, ae, d, eh, l, m, n, ow, uu, uw.
11
+ """
12
+
13
+ import io
14
+ import struct
15
+ import wave
16
+
17
+ FRAME_SAMPLES = 2048
18
+
19
+ # Cycle de voyelles pour la synchro labiale approximative (amplitude-based).
20
+ _MOUTH_CYCLE = ["eh", "ae", "ow", "eh", "uw", "ae"]
21
+
22
+
23
+ def phonemes_from_wav(wav_bytes):
24
+ """Synchro labiale approximative par enveloppe d'amplitude.
25
+
26
+ L'appli genere les phonemes par analyse du signal ; ici on approxime :
27
+ trames silencieuses -> "sil", trames parlees -> cycle de voyelles.
28
+ """
29
+ import numpy as np
30
+
31
+ with wave.open(io.BytesIO(wav_bytes)) as w:
32
+ rate = w.getframerate()
33
+ pcm = np.frombuffer(w.readframes(w.getnframes()), dtype="<i2")
34
+
35
+ records = []
36
+ n_frames = max(1, (len(pcm) + FRAME_SAMPLES - 1) // FRAME_SAMPLES)
37
+ rms = np.array([
38
+ np.sqrt(np.mean(
39
+ pcm[i * FRAME_SAMPLES:(i + 1) * FRAME_SAMPLES].astype("f8") ** 2
40
+ )) if len(pcm[i * FRAME_SAMPLES:(i + 1) * FRAME_SAMPLES]) else 0.0
41
+ for i in range(n_frames)
42
+ ])
43
+ threshold = max(300.0, float(rms.max()) * 0.08)
44
+
45
+ mouth = 0
46
+ for i in range(n_frames):
47
+ start = i * FRAME_SAMPLES / rate
48
+ end = min((i + 1) * FRAME_SAMPLES, len(pcm)) / rate
49
+ if rms[i] >= threshold:
50
+ label = _MOUTH_CYCLE[(mouth // 2) % len(_MOUTH_CYCLE)]
51
+ mouth += 1
52
+ else:
53
+ label = "sil"
54
+ mouth = 0
55
+ records.append((start, end, label))
56
+ return records
57
+
58
+
59
+ def encode_phonemes(records):
60
+ """Encode les enregistrements au format protobuf observe."""
61
+ out = bytearray()
62
+ for start, end, label in records:
63
+ body = bytearray()
64
+ if start > 0.0:
65
+ body += b"\x0d" + struct.pack("<f", start)
66
+ body += b"\x15" + struct.pack("<f", end)
67
+ raw = label.encode()
68
+ body += b"\x1a" + bytes([len(raw)]) + raw
69
+ out += b"\x0a" + bytes([len(body)]) + body
70
+ return bytes(out)
@@ -0,0 +1,163 @@
1
+ """Synthese vocale Edge TTS au format audio de Plotagon Studio.
2
+
3
+ Format CONFIRME (export officiel 1.11.0) : WAV PCM mono 44100 Hz 16 bits.
4
+
5
+ Deux optimisations pour l'iteration rapide :
6
+ - cache disque (%LOCALAPPDATA%/plotagon-director/tts-cache) par hash de
7
+ (texte, voix, rate, pitch) — un rebuild sans changement ne touche pas
8
+ au reseau ;
9
+ - synthese parallele (asyncio) pour les films a nombreuses repliques.
10
+ """
11
+
12
+ import asyncio
13
+ import hashlib
14
+ import io
15
+ import os
16
+ import wave
17
+ from pathlib import Path
18
+
19
+ TARGET_RATE = 44100
20
+ CONCURRENCY = 4
21
+
22
+ CACHE_DIR = (
23
+ Path(os.environ.get("LOCALAPPDATA", str(Path.home())))
24
+ / "plotagon-director" / "tts-cache"
25
+ )
26
+
27
+
28
+ def _inject_truststore():
29
+ """Fait utiliser a Python le magasin de certificats Windows.
30
+
31
+ Indispensable derriere un antivirus qui intercepte le TLS (ex. Norton).
32
+ """
33
+ try:
34
+ import truststore
35
+ truststore.inject_into_ssl()
36
+ except ImportError:
37
+ pass
38
+
39
+
40
+ def _cache_path(text, voice, rate, pitch):
41
+ key = "%s|%s|%s|%s" % (text, voice, rate or "", pitch or "")
42
+ return CACHE_DIR / (hashlib.sha256(key.encode("utf-8")).hexdigest() + ".wav")
43
+
44
+
45
+ async def _fetch_mp3(text, voice, rate=None, pitch=None):
46
+ import edge_tts
47
+
48
+ kwargs = {}
49
+ if rate:
50
+ kwargs["rate"] = rate
51
+ if pitch:
52
+ kwargs["pitch"] = pitch
53
+ communicate = edge_tts.Communicate(text, voice, **kwargs)
54
+ buf = io.BytesIO()
55
+ async for chunk in communicate.stream():
56
+ if chunk["type"] == "audio":
57
+ buf.write(chunk["data"])
58
+ return buf.getvalue()
59
+
60
+
61
+ def _mp3_to_wav(mp3_bytes):
62
+ import numpy as np
63
+ import soundfile as sf
64
+
65
+ data, sr = sf.read(io.BytesIO(mp3_bytes), dtype="float32")
66
+ if data.ndim > 1:
67
+ data = data.mean(axis=1)
68
+ if sr != TARGET_RATE:
69
+ n_out = int(round(len(data) * TARGET_RATE / sr))
70
+ x_old = np.linspace(0.0, 1.0, num=len(data), endpoint=False)
71
+ x_new = np.linspace(0.0, 1.0, num=n_out, endpoint=False)
72
+ data = np.interp(x_new, x_old, data).astype("float32")
73
+
74
+ pcm = (np.clip(data, -1.0, 1.0) * 32767).astype("<i2")
75
+ out = io.BytesIO()
76
+ with wave.open(out, "wb") as w:
77
+ w.setnchannels(1)
78
+ w.setsampwidth(2)
79
+ w.setframerate(TARGET_RATE)
80
+ w.writeframes(pcm.tobytes())
81
+ return out.getvalue()
82
+
83
+
84
+ def synthesize_wav(text, voice, rate=None, pitch=None, use_cache=True):
85
+ """Synthetise une replique et retourne des octets WAV 44.1k mono 16b."""
86
+ if use_cache:
87
+ cached = _cache_path(text, voice, rate, pitch)
88
+ if cached.exists():
89
+ return cached.read_bytes()
90
+
91
+ _inject_truststore()
92
+ wav = _mp3_to_wav(asyncio.run(_fetch_mp3(text, voice, rate, pitch)))
93
+
94
+ if use_cache:
95
+ CACHE_DIR.mkdir(parents=True, exist_ok=True)
96
+ cached.write_bytes(wav)
97
+ return wav
98
+
99
+
100
+ def synthesize_many(jobs, use_cache=True, progress=None):
101
+ """Synthetise plusieurs repliques en parallele.
102
+
103
+ jobs : liste de dicts {"guid", "text", "voice", "rate", "pitch"}.
104
+ progress : callback(job, from_cache) appele apres chaque replique.
105
+ Retourne {guid: wav_bytes}.
106
+ """
107
+ results = {}
108
+ to_fetch = []
109
+ for job in jobs:
110
+ cached = _cache_path(job["text"], job["voice"], job.get("rate"), job.get("pitch"))
111
+ if use_cache and cached.exists():
112
+ results[job["guid"]] = cached.read_bytes()
113
+ if progress:
114
+ progress(job, True)
115
+ else:
116
+ to_fetch.append(job)
117
+
118
+ if to_fetch:
119
+ _inject_truststore()
120
+
121
+ async def _run_all():
122
+ sem = asyncio.Semaphore(CONCURRENCY)
123
+
124
+ async def _one(job):
125
+ async with sem:
126
+ mp3 = await _fetch_mp3(
127
+ job["text"], job["voice"], job.get("rate"), job.get("pitch")
128
+ )
129
+ return job, mp3
130
+
131
+ return await asyncio.gather(*(_one(j) for j in to_fetch))
132
+
133
+ for job, mp3 in asyncio.run(_run_all()):
134
+ wav = _mp3_to_wav(mp3)
135
+ results[job["guid"]] = wav
136
+ if use_cache:
137
+ CACHE_DIR.mkdir(parents=True, exist_ok=True)
138
+ _cache_path(
139
+ job["text"], job["voice"], job.get("rate"), job.get("pitch")
140
+ ).write_bytes(wav)
141
+ if progress:
142
+ progress(job, False)
143
+
144
+ return results
145
+
146
+
147
+ def list_voices(locale_prefix=None):
148
+ """Liste les voix Edge TTS, filtrees par prefixe de locale (ex. 'fr')."""
149
+ _inject_truststore()
150
+ import edge_tts
151
+
152
+ voices = asyncio.run(edge_tts.list_voices())
153
+ if locale_prefix:
154
+ voices = [
155
+ v for v in voices
156
+ if v["Locale"].lower().startswith(locale_prefix.lower())
157
+ ]
158
+ return sorted(voices, key=lambda v: v["ShortName"])
159
+
160
+
161
+ def wav_duration_ms(wav_bytes):
162
+ with wave.open(io.BytesIO(wav_bytes)) as w:
163
+ return int(round(1000.0 * w.getnframes() / w.getframerate()))