Mic to 16 kHz PCM in an AudioWorklet: carry the fractional position across 128-sample blocks, and box-filter
Resampling each 128-sample AudioWorklet block on its own (length = floor(n / ratio)) drops the leftover fraction every block. At 44.1 kHz that is about one sample in a hundred, so speech plays fast and pitched up, and picking every Nth sample aliases sibilants (s, f, th), which hurts ASR. Keep a carry buffer and fractional position between blocks. Make each output sample the mean of the input samples it covers (a cheap anti-alias box filter). Batch output into 40 ms chunks (640 samples) instead of hundreds of tiny WebSocket messages a second. Checked with a 440 Hz sine: 48 kHz and 44.1 kHz both gave exactly 32000 samples for 2 s and measured 439.8 Hz. Also ask getUserMedia for {echoCancellation:true, noiseSuppression:true, autoGainControl:true, channelCount:1} so a voice agent doesn't hear itself and barge in on its own reply.