-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.mjs
More file actions
47 lines (43 loc) · 2.12 KB
/
example.mjs
File metadata and controls
47 lines (43 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { fs, path } from '@eliware/common';
import { Resampler } from '@eliware/resampler';
async function run() {
// Downsample: 48kHz stereo -> 24kHz mono
const input48Stereo = path(import.meta, 'input-48k-stereo.s16le');
const output24Mono = path(import.meta, 'output-24k-mono.s16le');
const resamplerDown = new Resampler({ inRate: 48000, outRate: 24000, inChannels: 2, outChannels: 1 });
console.log('Resampling 48kHz stereo → 24kHz mono...');
await new Promise((resolve, reject) => {
fs.createReadStream(input48Stereo)
.pipe(resamplerDown)
.pipe(fs.createWriteStream(output24Mono))
.on('finish', resolve)
.on('error', reject);
});
console.log('Downsample complete:', output24Mono);
// Upsample: 24kHz mono -> 48kHz stereo
const input24Mono = path(import.meta, 'input-24k-mono.s16le');
const output48Stereo = path(import.meta, 'output-48k-stereo.s16le');
const resamplerUp = new Resampler({ inRate: 24000, outRate: 48000, inChannels: 1, outChannels: 2 });
console.log('Resampling 24kHz mono → 48kHz stereo...');
await new Promise((resolve, reject) => {
fs.createReadStream(input24Mono)
.pipe(resamplerUp)
.pipe(fs.createWriteStream(output48Stereo))
.on('finish', resolve)
.on('error', reject);
});
console.log('Upsample complete:', output48Stereo);
// Downsample with volume control: 48kHz stereo -> 24kHz mono, half volume
const output24MonoQuiet = path(import.meta, 'output-24k-mono-quiet.s16le');
const resamplerDownQuiet = new Resampler({ inRate: 48000, outRate: 24000, inChannels: 2, outChannels: 1, volume: 0.5 });
console.log('Resampling 48kHz stereo → 24kHz mono at half volume...');
await new Promise((resolve, reject) => {
fs.createReadStream(input48Stereo)
.pipe(resamplerDownQuiet)
.pipe(fs.createWriteStream(output24MonoQuiet))
.on('finish', resolve)
.on('error', reject);
});
console.log('Downsample (quiet) complete:', output24MonoQuiet);
}
run().catch(err => console.error(err));