aws-samples / aws-samples/amazon-nova-samples
Why use a deprecated API for recording sound (createScriptProcessor)?
- Dominant language
- Jupyter Notebook
- Stars
- 452
- Forks
- 266
- PR merge metrics
- No merged PRs in 30d
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:
```javascript
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](https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/createScriptProcessor)?
Contributor guide
Research direction
Start with the samples' recording path that calls audioContext.createScriptProcessor, then compare it with the initializeAudioWorklet entry point and audioRecorderProcessorCode shown in the issue. Done means documenting why the samples use the deprecated API and whether the AudioWorkletProcessor approach is an appropriate replacement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- audio-video-rtc
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100