mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-16 03:39:15 +02:00
feat(reels): voix Gemini complète, sous-titres mot à mot et rendu de qualité
Service ffmpeg-api réécrit (ffmpeg-service/app/) : - Appels FFmpeg asynchrones : le service ne se fige plus pendant un rendu - Vidéo récupérée par téléchargement (GET /files/…) au lieu de base64 en JSON - Vraies erreurs HTTP ; échec explicite si la voix demandée est impossible - 30 voix Gemini + ton de lecture (dynamique, chaleureux, promo, calme), clé en en-tête, modèle configurable avec repli - Edge TTS 7 (minutage des mots restauré), secours en voix françaises - Voix traitée : filtre, compression, niveau constant ; musique bouclée et baissée automatiquement sous la voix ; mix final à -14 LUFS - Sous-titres calés mot à mot (Whisper pour Gemini et la voix d'origine, à la place de ffsubsync), style Montserrat, placés hors des boutons Reels - Vidéo : plus de retouche luminosité forcée, scaling lanczos, HDR iPhone converti, BT.709, AAC 48 kHz 192k ; la vidéo s'allonge si la voix dépasse - Grand logo de fin affiché après la voix ; FFmpeg 7.0.2 épinglé, polices et modèle Whisper intégrés à l'image ; tests pytest et ruff Application : - Sélecteur de voix partagé (4 pages) : moteur, 30 voix, ton, écoute - Reel images : minutage réel des mots, interrupteur voix respecté - sync-info ne génère plus de voix à chaque frappe (estimation locale) - Stabilisation désactivée par défaut, route /reels/preview inutilisée retirée - Log « [ReelQueue] Worker démarré » pour vérifier la version déployée Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Ze4bs7tpF1KGWUk6ZZSZ4
This commit is contained in:
47 files changed
+2206
-2285
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,3 @@
|
||||
import os
|
||||
|
||||
os.environ.setdefault("API_KEY", "test-key")
|
||||
@@ -0,0 +1,31 @@
|
||||
from app.align import Word, align_words, display_tokens, normalize
|
||||
|
||||
|
||||
def test_normalize_strips_accents_and_punctuation():
|
||||
assert normalize("Été,") == "ete"
|
||||
assert normalize("«") == ""
|
||||
|
||||
|
||||
def test_display_tokens_attach_isolated_punctuation():
|
||||
assert display_tokens("Bonjour ! Venez vite .") == ["Bonjour!", "Venez", "vite."]
|
||||
|
||||
|
||||
def test_align_uses_engine_timings_and_keeps_display_text():
|
||||
spoken = [Word("Bonjour", 0.05, 0.6), Word("découvrez", 0.99, 1.35), Word("nos", 1.35, 1.44)]
|
||||
words = align_words("Bonjour, découvrez nos", spoken)
|
||||
assert [w.text for w in words] == ["Bonjour,", "découvrez", "nos"]
|
||||
assert words[1].start == 0.99
|
||||
|
||||
|
||||
def test_unmatched_words_are_interpolated_between_neighbours():
|
||||
spoken = [Word("les", 0.0, 0.2), Word("prix", 1.0, 1.3)]
|
||||
words = align_words("les super promos prix", spoken)
|
||||
assert [w.text for w in words] == ["les", "super", "promos", "prix"]
|
||||
assert 0.2 <= words[1].start < words[2].start < 1.0
|
||||
assert all(b.start > a.start for a, b in zip(words, words[1:]))
|
||||
|
||||
|
||||
def test_without_spoken_words_text_is_spread_over_duration():
|
||||
words = align_words("un deux trois", [], total_duration=3.0)
|
||||
assert words[0].start == 0.0
|
||||
assert abs(words[-1].end - 3.0) < 1e-6
|
||||
@@ -0,0 +1,77 @@
|
||||
from pathlib import Path
|
||||
|
||||
from app.render import RenderPlan, build_command
|
||||
|
||||
|
||||
def _graph(cmd):
|
||||
return cmd[cmd.index("-filter_complex") + 1]
|
||||
|
||||
|
||||
def test_voice_longer_than_video_extends_with_frozen_frame():
|
||||
plan = RenderPlan(
|
||||
video=Path("in.mp4"),
|
||||
video_duration=5.0,
|
||||
output=Path("out.mp4"),
|
||||
voice=Path("v.wav"),
|
||||
voice_duration=10.0,
|
||||
)
|
||||
assert plan.total_duration == 12.8
|
||||
cmd = build_command(plan)
|
||||
assert "tpad=stop_mode=clone:stop_duration=7.800" in _graph(cmd)
|
||||
assert cmd[cmd.index("-t") + 1] == "12.800"
|
||||
|
||||
|
||||
def test_music_is_looped_and_ducked_under_voice():
|
||||
plan = RenderPlan(
|
||||
video=Path("in.mp4"),
|
||||
video_duration=20.0,
|
||||
output=Path("out.mp4"),
|
||||
music=Path("m.mp3"),
|
||||
voice=Path("v.wav"),
|
||||
voice_duration=5.0,
|
||||
)
|
||||
cmd = build_command(plan)
|
||||
assert cmd[cmd.index("m.mp3") - 3 : cmd.index("m.mp3")] == ["-stream_loop", "-1", "-i"]
|
||||
graph = _graph(cmd)
|
||||
assert "sidechaincompress" in graph
|
||||
assert "amix=inputs=2:duration=longest" in graph
|
||||
assert "loudnorm=I=-14" in graph
|
||||
|
||||
|
||||
def test_no_brightness_hack_and_hdr_tonemapped():
|
||||
plan = RenderPlan(video=Path("in.mp4"), video_duration=5.0, output=Path("out.mp4"), is_hdr=True)
|
||||
graph = _graph(build_command(plan))
|
||||
assert "eq=" not in graph
|
||||
assert "tonemap=tonemap=hable" in graph
|
||||
assert "flags=lanczos" in graph
|
||||
|
||||
|
||||
def test_original_audio_kept_when_nothing_added():
|
||||
plan = RenderPlan(
|
||||
video=Path("in.mp4"), video_duration=5.0, output=Path("out.mp4"), keep_original_audio=True
|
||||
)
|
||||
cmd = build_command(plan)
|
||||
assert cmd[cmd.index("-map", cmd.index("[vout]")) + 1] == "0:a:0"
|
||||
|
||||
|
||||
def test_encoding_targets_social_networks():
|
||||
cmd = build_command(RenderPlan(video=Path("in.mp4"), video_duration=5.0, output=Path("out.mp4")))
|
||||
joined = " ".join(cmd)
|
||||
assert "-crf 19" in joined and "-b:v" not in joined
|
||||
assert "-ar 48000" in joined and "-b:a 192k" in joined
|
||||
assert "-colorspace bt709" in joined
|
||||
|
||||
|
||||
def test_big_logo_waits_for_the_end_of_the_voice():
|
||||
plan = RenderPlan(
|
||||
video=Path("in.mp4"),
|
||||
video_duration=6.0,
|
||||
output=Path("out.mp4"),
|
||||
voice=Path("v.wav"),
|
||||
voice_duration=4.8,
|
||||
watermark=Path("logo.png"),
|
||||
outro=Path("o.ass"),
|
||||
)
|
||||
assert plan.logo_start == 6.8
|
||||
assert plan.total_duration == 9.3
|
||||
assert "gte(t,6.800)" in _graph(build_command(plan))
|
||||
@@ -0,0 +1,23 @@
|
||||
from app.align import Word
|
||||
from app.subtitles import ass_time, group_lines, write_captions
|
||||
|
||||
|
||||
def test_ass_time_format():
|
||||
assert ass_time(0) == "0:00:00.00"
|
||||
assert ass_time(61.234) == "0:01:01.23"
|
||||
|
||||
|
||||
def test_lines_break_on_punctuation_and_length():
|
||||
words = [Word(t, i, i + 0.5) for i, t in enumerate("Bonjour, venez découvrir nos nouveautés".split())]
|
||||
lines = group_lines(words)
|
||||
assert [w.text for w in lines[0]] == ["Bonjour,"]
|
||||
assert all(len(line) <= 3 for line in lines)
|
||||
|
||||
|
||||
def test_captions_are_offset_and_escape_braces(tmp_path):
|
||||
path = tmp_path / "c.ass"
|
||||
write_captions([Word("{prix}", 0.0, 0.5), Word("fous", 0.5, 1.0)], path, offset=2.0, font_size=80)
|
||||
content = path.read_text()
|
||||
assert "Dialogue: 0,0:00:02.00," in content
|
||||
assert "{prix}" not in content.split("[Events]")[1].replace("{\\", "")
|
||||
assert "(prix)" in content
|
||||
@@ -0,0 +1,23 @@
|
||||
from app.tts.gemini import build_prompt
|
||||
from app.voices import GEMINI_VOICES, edge_fallbacks, resolve_edge_voice, resolve_gemini_voice
|
||||
|
||||
|
||||
def test_thirty_gemini_voices():
|
||||
assert len(GEMINI_VOICES) == 30
|
||||
|
||||
|
||||
def test_legacy_gemini_identifiers_still_resolve():
|
||||
assert resolve_gemini_voice("fr-FR-Standard-B").id == "Charon"
|
||||
assert resolve_gemini_voice("fr-FR-Standard-A").id == "Kore"
|
||||
assert resolve_gemini_voice("puck").id == "Puck"
|
||||
|
||||
|
||||
def test_edge_fallbacks_are_french_and_same_gender():
|
||||
voice = resolve_edge_voice("Fenrir") # voix Gemini masculine
|
||||
assert voice.gender == "male"
|
||||
assert all(v.id.startswith("fr-FR") and v.gender == "male" for v in edge_fallbacks(voice))
|
||||
|
||||
|
||||
def test_style_prompt_precedes_text():
|
||||
assert build_prompt("Salut", "neutral") == "Salut"
|
||||
assert build_prompt("Salut", "dynamic").endswith(":\nSalut")
|
||||
Reference in new issue
Block a user