2024-02-18 18:32:58 +01:00
|
|
|
import { Command } from 'commander';
|
|
|
|
import wav from 'node-wav';
|
|
|
|
import fs from 'fs';
|
|
|
|
|
|
|
|
const program = new Command();
|
|
|
|
program
|
|
|
|
.requiredOption('-i, --input <input>', 'Input file')
|
|
|
|
.requiredOption('-o, --output <output>', 'Output file')
|
|
|
|
.requiredOption('--repeats <repeats>', 'Number of repeats')
|
|
|
|
.parse(process.argv);
|
|
|
|
const options = program.opts();
|
|
|
|
|
|
|
|
let beep = wav.decode(fs.readFileSync(options.input));
|
|
|
|
let samples = beep.channelData[0];
|
|
|
|
|
|
|
|
const sampleRate = beep.sampleRate;
|
|
|
|
const silenceDuration = sampleRate - samples.length;
|
|
|
|
const silenceSamples = new Float32Array(silenceDuration).fill(0);
|
|
|
|
|
|
|
|
let oneSecondChunk = new Float32Array(sampleRate);
|
|
|
|
oneSecondChunk.set(samples, 0);
|
|
|
|
oneSecondChunk.set(silenceSamples, samples.length);
|
|
|
|
|
|
|
|
let numberOfRepeats = parseInt(options.repeats);
|
|
|
|
let finalSamples = new Float32Array(sampleRate * numberOfRepeats);
|
|
|
|
|
|
|
|
for (let i = 0; i < numberOfRepeats; i++) {
|
|
|
|
finalSamples.set(oneSecondChunk, i * sampleRate);
|
|
|
|
}
|
|
|
|
|
2024-02-26 12:45:38 +01:00
|
|
|
let halfSecondSilence = new Float32Array(sampleRate / 2).fill(0);
|
|
|
|
finalSamples = Float32Array.from([...halfSecondSilence, ...finalSamples]);
|
|
|
|
|
2024-02-18 18:32:58 +01:00
|
|
|
let finalBuffer = wav.encode([finalSamples], { sampleRate: sampleRate, float: true, bitDepth: 32 });
|
|
|
|
|
|
|
|
fs.writeFileSync(options.output, finalBuffer);
|