v1.3.6: 목소리 깨짐(RTP 기준 쉼 채우기) · 알 수 없음 · 잡음 숨기기/삭제 · 사이트 로그 · 지금 게임 · TTS 속도 · 시작 창
- 녹음기: 패킷 도착 간격 대신 RTP 타임스탬프로 자리를 정한다. 게임 중 몰려 온 패킷 사이에 무음이 끼어 목소리가 깨졌다. 예전 녹음은 한 번 고친 뒤 다시 변환 - users.updated 를 빈 목록으로 보내 사이트에서 말한 사람이 '알 수 없음'이 되던 것 - 잡음은 숨기고 ogg 삭제, 로그에 잡음으로 남김. 짧은 목소리도 Whisper 로, 반복 고리는 줄여서 보여 줌 - 사이트: 재생 음량, 발화 우클릭(자세한 정보 · ogg 다운로드), 사이트 로그(/logs, 게임 PC 꺼져도), 지금 게임 상태 - 앱: 지금 게임 상태, 녹음 안내 말 속도 0.1~2.0, 포터블 · 앱 시작 창 - 발로란트 데스매치 가짜 라운드 · 에이스, 빈 선수 이름 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -80,6 +80,15 @@ def build_server(writer: Writer) -> Server:
|
||||
raise WorkerError("bad_request", "since_ms 는 숫자(Unix ms) 또는 null 이어야 합니다")
|
||||
return read(require(req, "logs_dir"), since)
|
||||
|
||||
@server.route("tempo", "thread")
|
||||
def tempo(req: dict[str, Any], ctx: Context) -> dict[str, Any]:
|
||||
from .tempo import change_tempo
|
||||
|
||||
t = req.get("tempo")
|
||||
if not isinstance(t, (int, float)):
|
||||
raise WorkerError("bad_request", "tempo 는 숫자여야 합니다")
|
||||
return change_tempo(require(req, "src"), require(req, "dst"), float(t))
|
||||
|
||||
@server.route("train", "thread")
|
||||
def train(req: dict[str, Any], ctx: Context) -> dict[str, Any]:
|
||||
return run_finetune(req, ctx)
|
||||
|
||||
@@ -95,7 +95,6 @@ class SegInfo:
|
||||
|
||||
@dataclass
|
||||
class Thresholds:
|
||||
vad_ratio: float
|
||||
vad_min_speech_s: float
|
||||
no_speech_prob: float
|
||||
logprob: float
|
||||
@@ -109,7 +108,6 @@ class Thresholds:
|
||||
def thresholds(sensitivity: float) -> Thresholds:
|
||||
s = min(max(float(sensitivity), 0.0), 1.0)
|
||||
return Thresholds(
|
||||
vad_ratio=0.03 + 0.17 * s, # 0.5 → 0.115
|
||||
vad_min_speech_s=0.08 + 0.14 * s, # 0.5 → 0.15s
|
||||
no_speech_prob=0.85 - 0.3 * s, # 0.5 → 0.70
|
||||
logprob=-1.3 + 0.6 * s, # 0.5 → -1.0
|
||||
@@ -122,8 +120,13 @@ def thresholds(sensitivity: float) -> Thresholds:
|
||||
|
||||
|
||||
def judge_vad(speech_ratio: float, speech_s: float, sensitivity: float) -> bool:
|
||||
"""목소리가 조금이라도(0.5 기준 0.15초) 있으면 Whisper 로 넘긴다.
|
||||
|
||||
v1.3.5 까지는 말소리 비율(길이 대비 11.5%)도 봐서, 긴 잡음 속 짧은 한마디도 잡음으로 버렸다.
|
||||
"""
|
||||
del speech_ratio # 비율은 보지 않는다 (호환용 인자)
|
||||
t = thresholds(sensitivity)
|
||||
return speech_ratio < t.vad_ratio or speech_s < t.vad_min_speech_s
|
||||
return speech_s < t.vad_min_speech_s
|
||||
|
||||
|
||||
def judge_no_speech(segs: list[SegInfo], text: str, sensitivity: float) -> bool:
|
||||
@@ -180,6 +183,20 @@ def judge_repetition(text: str, segs: list[SegInfo], sensitivity: float) -> bool
|
||||
return any(s.compression_ratio > t.compression + 0.4 for s in segs) and len(norm) >= 12
|
||||
|
||||
|
||||
_REPEAT_RE = re.compile(r"(.{1,10}?)(?:\s*\1){2,}")
|
||||
|
||||
|
||||
def collapse_repetition(text: str) -> str:
|
||||
"""Whisper 반복 고리("페이스페이스페이스…", "아 아 아 아")를 한 번으로 줄인다."""
|
||||
out = text.strip()
|
||||
for _ in range(3):
|
||||
nxt = _REPEAT_RE.sub(lambda m: m.group(1), out)
|
||||
if nxt == out:
|
||||
break
|
||||
out = nxt
|
||||
return re.sub(r"\s{2,}", " ", out).strip()
|
||||
|
||||
|
||||
def judge_text(
|
||||
text: str, segs: list[SegInfo], confidence: float, duration_s: float, sensitivity: float
|
||||
) -> str | None:
|
||||
|
||||
@@ -196,6 +196,12 @@ class SttEngine:
|
||||
result.update(raw_text=raw_text or None, confidence=round(confidence, 3))
|
||||
|
||||
reason = noise.judge_text(raw_text, infos, confidence, prep.duration_s, sensitivity)
|
||||
if reason == "repetition":
|
||||
# 반복 고리는 한 번으로 줄여서, 알아들은 말이 남으면 그 말을 쓴다 (단어 하나라도 있으면 보여 준다)
|
||||
collapsed = noise.collapse_repetition(raw_text)
|
||||
if noise.normalize(collapsed) and noise.judge_hallucination(collapsed, confidence, prep.duration_s, sensitivity) is False:
|
||||
raw_text, words, reason = collapsed, [], None
|
||||
result.update(raw_text=raw_text, collapsed_repetition=True)
|
||||
if reason:
|
||||
return done(reason)
|
||||
|
||||
|
||||
69
worker/gvr_worker/tempo.py
Normal file
69
worker/gvr_worker/tempo.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""녹음 안내(TTS) 속도 바꾸기.
|
||||
|
||||
Edge TTS 는 말 속도를 0.5배까지만 늦춘다. 그보다 느리게(0.1~0.5배) 하려면 0.5배로 합성한 음성을
|
||||
여기서 atempo 필터로 한 번 더 늘린다. 결과는 디스코드에 바로 보낼 수 있는 Ogg Opus (48kHz).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from fractions import Fraction
|
||||
|
||||
from .protocol import WorkerError
|
||||
|
||||
|
||||
def atempo_chain(tempo: float) -> list[float]:
|
||||
"""atempo 한 단계는 0.5~2.0 만 받는다. 0.5 보다 느리면 여러 단계로 나눈다."""
|
||||
if not 0.05 <= tempo <= 2.0:
|
||||
raise WorkerError("bad_request", "tempo 는 0.05~2.0 이어야 합니다")
|
||||
out: list[float] = []
|
||||
t = tempo
|
||||
while t < 0.5:
|
||||
out.append(0.5)
|
||||
t /= 0.5
|
||||
out.append(round(t, 6))
|
||||
return out
|
||||
|
||||
|
||||
def change_tempo(src: str, dst: str, tempo: float) -> dict[str, float]:
|
||||
import av
|
||||
import av.filter
|
||||
|
||||
chain = atempo_chain(tempo)
|
||||
with av.open(src) as inp, av.open(dst, "w", format="ogg") as out:
|
||||
ist = inp.streams.audio[0]
|
||||
ost = out.add_stream("libopus", rate=48000)
|
||||
ost.layout = "mono"
|
||||
graph = av.filter.Graph()
|
||||
node = graph.add_abuffer(template=ist)
|
||||
for t in chain:
|
||||
nxt = graph.add("atempo", str(t))
|
||||
node.link_to(nxt)
|
||||
node = nxt
|
||||
fmt = graph.add("aformat", "sample_fmts=s16:sample_rates=48000:channel_layouts=mono")
|
||||
node.link_to(fmt)
|
||||
sink = graph.add("abuffersink")
|
||||
fmt.link_to(sink)
|
||||
graph.configure()
|
||||
dur = 0.0
|
||||
|
||||
def drain() -> None:
|
||||
nonlocal dur
|
||||
while True:
|
||||
try:
|
||||
f = sink.pull()
|
||||
except (av.error.BlockingIOError, av.error.EOFError):
|
||||
return
|
||||
f.pts = None
|
||||
f.time_base = Fraction(1, 48000)
|
||||
dur += f.samples / 48000
|
||||
for p in ost.encode(f):
|
||||
out.mux(p)
|
||||
|
||||
for frame in inp.decode(ist):
|
||||
graph.push(frame)
|
||||
drain()
|
||||
graph.push(None)
|
||||
drain()
|
||||
for p in ost.encode(None):
|
||||
out.mux(p)
|
||||
return {"duration_s": round(dur, 3), "stages": len(chain)}
|
||||
@@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from gvr_worker.noise import HALLUCINATION_PHRASES, SegInfo, judge_text, judge_vad, thresholds
|
||||
from gvr_worker.noise import HALLUCINATION_PHRASES, SegInfo, collapse_repetition, judge_text, judge_vad, thresholds
|
||||
|
||||
GOOD = [SegInfo(0.05, -0.3, 1.2)]
|
||||
|
||||
@@ -36,5 +36,14 @@ def test_vad_and_sensitivity() -> None:
|
||||
assert judge_vad(0.0, 0.0, 0.5)
|
||||
assert not judge_vad(0.7, 2.0, 0.5)
|
||||
lo, hi = thresholds(0.0), thresholds(1.0)
|
||||
assert lo.vad_ratio < hi.vad_ratio and lo.no_speech_prob > hi.no_speech_prob
|
||||
assert judge_vad(0.15, 0.4, 1.0) and not judge_vad(0.15, 0.4, 0.0)
|
||||
assert lo.vad_min_speech_s < hi.vad_min_speech_s and lo.no_speech_prob > hi.no_speech_prob
|
||||
assert judge_vad(0.02, 0.2, 1.0) and not judge_vad(0.02, 0.2, 0.0)
|
||||
# 긴 잡음 속 짧은 한마디(0.3초)도 Whisper 로 넘긴다 (예전: 비율 5% 라 잡음)
|
||||
assert not judge_vad(0.05, 0.3, 0.5)
|
||||
|
||||
|
||||
def test_collapse_repetition() -> None:
|
||||
assert collapse_repetition("엘리베이 아이스페이스페이스페이스페이스페이스") == "엘리베이 아이스페이스"
|
||||
assert collapse_repetition("아 아 아 아 아 아 아 아") == "아"
|
||||
assert collapse_repetition("가자 가자") == "가자 가자"
|
||||
assert collapse_repetition("레이즈 궁 빠졌어") == "레이즈 궁 빠졌어"
|
||||
|
||||
32
worker/tests/test_tempo.py
Normal file
32
worker/tests/test_tempo.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from gvr_worker.protocol import WorkerError
|
||||
from gvr_worker.tempo import atempo_chain, change_tempo
|
||||
|
||||
SRC = Path(__file__).resolve().parents[2] / "app" / "resources" / "tts" / "announce-default.webm"
|
||||
|
||||
|
||||
def test_chain() -> None:
|
||||
assert atempo_chain(1.0) == [1.0]
|
||||
assert atempo_chain(0.2) == [0.5, 0.5, 0.8]
|
||||
assert atempo_chain(2.0) == [2.0]
|
||||
with pytest.raises(WorkerError):
|
||||
atempo_chain(0.01)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not SRC.exists(), reason="기본 안내 음성 없음")
|
||||
def test_change_tempo(tmp_path: Path) -> None:
|
||||
import av
|
||||
|
||||
with av.open(str(SRC)) as f:
|
||||
base = sum(fr.samples / fr.sample_rate for fr in f.decode(audio=0))
|
||||
out = tmp_path / "slow.ogg"
|
||||
r = change_tempo(str(SRC), str(out), 0.4)
|
||||
assert abs(r["duration_s"] - base / 0.4) < 0.5
|
||||
with av.open(str(out)) as f:
|
||||
s = f.streams.audio[0]
|
||||
assert s.codec_context.name == "opus" and s.rate == 48000
|
||||
Reference in New Issue
Block a user