I've been working on an audio-related app for one of my clients recently.
I ended up writing a TypeScript port of the popular node-record-lpcm16 package, which hadn't been updated in years and lacked TypeScript support. I've modernized the codebase and added full TypeScript bindings. This also prevents certain weird errors and warnings from appearing when the library is used in more modern projects.
import { record } from 'node-record-lpcm16-ts';
import fs from 'fs';
const file = fs.createWriteStream('test.wav', { encoding: 'binary' });
const recording = record({
sampleRate: 44100,
channels: 1
});
recording.stream().pipe(file);
// Stop recording after 3 seconds
setTimeout(() => {
recording.stop();
}, 3000);
Check out the GitHub repository.