v1.4.3: 상대 닉네임을 말로 적던 문제 ("QQQWWWQ")
- 선수 이름은 한글이 들어간 것만 핫워드로 넣는다 - 결과가 선수 이름(조각)뿐이면 워커가 이름을 빼고 다시 변환 (is_name_echo, player_names) - 예전에 이렇게 적힌 발화는 한 번만 정밀 모델로 다시 변환 (파일 없으면 숨김, 고친 발화 제외) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -176,10 +176,17 @@ class SttEngine:
|
||||
segs = run(hotwords)
|
||||
# 핫워드 되풀이 방지: Whisper 가 말을 못 알아들으면 프롬프트(핫워드 목록)를 그대로 읽어 버리는 경우가 있다.
|
||||
# 결과가 핫워드로만 채워져 있으면 핫워드 없이 한 번 더 돌려 그 결과를 쓴다.
|
||||
names = [n for n in (req.get("player_names") or []) if isinstance(n, str) and n.strip()]
|
||||
if hotwords and is_hotword_echo("".join(x.text for x in segs), hotwords):
|
||||
log.info("핫워드 되풀이 감지 → 핫워드 없이 다시 변환")
|
||||
segs = run(None)
|
||||
result["hotword_retry"] = True
|
||||
elif names and is_name_echo("".join(x.text for x in segs), names):
|
||||
# 말을 못 알아들으면 핫워드에 넣은 선수 이름(상대 닉네임 등)을 그대로 적는 경우가 있다 (예: "QQQWWWQ").
|
||||
# 결과가 선수 이름(또는 그 조각)뿐이면 선수 이름을 빼고 다시 변환한다. 정말 이름을 말했으면 다시 해도 그 이름이 나온다.
|
||||
log.info("선수 이름 되풀이 감지 → 선수 이름 없이 다시 변환")
|
||||
segs = run(_without_names(hotwords, names))
|
||||
result["name_retry"] = True
|
||||
|
||||
words: list[dict[str, Any]] = []
|
||||
for seg in segs:
|
||||
@@ -214,6 +221,36 @@ class SttEngine:
|
||||
return done()
|
||||
|
||||
|
||||
def _norm_name(s: str) -> str:
|
||||
"""대소문자 · 띄어쓰기 · 문장부호를 무시한 비교용 글자."""
|
||||
return "".join(ch for ch in s.lower() if ch.isalnum())
|
||||
|
||||
|
||||
def is_name_echo(text: str, names: list[str]) -> bool:
|
||||
"""결과 문장이 선수 이름(또는 이름 조각)만으로 되어 있는지.
|
||||
|
||||
문장 전체(띄어쓰기 무시) 또는 모든 단어가 2글자 이상이면서 어떤 선수 이름 안에 그대로 들어 있어야 한다.
|
||||
예: 이름 "QQQWWWQQQ" → "QQQWWWQ", "QQQWWWQ QQQWWWQ" 는 되풀이, "QQQ 잡았다" 는 아님.
|
||||
"""
|
||||
keys = [k for k in (_norm_name(n) for n in names) if len(k) >= 2]
|
||||
toks = [_norm_name(t) for t in text.split()]
|
||||
toks = [t for t in toks if t]
|
||||
if not keys or not toks:
|
||||
return False
|
||||
whole = "".join(toks)
|
||||
if len(whole) >= 2 and any(whole in k for k in keys):
|
||||
return True
|
||||
return all(len(t) >= 2 and any(t in k for k in keys) for t in toks)
|
||||
|
||||
|
||||
def _without_names(hotwords: str | None, names: list[str]) -> str | None:
|
||||
if not hotwords:
|
||||
return None
|
||||
drop = {w for n in names for w in n.split()}
|
||||
rest = " ".join(h for h in hotwords.split() if h not in drop)
|
||||
return rest or None
|
||||
|
||||
|
||||
def is_hotword_echo(text: str, hotwords: str) -> bool:
|
||||
"""결과 문장이 핫워드 목록을 되풀이한 것인지.
|
||||
|
||||
|
||||
@@ -15,3 +15,33 @@ 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)
|
||||
|
||||
|
||||
# 선수 이름 되풀이 (v1.4.3): 상대 닉네임 "QQQWWWQQQ" 를 핫워드로 넣었더니 말소리를 "QQQWWWQ" 로 적었다
|
||||
from gvr_worker.stt import _without_names, is_name_echo # noqa: E402
|
||||
|
||||
NAMES = ["QQQWWWQQQ", "노곤노곤탐방가", "하늘 별"]
|
||||
|
||||
|
||||
def test_name_echo_detected_for_name_or_fragment():
|
||||
assert is_name_echo("QQQWWWQ", NAMES)
|
||||
assert is_name_echo(" QQQWWWQ.", NAMES)
|
||||
assert is_name_echo("qqqwwwqqq", NAMES)
|
||||
assert is_name_echo("QQQWWWQ QQQWWWQ", NAMES)
|
||||
assert is_name_echo("노곤노곤탐방가", NAMES)
|
||||
assert is_name_echo("하늘 별", NAMES)
|
||||
|
||||
|
||||
def test_name_echo_not_for_real_speech():
|
||||
assert not is_name_echo("QQQ 잡았다", NAMES)
|
||||
assert not is_name_echo("노곤노곤탐방가 죽였어", NAMES)
|
||||
assert not is_name_echo("아이고, 점프티... 아, 갔다.", NAMES)
|
||||
assert not is_name_echo("Q", NAMES)
|
||||
assert not is_name_echo("", NAMES)
|
||||
assert not is_name_echo("QQQWWWQ", [])
|
||||
|
||||
|
||||
def test_without_names_keeps_other_hotwords():
|
||||
assert _without_names("제트 레이즈 QQQWWWQQQ 하늘 별 로테", NAMES) == "제트 레이즈 로테"
|
||||
assert _without_names("QQQWWWQQQ", NAMES) is None
|
||||
assert _without_names(None, NAMES) is None
|
||||
|
||||
Reference in New Issue
Block a user