Clipador: quem fala cada palavra (streamer × outra pessoa) e legenda em duas linhas
A fala de colegas no Discord e de outros jogadores saía na legenda como se fosse do streamer. Agora cada palavra tem falante: - voz: cada trecho de fala vira uma impressão de voz (WeSpeaker ResNet34-LM, ONNX, pesos CC-BY-4.0) na análise do bloco (~0,2 s de CPU por bloco); as vozes da sessão são agrupadas sob demanda (0,05 s) e a do streamer é a que mexe a boca na webcam (YuNet, nova série `mouth` no rastreio) ou a mais alta no áudio. Sem prova, tudo continua como do streamer. - dados: `scoring.Word.speaker`; `words_json` aceita o 4º elemento; tabela `voice_chunks` (CREATE TABLE IF NOT EXISTS, fora da lista de migrações). - legenda: streamer na posição normal e outra pessoa logo abaixo, em outra cor (`caption.otherColor`/`otherSize`); blocos nunca misturam falantes; os dois juntos = duas linhas; gancho desvia as duas; vertical e horizontal. - tradução com `speaker` por linha; juízes recebem a transcrição marcada. - painel: cor da outra pessoa na configuração, falante na transcrição do editor (com correção manual), prévia em duas linhas e "O que falam" no modal. - doc/clipador/FALANTES.md com abordagem, licenças e qualidade medida na sessão 15. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
54eac7cebf
commit
377536f778
+33
-9
@@ -660,16 +660,40 @@ def _game_context_en(game: str, screen_game: str, profile: dict | None, live_tit
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def _transcript(words: list[Word], lo: float, hi: float, lang: str = "pt") -> str:
|
||||
lines, current, current_t = [], [], None
|
||||
for word in sorted((w for w in words if lo <= w.start <= hi), key=lambda w: w.start):
|
||||
if current_t is None or word.start - current_t > 4 or len(current) >= 14:
|
||||
SPEAKER_NOTE = {
|
||||
"pt": "Quem fala vem marcado: [{s}] = o streamer; [other1], [other2]… = OUTRA pessoa (colega no Discord, outro "
|
||||
"jogador no chat de voz do jogo). Nunca atribua a {s} o que outra pessoa disse.",
|
||||
"en": "Each line is tagged with who speaks: [{s}] = the streamer; [other1], [other2]… = SOMEONE ELSE (teammate on "
|
||||
"Discord, another player on in-game voice chat). Never attribute to {s} what someone else said.",
|
||||
}
|
||||
|
||||
|
||||
def _transcript(words: list[Word], lo: float, hi: float, lang: str = "pt", streamer: str = "") -> str:
|
||||
"""Transcrição com tempo para os prompts. Com fala de outra pessoa no trecho (doc/clipador/FALANTES.md), cada
|
||||
linha diz quem fala ([Tfue] / [other1]) e nunca mistura falantes; sem outra pessoa, sai igual a antes."""
|
||||
inside = sorted((w for w in words if lo <= w.start <= hi), key=lambda w: w.start)
|
||||
tagged = any(w.speaker and w.speaker != "streamer" for w in inside)
|
||||
me = (streamer or "streamer").replace("[", "(").replace("]", ")")
|
||||
lines: list[str] = []
|
||||
current: list[str] = []
|
||||
current_t: float | None = None
|
||||
current_sp = ""
|
||||
|
||||
def flush() -> None:
|
||||
tag = f" [{me if current_sp == 'streamer' else current_sp}]" if tagged else ""
|
||||
lines.append(f"[{current_t:.0f}s]{tag} {' '.join(current)}")
|
||||
|
||||
for word in inside:
|
||||
sp = word.speaker or "streamer"
|
||||
if current_t is None or word.start - current_t > 4 or len(current) >= 14 or (tagged and sp != current_sp):
|
||||
if current:
|
||||
lines.append(f"[{current_t:.0f}s] {' '.join(current)}")
|
||||
current, current_t = [], word.start
|
||||
flush()
|
||||
current, current_t, current_sp = [], word.start, sp
|
||||
current.append(word.word)
|
||||
if current:
|
||||
lines.append(f"[{current_t:.0f}s] {' '.join(current)}")
|
||||
flush()
|
||||
if lines and tagged:
|
||||
lines.insert(0, SPEAKER_NOTE["en" if lang == "en" else "pt"].format(s=me))
|
||||
return "\n".join(lines) or LABELS[lang]["no_speech"]
|
||||
|
||||
|
||||
@@ -717,7 +741,7 @@ def build_prompt(streamer: str, platform: str, start_s: float, end_s: float, pea
|
||||
f"{L['signals']}: {json.dumps(heuristic, ensure_ascii=False)}\n"
|
||||
+ (f"{L['face']}: {face}\n" if face else "")
|
||||
+ f"{_frames_block(frames or [], lang)}\n\n"
|
||||
f"{L['transcript']}:\n{_transcript(words, lo, hi, lang)}\n\n"
|
||||
f"{L['transcript']}:\n{_transcript(words, lo, hi, lang, streamer)}\n\n"
|
||||
f"{_chat_block(chat, lo, hi, peak_s, lang=lang)}"
|
||||
)
|
||||
|
||||
@@ -732,7 +756,7 @@ def build_scan_prompt(streamer: str, platform: str, lo: float, hi: float, back_l
|
||||
f"{L['new_window']}: {lo:.0f}s {to} {hi:.0f}s ({L['back_to'].format(s=f'{back_lo:.0f}')}).\n"
|
||||
f"{L['duration']}: {min_s:.0f} {to} {max_s:.0f} s. {L['done']}: {done}\n"
|
||||
f"{_frames_block(frames, lang)}\n\n"
|
||||
f"{L['transcript']}:\n{_transcript(words, back_lo, hi, lang)}\n\n"
|
||||
f"{L['transcript']}:\n{_transcript(words, back_lo, hi, lang, streamer)}\n\n"
|
||||
f"{_chat_block(chat, back_lo, hi, None, bucket_s=10, lang=lang)}"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user