WhisperFusion / examples /chatbot /html /js /audio-processor.js
Marcus Edel
Add simple HTML frontend.
6d778c2
raw
history blame contribute delete
753 Bytes
class AudioStreamProcessor extends AudioWorkletProcessor {
constructor() {
super();
this.chunkSize = 4096;
this.buffer = new Float32Array(this.chunkSize);
this.bufferPointer = 0;
}
process(inputs, outputs, parameters) {
const input = inputs[0];
const output = outputs[0];
for (let i = 0; i < input[0].length; i++) {
this.buffer[this.bufferPointer++] = input[0][i];
if (this.bufferPointer >= this.chunkSize) {
this.port.postMessage(this.buffer);
this.bufferPointer = 0;
}
}
for (let channel = 0; channel < input.length; ++channel) {
output[channel].set(input[channel]);
}
return true;
}
}
registerProcessor("audio-stream-processor", AudioStreamProcessor);