zebra-spaces: deploy anti-alias + compressor self-transcribe

This commit is contained in:
russell@unturf.com 2026-06-05 13:42:15 -04:00
parent eb1718225e
commit 6d24cf2d8f
No known key found for this signature in database

View file

@ -2367,14 +2367,29 @@ async function startSelfCapture(){
if (!ok){ logLine('err','self capture: worklet module load failed'); return; }
try {
const src = audioCtx.createMediaStreamSource(micStream);
/* DynamicsCompressorNode — normalize amplitude before Whisper.
* Host raw mic (especially in music mode with no AGC) has wide
* dynamic range; Whisper accuracy suffers on quiet/clipped
* passages. Compressor flattens it. Voice-friendly settings. */
const comp = audioCtx.createDynamicsCompressor();
comp.threshold.value = -30; comp.knee.value = 30;
comp.ratio.value = 4; comp.attack.value = 0.003; comp.release.value = 0.25;
/* BiquadFilter lowpass @ 7 kHz — anti-alias before the worklet's
* 48k→16k decimation. Mic content >8 kHz otherwise folds into
* the audible band as noise and degrades Whisper. Listener path
* doesn't need this because Opus has already band-limited the
* peer audio. Fox 2026-06-05: "the remote phones are transcribing
* more accurate than the host version." */
const lpf = audioCtx.createBiquadFilter();
lpf.type = 'lowpass'; lpf.frequency.value = 7000; lpf.Q.value = 0.707;
const cap = new AudioWorkletNode(audioCtx, 'whisper-capture');
cap.port.onmessage = (e) => {
if (e.data && e.data.chunk) handleWhisperChunk(myUUID, e.data.chunk);
};
src.connect(cap);
src.connect(comp).connect(lpf).connect(cap);
cap.port.postMessage({ cmd: 'start' });
_selfCapture = { src, cap };
logLine('', 'whisper: self capture started');
_selfCapture = { src, comp, lpf, cap };
logLine('', 'whisper: self capture started (anti-alias + compressor)');
} catch (e){
logLine('err', 'whisper self capture: '+e.message);
}
@ -2383,6 +2398,8 @@ function stopSelfCapture(){
if (!_selfCapture) return;
try { _selfCapture.cap.port.postMessage({ cmd: 'stop' }); } catch(_){}
try { _selfCapture.cap.disconnect(); } catch(_){}
try { _selfCapture.lpf.disconnect(); } catch(_){}
try { _selfCapture.comp.disconnect(); } catch(_){}
try { _selfCapture.src.disconnect(); } catch(_){}
_selfCapture = null;
}
@ -2393,6 +2410,13 @@ async function startCaptureForUuid(uuid){
const ok = await loadWhisperCaptureWorklet(audioCtx);
if (!ok) return;
try {
/* Same anti-alias lowpass as self-capture. Opus has already
* band-limited remote audio, so this is usually a no-op — but
* the music-mode peer can push wideband Opus close to 12 kHz
* and the decimation still aliases. Cheap to apply
* unconditionally. */
const lpf = audioCtx.createBiquadFilter();
lpf.type = 'lowpass'; lpf.frequency.value = 7000; lpf.Q.value = 0.707;
const capture = new AudioWorkletNode(audioCtx, 'whisper-capture');
capture.port.onmessage = (e) => {
if (e.data && e.data.chunk) handleWhisperChunk(uuid, e.data.chunk);
@ -2400,9 +2424,10 @@ async function startCaptureForUuid(uuid){
/* tap the source — capture runs in parallel with the worklet
* chain, doesn't need to connect to destination (we just want
* the chunks via port messages). */
node.src.connect(capture);
node.src.connect(lpf).connect(capture);
capture.port.postMessage({ cmd: 'start' });
node.capture = capture;
node.captureLpf = lpf;
logLine('', 'whisper: capture started for '+uuid.slice(0,4));
} catch (e){
logLine('err', 'whisper capture install '+uuid.slice(0,4)+': '+e.message);
@ -2414,6 +2439,10 @@ function stopCaptureForUuid(uuid){
if (!node || !node.capture) return;
try { node.capture.port.postMessage({ cmd: 'stop' }); } catch(_){}
try { node.capture.disconnect(); } catch(_){}
if (node.captureLpf){
try { node.captureLpf.disconnect(); } catch(_){}
node.captureLpf = null;
}
try { node.src.disconnect(node.capture); } catch(_){}
node.capture = null;
}
@ -7427,8 +7456,8 @@ logLine('', 'ready — pick a handle, type a rendezvous code, enter the space');
<footer style="margin:2.2rem auto 0;font-size:0.65rem;color:#999;line-height:1.7;word-break:break-all;font-family:monospace">
<span id="pi-seal" style="color:#777;cursor:default;user-select:none" title="">page integrity</span> &nbsp;·&nbsp; built <span class="stamp-date">2026-06-05</span><br>
md5 <span class="stamp-md5">2735b0ba85cac127a1dee3bdc5ecd88e</span><br>
sha256 <span class="stamp-sha">725573c39710827dda977eb9dbcf13d05fad6cc73ba694448d3886f63810bd80</span><br>
md5 <span class="stamp-md5">e2a9c5eb310147cb147f54dc2495f3f6</span><br>
sha256 <span class="stamp-sha">076444a5567d418cb48557ee1b1e0c88539534a1532df4d6f6be98a7e40b0343</span><br>
<span style="color:#bbb">hashes are of this page with these two fields zeroed — to verify, blank them and re-hash</span><br>
<span style="color:#bbb">one self-contained file — <strong>save a copy</strong> and verify against these hashes; point at your own servers with ?signal= and ?turncred=, or <a href="host-your-own.html" style="color:#999">host your own community</a></span>
</footer>