From 9292ac9bab7deafe74cae867b383d403b1d8a051 Mon Sep 17 00:00:00 2001 From: orfelorfel23 Date: Fri, 28 Aug 2026 15:11:53 +0200 Subject: [PATCH] Fix syntax error in app.js and add ffmpeg conversion --- public/app.js | Bin 5617 -> 5129 bytes server/routes/recognize.js | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/public/app.js b/public/app.js index af1e8abcf282ad6cafd6cabf2cc189286e4b9d90..a6e82a5ae23cf1fe07bb8cbb3d36949ab6e6ca8b 100644 GIT binary patch delta 495 zcmeyU-KnwRoS<51UUErhex5=}etLRNYIsI!YL14cLN%9yLUMjyafw1kYEiy|?IcdA zdJs!p(;6s~nWmrt;^`&lBo-I@WEPj`0Tq`dX66-ZsF#C`(9O+HNmbW`7^I+3lv)4=0J3c$Wwl(jTwH0eSV0OnU~o!Zo{)<6JF!gmP~VanCdfjb18BS6YAqE}&c zCaNo*N8D2f^_5e7C4ra$j6=<6C;UzwodH+HR7zdTa63-rDEDuU%34>>hZmGWd~#P7 zq9Z#&IkXb0M+#skr&9dIUmzl=Ijt3|pVPQPEPIt&j}oh>m@Sv=AGJ<(xJRr?oo(JI sm#CGARq!vTYjEGj>{UglDkrGv47hvYke2*@Qf$?0I21^`v3p{ 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) {