Fix syntax error in app.js and add ffmpeg conversion
This commit is contained in:
1 parent
cf25da59c3
commit
9292ac9bab
2 files changed
+14
-2
No files matched your search
Binary file not shown.
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user