MTG / essentia.js

JavaScript library for music/audio analysis and processing powered by Essentia WebAssembly
https://essentia.upf.edu/essentiajs
GNU Affero General Public License v3.0
627 stars 41 forks source link

GapsDetector not returning timestamp of anomaly in NodeJS #125

Open rob-richards opened 1 year ago

rob-richards commented 1 year ago

What is the issue about?

What part(s) of Essentia.js is involved?

Description

I am not getting any returned frames that contain a gap in the audio using GapsDetector. I am using Node for offline extraction. Am I missing something?

I know for sure that the audio file has gaps. I added 3 of them manually in my DAW.

Steps to reproduce / Code snippets / Screenshots

const esLib = require('essentia.js');
const wav = require('node-wav');
const fs = require('fs');

const frameSize = 2048;
const hopSize = 1024;

async function detectGapsInAudio(audioFilename) {
  try {
    const essentia = new esLib.Essentia(esLib.EssentiaWASM);

    const buffer = fs.readFileSync(audioFilename);

    const audio = wav.decode(buffer);

    const audioDataLeft = essentia.arrayToVector(audio.channelData[0]);
    const audioDataRight = essentia.arrayToVector(audio.channelData[1]);

    const audioDownMixed = essentia.MonoMixer(
      audioDataLeft,
      audioDataRight
    ).audio;

    const audioData = essentia.vectorToArray(audioDownMixed);

    const frames = essentia.FrameGenerator(audioData, frameSize, hopSize);

    const gaps = [];

    for (let i = 0; i < frames.size(); i++) {
      // Detect gaps for each frame of downmixed audio signal
      const gapsDetector = essentia.GapsDetector(
        frames.get(i),
        0.05, // attackTime
        frameSize, // frameSize
        hopSize, // hopSize
        11, // kernelSize
        3500, // maximumTime
        10, // minimumTime
        40, // postpowerTime
        -30, // prepowerThreshold
        20, // prepowerTime
        0.05, // releaseTime
        44100, // sampleRate
        -50 // silenceThreshold
      );

      if (gapsDetector.starts.size() !== 0) {
        gaps.push(gapsDetector);
      }
    }

    console.log('gaps :>> ', gaps);

    frames.delete();
    essentia.delete();
  } catch (error) {
    console.error('Catch Block Error: >> ', error);
  }
}

const audioFilename = 'audio-file.wav';
detectGapsInAudio(audioFilename);

System info

MacBook Pro M2 Max, Node.js v18.16.0