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:
@@ -150,6 +150,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/js/call-in.js?v=5"></script>
|
||||
<script src="/js/call-in.js?v=6"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user