M3: 발로란트 연동 - 전체 스택 시연·테스트, 핫워드 되풀이 방지

- scripts/demo-stack.mts: 코어+STT+사이트 서버+중계+헤드리스 브라우저 전체 스택 (22라운드 어센트, TTS 대화, 잠금/해제)
- test/fixtures/demo-matches.ts: match-details·LCU 구조 시연 데이터
- 워커: 결과가 핫워드 목록 되풀이면 핫워드 없이 다시 변환, 핫워드 40개
- ACS: API 는 총 전투 점수

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-15 01:41:02 +09:00
parent 9abda88046
commit 5222b3ee72
17 changed files with 549 additions and 21 deletions

View File

@@ -153,22 +153,33 @@ class SttEngine:
return done("vad")
hotwords = req.get("hotwords") or None
try:
segments, _info = lm.model.transcribe(
prep.audio,
language="ko",
task="transcribe",
beam_size=BEAM.get(slot, 5),
word_timestamps=True,
vad_filter=True,
vad_parameters={"min_silence_duration_ms": VAD_MIN_SILENCE_MS},
hotwords=hotwords if isinstance(hotwords, str) else None,
initial_prompt=req.get("initial_prompt") or None,
condition_on_previous_text=False,
)
segs = list(segments)
except Exception as e: # noqa: BLE001
raise WorkerError("transcribe_failed", f"음성 변환 실패: {e}") from e
hotwords = hotwords if isinstance(hotwords, str) and hotwords.strip() else None
def run(hw: str | None) -> list[Any]:
try:
segments, _info = lm.model.transcribe(
prep.audio,
language="ko",
task="transcribe",
beam_size=BEAM.get(slot, 5),
word_timestamps=True,
vad_filter=True,
vad_parameters={"min_silence_duration_ms": VAD_MIN_SILENCE_MS},
hotwords=hw,
initial_prompt=req.get("initial_prompt") or None,
condition_on_previous_text=False,
)
return list(segments)
except Exception as e: # noqa: BLE001
raise WorkerError("transcribe_failed", f"음성 변환 실패: {e}") from e
segs = run(hotwords)
# 핫워드 되풀이 방지: Whisper 가 말을 못 알아들으면 프롬프트(핫워드 목록)를 그대로 읽어 버리는 경우가 있다.
# 결과가 핫워드로만 채워져 있으면 핫워드 없이 한 번 더 돌려 그 결과를 쓴다.
if hotwords and is_hotword_echo("".join(x.text for x in segs), hotwords):
log.info("핫워드 되풀이 감지 → 핫워드 없이 다시 변환")
segs = run(None)
result["hotword_retry"] = True
words: list[dict[str, Any]] = []
for seg in segs:
@@ -195,3 +206,32 @@ class SttEngine:
text, out_words = corrector.correct_text(raw_text), []
result.update(text=text, words=out_words)
return done()
def is_hotword_echo(text: str, hotwords: str) -> bool:
"""결과 문장이 핫워드 목록을 되풀이한 것인지.
- 단어 3개 이상이고 그중 60% 이상이 핫워드와 정확히 같거나
- 핫워드 목록에 나온 순서대로 핫워드 3개 이상이 연달아 나오면 되풀이로 본다.
"""
toks = [t.strip(".,!?~") for t in text.split()]
toks = [t for t in toks if t]
if len(toks) < 3:
return False
hw = [h for h in hotwords.split() if h]
hwset = set(hw)
hits = sum(1 for t in toks if t in hwset)
if hits / len(toks) >= 0.6:
return True
pos = {h: i for i, h in enumerate(hw)}
run_len, prev = 0, -1
for t in toks:
i = pos.get(t)
if i is not None and i > prev:
run_len += 1
prev = i
if run_len >= 3:
return True
else:
run_len, prev = (1, i) if i is not None else (0, -1)
return False

View File

@@ -0,0 +1,17 @@
from gvr_worker.stt import is_hotword_echo
HW = "바론 드래곤 용 장로 전령 유충 억제기 포탑 탑라이너 바텀 슈퍼미니언 정글러 미드라이너 갱킹 백도어 텔"
def test_echo_detected_when_output_is_hotword_list():
assert is_hotword_echo("탑라이너 바텀 슈퍼미니언 정글러 미드라이너 갱킹 백도어 텔", HW)
def test_echo_detected_ordered_run():
assert is_hotword_echo("음 바론 드래곤 용 그래서", HW)
def test_normal_sentence_with_some_hotwords_is_kept():
assert not is_hotword_echo("드래곤 가자 바텀으로 모여", HW)
assert not is_hotword_echo("바론 치자 시야 잡아줘", HW)
assert not is_hotword_echo("포탑 밀자", HW)