Voice testing

This commit is contained in:
2026-01-05 22:34:25 +01:00
parent 07dbac50c8
commit 1af261058f
4 changed files with 106 additions and 10 deletions
+26 -3
View File
@@ -1,10 +1,33 @@
class MicProcessor extends AudioWorkletProcessor {
constructor() {
super();
this.buffer = new Float32Array(960);
this.offset = 0;
}
process(inputs) {
const input = inputs[0];
if (input.length > 0) {
const channelData = input[0]; // Float32Array
this.port.postMessage(channelData);
if (!input || !input[0]) return true;
const channel = input[0];
let i = 0;
while (i < channel.length) {
const remaining = this.buffer.length - this.offset;
const toCopy = Math.min(remaining, channel.length - i);
this.buffer.set(channel.subarray(i, i + toCopy), this.offset);
this.offset += toCopy;
i += toCopy;
if (this.offset === this.buffer.length) {
// COPY before sending
this.port.postMessage(this.buffer.slice());
this.offset = 0;
}
}
return true;
}
}