openclaw-voice/server/static/voice-worklet.js

31 lines
819 B
JavaScript

// AudioWorklet processor for capturing raw PCM audio
// Captures audio at 16kHz mono float32 as specified by getUserMedia
class VoiceProcessor extends AudioWorkletProcessor {
constructor() {
super();
this.port.onmessage = this.handleMessage.bind(this);
}
handleMessage(event) {
// No message handling needed - audio is captured automatically
// in onaudioprocess
}
process(inputs, outputs, parameters) {
// Get input audio
const input = inputs[0];
if (input && input.length > 0) {
// Get mono channel (channel 0)
const channelData = input[0];
// Send audio data to main thread
this.port.postMessage({ type: 'audio', audio: channelData });
}
// Keep processor alive
return true;
}
}
registerProcessor('voice-processor', VoiceProcessor);