Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// const actualChunkDuration = baseChunkDuration + (Math.random() * 0.5 - 0.25) * baseChunkDuration;
const chunked = this.getChunk(metaBuffer, chunkStart, baseChunkDuration + overlapDuration);
// chunk times rounded to actual samples: updated values
chunkStart = chunked.chunkStart;
const chunkDuration = chunked.chunkDuration;
const chunkBuffer = chunked.chunkBuffer;
const overlapStart = chunkStart > overlapDuration ? overlapDuration : 0;
overlapEnd = chunkStart + chunkDuration + overlapDuration < totalDuration ? overlapDuration : 0;
const filename = `${chunkIndex}-${input.name}.${outputExtension}`;
const chunkPath = path.join(outputDir, filename);
if (outputExtension === 'mp3') {
// need to encode segmented wav buffer to mp3
const encoder = new Lame({
output: chunkPath,
bitrate: this.bitrate,
});
encoder.setBuffer(chunkBuffer);
// @todo - limit the number of processes
const promise = encoder.encode().catch((error) => {
console.error(`Error with lame ${error.message}`);
throw error;
});
encoderPromises.push(promise);
} else {
// wav output
fs.writeFile(chunkPath, chunkBuffer, (error) => {
if (error) {
const resampleFileAsync = ({ file, path }, cb) => {
const [fileNameNoFormat, format] = file.split('.');
const input = `${path}/${fileNameNoFormat}.${format}`;
const output = getOutputPath(`${fileNameNoFormat}.mp3`);
const encoder = new Lame({
output,
bitrate: 128,
resample: 44.1,
meta: createId3TagsSchema({ fileName: file }),
}).setFile(input);
return encoder.encode()
.then(() => {
cb({ file, path});
});
};
files.forEach(filename => {
const basename = path.basename(filename, '.wav');
const decoder = new Lame({
output: `./samples/vsco2-violins-susvib-mp3/${basename}.mp3`,
}).setFile(filename);
decoder.decode();
});
});
const encode = (wavFile, mp3File, trackMetadata) => {
return new lame.Lame({
bitrate: 320,
output: mp3File,
quality: 2,
meta: trackMetadata
}).setFile(wavFile).encode()
}