feat(orchestrator): radio set with CPU-gated speech, noise burst, modes and log (requirement 004)

The hub gates uncached /api/tts renders on the latest W4 host CPU sample (503 busy or unknown, cached lines always served, signed speech.threshold 30 to 90 in steps of 10, speech.gate in /api/state). The page plays a WebAudio squelch-tail burst when no speech plays, offers Auto, Quiet and Silence per browser, and always sounds the MAYDAY, PAN-PAN and SECURITE procedure word. The radio panel becomes a minimalist VHF faceplate with display line, mode buttons, knobs, PTT send and the internet station; the settings dialog loses its radio section. The log gets Sent, Received and All tabs with class, sender, recipient and agent chips plus text search. Decisions 3 and 10 of 004 now state that the procedure word still sounds in Silence.

Security: MEDUSA-MEX-SCAN-1167 at orchestrator/kvb_orchestrator/hub.py:126 accepted as a false positive after the round 5 skeptic review and the operator pick of 2026-11-13 (regex hit on rce inside RESOURCES; CpuGate reads host CPU samples, no model).

Break risk 6 % is above the 5 % bar; committed and merged on the operator pick of 2026-11-13 for this bundle.

🎯 Fix: 92 %
💥 Break: 6 %
💸 Cost: 100 %
⏱️ Time: 100 %
🛡️ Security: 100 %
🏆 Score: 86
🚦 Gate: ⛔ break 6 % > 5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-13 10:48:13 +00:00
1 parent 69693ac2bc
commit acf39255fc
37 files changed
+2480 -356

No files matched your search

+28 -5
View File
@@ -8,13 +8,14 @@ import subprocess
import threading
import time
import wave
from collections.abc import Callable
from dataclasses import dataclass
from pathlib import Path
from .council import HUMAN
from .errors import EngineError, ToolError, Unavailable
from .fields import TEXT_LIMIT, bounded, decode, expect
from .phrasing import SPEECH_LIMIT, SPOKEN_LINE, phrase
from .phrasing import PROCEDURE_LINES, SPEECH_LIMIT, SPOKEN_LINE, phrase
from .records import digest, read_json
from .skill_scripts import SAFE_PATH
@@ -22,6 +23,7 @@ MODEL_NAME = re.compile(r"[A-Za-z0-9][A-Za-z0-9_.-]{0,127}")
SPEAKER_LIMIT = 10000
TTS_TIMEOUT = 120
TTS_KEEP = 200
WORD_CACHE = "word-"
STT_RATE = 16000
STT_SECONDS = 120
STT_LIMIT = 44 + STT_RATE * 2 * STT_SECONDS
@@ -141,6 +143,7 @@ class Speech:
raise ToolError(f"the operator voice {engines.operator_voice!r} is not installed in {engines.voices}")
self.operator = engines.operator_voice if self.voices else ""
self.pool = [voice for voice in self.voices if voice != self.operator]
self.handed = {self.operator} if self.operator else set()
self.speaking = threading.Lock()
self.hearing = threading.Lock()
self.metering = threading.Lock()
@@ -174,7 +177,15 @@ class Speech:
return gap or ("" if os.path.isfile(model) else f"the whisper.cpp model {model} is not a file")
def voice_of(self, key: str) -> str:
return voice_of(key, self.pool, self.operator)
"""Args:
key: the speaker's session id or directory key.
Returns:
The speaker's voice, which /api/tts accepts from then on.
"""
voice = voice_of(key, self.pool, self.operator)
self.handed.add(voice)
return voice
def describe(self) -> dict:
operator = self.voice_of(HUMAN)
@@ -185,7 +196,15 @@ class Speech:
"limit": SPEECH_LIMIT, "rate": STT_RATE, "seconds": STT_SECONDS,
}
def synthesize(self, body: bytes) -> bytes:
def synthesize(self, body: bytes, admit: Callable[[str], None]) -> bytes:
"""Args:
body: {"text", "voice"} as JSON.
admit: called with a line before it renders and not for a cached
one; it raises to hold the render back.
Returns:
The WAV of the line, from the cache when rendered before.
"""
gap = self.output_gap()
if gap:
raise Unavailable(f"speech output is off: {gap}")
@@ -194,13 +213,16 @@ class Speech:
voice = payload["voice"]
if not isinstance(voice, str) or voice not in self.voices:
raise ToolError("voice must be one of the installed voices")
if voice not in self.handed:
raise ToolError("voice must be one the hub hands out to a speaker")
line = " ".join(bounded(payload, "text", SPEECH_LIMIT).split())
if not SPOKEN_LINE.fullmatch(line):
raise ToolError(f"text must be 1 to {SPEECH_LIMIT} printable characters")
key = digest(f"{voice}\n{line}")
target = self.cache / f"{key}.wav"
target = self.cache / f"{WORD_CACHE if line in PROCEDURE_LINES else ''}{key}.wav"
with self.speaking:
if not target.is_file():
admit(line)
self.render(voice, line, target)
self.trim()
os.utime(target)
@@ -235,7 +257,8 @@ class Speech:
partial.unlink(missing_ok=True)
def trim(self) -> None:
kept = sorted(self.cache.glob("*.wav"), key=lambda path: path.stat().st_mtime, reverse=True)
spoken = (path for path in self.cache.glob("*.wav") if not path.name.startswith(WORD_CACHE))
kept = sorted(spoken, key=lambda path: path.stat().st_mtime, reverse=True)
for path in kept[TTS_KEEP:]:
path.unlink(missing_ok=True)