generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 230
Open
Description
We are attempting to replicate some of these samples, but are using a subclass of AudioWorkletProcessor for the recording instead of the audioContext.createScriptProcessor method that is used in these samples.
Here's what we have:
export const audioRecorderProcessorCode = `
class AudioRecorderProcessor extends AudioWorkletProcessor {
constructor() {
super();
this.recording = false;
this.port.onmessage = event => {
this.recording = event.data.type === 'start-recording';
};
}
process(inputs) {
const inputSamples = inputs[0]?.[0]; // First channel of the first input
if (!this.recording || !inputSamples?.length) return true;
const pcm = Int16Array.from(inputSamples, sample =>
Math.max(-1, Math.min(1, sample)) * 0x7FFF
);
this.port.postMessage(
{ type: 'audio-data', audioData: pcm.buffer },
[pcm.buffer]
);
return true;
}
}
registerProcessor('audio-recorder-processor', AudioRecorderProcessor);
`;
async initializeAudioWorklet(ctx) {
const processorBlob = new Blob([audioRecorderProcessorCode], {
type: "application/javascript",
});
await ctx.audioWorklet.addModule(URL.createObjectURL(processorBlob));
}Is there some reason these samples use the deprecated API?
Metadata
Metadata
Assignees
Labels
No labels