fix(voice_worker): even out speaker loudness and stop transcribing noise into words

- Loudness equalisation replaces peak normalisation: rumble below 60 Hz removed, level measured on
  the VAD-voiced windows only, brought to -20 dBFS (gain -20..+40 dB), soft limiter below 0.98.
- Only clearly voiced windows (VAD >= 0.5) count towards the 250 ms needed before an utterance
  reaches the model, so noise the VAD half-believes never calls Whisper.
- Hallucination gate: mean token log-probability >= -0.7 (the old len/(len+1) correction let short
  hallucinations through), compression ratio <= 2.4; no_speech_prob dropped (always 0.0 on turbo).
- With hotwords, the plain decode of the same encoder pass decides; the hint may fix a wake word's
  spelling but cannot add or drop one (it wrote the wake word on laughter and after real sentences).
- Opt-in real-model evals: voice-like babble with the hint, speech over babble, quiet and clipped
  speakers, and a JARVIS_NOISE_DIR folder of real noise recordings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-11 10:27:38 +09:00
parent a7685e9078
commit 590cd07268
11 changed files with 460 additions and 54 deletions

View File

@@ -1,7 +1,8 @@
"""Voice worker end to end over a real local WebSocket, with fake STT/VAD/TTS engines.
The fake VAD reads speech probability off the amplitude and the fake transcriber names a clip by its
peak level, so each speaker's text tells which speaker's audio reached the model.
"level": each speaker sends a tone whose amplitude is the level (what the fake VAD reads) and whose
pitch is level x 1000 Hz (what the fake transcriber reads, since the worker evens out loudness).
"""
from __future__ import annotations
@@ -33,7 +34,7 @@ class LevelTranscriber:
def transcribe(self, clips, opts):
self.calls.append((opts, len(clips)))
return [f"level {np.median(np.abs(c)):.1f}" for c in clips]
return [f"level {np.argmax(np.abs(np.fft.rfft(c))) * 16000 / len(c) / 1000:.1f}" for c in clips]
class FakeTts:
@@ -54,7 +55,9 @@ class FakeTts:
def pcm(level: float, ms: int, rate=16000, channels=1) -> bytes:
n = rate * ms // 1000
return (np.full(n * channels, level) * 32767).astype("<i2").tobytes()
# 20 ms frames hold whole cycles at these pitches, so frames join without a click.
x = level * np.sin(2 * np.pi * level * 1000 * np.arange(n) / rate)
return (np.repeat(x, channels) * 32767).astype("<i2").tobytes()
async def with_worker(body, transcriber=None, tts=None, **kw):