Voice testing
This commit is contained in:
+26
-3
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user