Fix choppy/distorted audio to live caller

- Mute host mic forwarding while TTS is streaming to prevent interleaving
  both audio sources into the same playback buffer
- Replace nearest-neighbor downsampling with box-filter averaging on both
  server (host mic) and browser (caller mic) for anti-aliased resampling

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-05 17:01:33 -07:00
parent d4e25ceb88
commit d583b48af0
5 changed files with 18 additions and 8 deletions

View File

@@ -52,12 +52,14 @@ class CallerProcessor extends AudioWorkletProcessor {
const input = inputs[0][0];
if (!input) return true;
const ratio = sampleRate / 16000;
for (let i = 0; i < input.length; i += ratio) {
const idx = Math.floor(i);
if (idx < input.length) {
this.buffer.push(input[idx]);
// Downsample with averaging (anti-aliased)
const step = Math.floor(sampleRate / 16000);
for (let i = 0; i + step <= input.length; i += step) {
let sum = 0;
for (let j = 0; j < step; j++) {
sum += input[i + j];
}
this.buffer.push(sum / step);
}
while (this.buffer.length >= this.targetSamples) {