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
| const { exec } = require('child_process'); const fs = require('fs'); const path = require('path');
const inputFolder = './input_folder'; const outputFolder = './output_folder';
if (!fs.existsSync(outputFolder)) { fs.mkdirSync(outputFolder); }
fs.readdir(inputFolder, (err, files) => { if (err) { console.error('Error reading input folder:', err); return; }
const wavFiles = files.filter((file) => path.extname(file) === '.wav');
wavFiles.forEach((file) => { const inputFilePath = path.join(inputFolder, file); const outputFileName = path.basename(file, '.wav') + '.mp3'; const outputFilePath = path.join(outputFolder, outputFileName);
const command = `ffmpeg -i "${inputFilePath}" "${outputFilePath}"`;
exec(command, (err, stdout, stderr) => { if (err) { console.error(`Error converting ${file}:`, err); return; }
console.log(`${file} converted to MP3 successfully!`); }); }); });
|