Sound parameters extractor
This package helps you to get the acoustics parameters for a given sound and provides some tools to add others parameters.
Feel free to contribute or discuss my choices.
The MFCC code comes from : vails-systems implementation. The package was broken for me so I decided to fix it and provide some new tools.
npm install --save sound-parameters-extractor
Read the wav file and then write the MFCC in a binary format (usable by Alize)
constgetParamsFromFilearrayToRaw} = ;const config =fftSize: 32bankCount: 24lowFrequency: 1highFrequency: 8000 // samplerate/2 heresampleRate: 16000;;
Divides the signal in frames, the end of the signal will be filled with 0.
const framer = ;const windowSize = 4;const overlap = '50%';const signal = 64;const framedSignal = ;console;//[[0, 1, 2, 3], [2, 3, 4, 5], [4, 5, 6, 7], ...]
Computes the MFCC for a given signal
const fft = ; // is dependencyconst framer mfcc = ;const config =fftSize: 32bankCount: 24lowFrequency: 1highFrequency: 8000 // samplerate/2 heresampleRate: 16000;const windowSize = configfftSize * 2;const overlap = '50%';const mfccSize = 12;const signal = 1024;const framedSignal = ;//mfccSize is optionnal default 12const mfccMatrix = mfcc;const mfccSignal = framedSignal;console;// mfccSignal contains the mel-frenquencies
Zero Crossing Rate
Computes the number of times the signal cross 0. Must be computed on the signal.
Formal application of the formula.
Allows you to use a threshold for better noise resistance. This method gives the same result but has better performance than the formal one.
Spectral roll off point
spectralRollOffPoint(frame, sampleRate, cutoff, hz = false)
Computes the spectral roll-off point on a given frame.
Is computed on the modulus of the fft (don't forget to delete the first half of the FFT).
If hz is true the return will be in hertz, if not it's the index in the vector.
Computes the spectral centroid on a given frame. It's computed on the modulus of the fft (don't forget to delete the first half of the FFT).
This method uses the spectral roll off point with a cutoff of 50%, this is the equivalent of the spectral centroid, currently the spectral centroid method have some problems with ALIZE
deltaFrame to compute the derivative, used for MFCC.
Implementation of derivative formula from Practical Cryptography
Use it on the deltaParameters to have the delta delta.
Use a Taylor decomposition to estimate the first and second derivative. The delta delta are computed on the acoustic vector (and not the deltas) to minimize the approximation.
Computes the modulus of the FFT for a given frame.
You may want to delete the first half of the FFT before computing its modulus.
removeHalf is true, the second half of the fft will be removed before computing the fft.
Remarkable energy rate
Computed the RER on the signal
Parameters from file
This is a simple wrapper from file reading to parameters, you can have a look at it to see how to get sound parameters. Please have a look at Basic usage on how to use it. This method returns an object containing :
- The sound extracted by node-wav (key:
- The framed sound (key:
- MFCC (key :
- FFT (key :
- Zero crossing rate (key :
- Spectral Centroid (key :
- Spectral Centroid computed via spectral roll of method (key :
- Spectral Roll-Off Point (key :
- Remarkable energy rate (key :
Array to Raw
arrayToRaw(array, outputName, outputPath = '')
Write the given vectors to a binary file (RAW) this can be used by
Alize (e.g. i-vectors).
array is two dimensional
outputName is the name and extension of the file (eg :
outputPath is optional if not provided file will be write in
process.cwd() if provided the directories will be created if they are not existing (eg :