You can use the spectralFlux function provided by Meyda to compare two signals. The spectral flux, according to Wikipedia, "is usually calculated as the 2-norm (also known as the Euclidean distance) between two normalized spectra."
After running npm install --save meyda you will do something like:
const spectralFlux = require('meyda/src/extractors/spectralFlux'); const difference = spectralFlux({ signal: [your first signal], previousSignal: [your second signal] });
Feel free to simply copy the code from here , so that you do not have to process the dependency, the code base has an appropriate license.
It will return the coefficient of how two signals sound “different”. You can do this either in the time domain or in the frequency domain. You will get different numbers, but both will correlate with how “different” sounds are from each other.
But the “difference” may not describe the differences accurately enough for your use case. For example, you may worry a lot about volume differences, and not much about timbral differences, but the spectral flux metric does not take this into account. You can first run each signal through the function extractors, find other statistical data about their properties, such as their perception volume, their brightness, etc., and then take the weighted Euclidean distance between these data, which will provide a more individual "difference" to what you need for your purpose.
We will gladly think further, but this is already quite a long time for the SO answer.
source share