diff --git a/public/app.js b/public/app.js index af1e8ab..a6e82a5 100644 Binary files a/public/app.js and b/public/app.js differ diff --git a/server/routes/recognize.js b/server/routes/recognize.js index 6a117e1..c9a23cf 100644 --- a/server/routes/recognize.js +++ b/server/routes/recognize.js @@ -18,9 +18,18 @@ router.post('/', upload.single('audio'), async (req, res) => { const filePath = req.file.path; try { - // 1. Generate fingerprint using fpcalc + // 0. Convert uploaded file to WAV using ffmpeg to guarantee fpcalc can read it + const wavPath = filePath + '.wav'; + await new Promise((resolve, reject) => { + execFile('ffmpeg', ['-i', filePath, '-ar', '44100', '-ac', '2', '-f', 'wav', wavPath], (err, stdout, stderr) => { + if (err) return reject(new Error('ffmpeg failed: ' + stderr)); + resolve(); + }); + }); + + // 1. Generate fingerprint using fpcalc on the WAV file const { duration, fingerprint } = await new Promise((resolve, reject) => { - execFile('fpcalc', [filePath], (error, stdout, stderr) => { + execFile('fpcalc', [wavPath], (error, stdout, stderr) => { if (error) { return reject(new Error('fpcalc failed: ' + stderr)); } @@ -41,6 +50,9 @@ router.post('/', upload.single('audio'), async (req, res) => { }); }); + // Clean up WAV file + fs.unlink(wavPath, () => {}); + // 2. Query AcoustID API const acoustidKey = process.env.ACOUSTID_API_KEY; if (!acoustidKey) {