A new radio mode sends each spoken row as ggwave frames of at most 140 bytes: frame 1 carries the full session id, later frames its 8-character prefix, each with n/m. engines.sound_of() gives every speaker one of the four audible ggwave protocols that decode every frame length, plus its own stereo position, by a stable hash. The vendored ggwave 0.4.0 (MIT, LICENSE kept, sha256 pinned in test_hub_artifacts) runs only in the /gibberlink encoder page, sandboxed into an opaque origin with eval and WebAssembly but no connection; the hub page frames it (frame-src 'self') and review pages refuse framing (frame-ancestors 'none'). The radio gear gains a fallback selector (Gibberlink, Morse, Hiss) for rows that speech cannot play. Accepted MEDUSA false positives (security.py accept after kvb-think-criticize, 2026-11-17): engines.py FTSCAN-231 INF-SCAN-2638 INF-SCAN-2057 STG009 B603; handler.py FTSC-SCAN-089 B105 EXA002 EXA006; view.py WEB-FLASK-004 FINE-043 LO002. 🎯 Fix: 91 % 💥 Break: 4 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 87 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
3.5 KiB
JavaScript
88 lines
3.5 KiB
JavaScript
const GIBBER = {gap: 0.3, timeout: 15000, route: "/gibberlink"};
|
|
const gibber = {frame: null, ready: null, pending: new Map(), next: 0};
|
|
|
|
function gibberFrame() {
|
|
if (!gibber.frame) {
|
|
const frame = h("iframe", {class: "gibberlink-encoder", src: GIBBER.route, sandbox: "allow-scripts", title: "Gibberlink encoder", "aria-hidden": "true", tabindex: "-1", hidden: true});
|
|
gibber.ready = new Promise((resolve) => frame.addEventListener("load", resolve, {once: true}));
|
|
window.addEventListener("message", gibberAnswer);
|
|
document.body.append(frame);
|
|
gibber.frame = frame;
|
|
}
|
|
return gibber;
|
|
}
|
|
|
|
function gibberAnswer(event) {
|
|
const waiting = gibber.frame && event.source === gibber.frame.contentWindow && event.data ? gibber.pending.get(event.data.id) : null;
|
|
if (!waiting) {
|
|
return;
|
|
}
|
|
gibber.pending.delete(event.data.id);
|
|
window.clearTimeout(waiting.timer);
|
|
const {rate, samples, error} = event.data;
|
|
if (error) {
|
|
waiting.reject(new Error(String(error)));
|
|
} else if (Number.isFinite(rate) && rate > 0 && Array.isArray(samples) && samples.every((part) => part instanceof Float32Array)) {
|
|
waiting.resolve({rate, samples});
|
|
} else {
|
|
waiting.reject(new Error("the Gibberlink encoder answered no samples"));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {object} step a Gibberlink step with frames and protocol.
|
|
* @returns {Promise<object>} rate and samples: the samples of each frame from the sandboxed encoder frame, at its rate.
|
|
*/
|
|
function gibberEncode(step) {
|
|
const {frame, ready, pending} = gibberFrame();
|
|
gibber.next += 1;
|
|
const id = gibber.next;
|
|
return new Promise((resolve, reject) => {
|
|
const timer = window.setTimeout(() => {
|
|
pending.delete(id);
|
|
reject(new Error("the Gibberlink encoder did not answer"));
|
|
}, GIBBER.timeout);
|
|
pending.set(id, {resolve, reject, timer});
|
|
ready.then(() => frame.contentWindow.postMessage({id, protocol: step.protocol, frames: step.frames}, "*"));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @param {AudioContext} sound the page's audio context.
|
|
* @param {object} item the row that sounds.
|
|
* @param {object} step its Gibberlink step: frames, protocol and pan.
|
|
* @returns {Promise<boolean>} whether the whole row sounded uncut: the frames one after another with a short gap, at the row's tone volume times the squelch, in the sender's stereo position.
|
|
*/
|
|
async function keyGibberlink(sound, item, step) {
|
|
const level = loudness(item.tone);
|
|
if (level <= 0 || !step.frames.length) {
|
|
return false;
|
|
}
|
|
const {rate, samples: parts} = await gibberEncode(step);
|
|
if (speech.item !== item) {
|
|
return false;
|
|
}
|
|
if (!allows(rendered(item, item.at), "gibberlink")) {
|
|
item.cut = true;
|
|
return false;
|
|
}
|
|
const gap = Math.round(rate * GIBBER.gap);
|
|
const buffer = sound.createBuffer(1, parts.reduce((sum, part) => sum + part.length + gap, 0), rate);
|
|
const data = buffer.getChannelData(0);
|
|
parts.reduce((at, part) => {
|
|
data.set(part, at);
|
|
return at + part.length + gap;
|
|
}, 0);
|
|
const source = sound.createBufferSource();
|
|
const gain = sound.createGain();
|
|
const pan = sound.createStereoPanner();
|
|
gain.gain.value = level;
|
|
pan.pan.value = step.pan;
|
|
source.buffer = buffer;
|
|
source.connect(gain).connect(pan).connect(sound.destination);
|
|
voicePace(item, Infinity, buffer.duration);
|
|
const ended = sounded(item, source, buffer.duration);
|
|
source.start();
|
|
return ended.then(() => speech.item === item && !item.cut);
|
|
}
|