This is a `playground`

to test code. It runs a full `Node.js`

environment and already has all of `npm`

’s 400,000 packages pre-installed, including `sound-parameters-extractor`

with all `npm`

packages installed. **Try it out**:

var soundParametersExtractor = require("sound-parameters-extractor")

- all documents on RunKit are public
`require()`

any package directly from npm- use arrow functions, classes, template strings, and most of ES6
`await`

any promise instead of using callbacks (example)- create your own embedded
**node.js**snippets

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

# 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)

```
const {
getParamsFromFile,
arrayToRaw
} = require('sound-parameters-extractor');
const config = {
fftSize: 32,
bankCount: 24,
lowFrequency: 1,
highFrequency: 8000, // samplerate/2 here
sampleRate: 16000
};
getParamsFromFile('sound.wav', config, 16)
.then(params => {
console.log(params);
arrayToRaw(params.mfcc, 'sound.raw');
});
```

Divides the signal in frames, the end of the signal will be filled with 0.

```
const {framer} = require('sound-parameters-extractor');
const windowSize = 4;
const overlap = '50%';
const signal = new Array(64).fill(0).map((val, index) => index);
const framedSignal = framer(signal, windowSize, overlap);
console.log(framedSignal);
//[[0, 1, 2, 3], [2, 3, 4, 5], [4, 5, 6, 7], ...]
```

Computes the MFCC for a given signal

```
const fft = require('fft-js'); // is dependency
const {framer, mfcc} = require('sound-parameters-extractor');
const config = {
fftSize: 32,
bankCount: 24,
lowFrequency: 1,
highFrequency: 8000, // samplerate/2 here
sampleRate: 16000
};
const windowSize = config.fftSize * 2;
const overlap = '50%';
const mfccSize = 12;
const signal = new Array(1024).fill(0).map((val, index) => index);
const framedSignal = framer(signal, windowSize, overlap);
//mfccSize is optionnal default 12
const mfccMatrix = mfcc.construct(config, mfccSize);
const mfccSignal = framedSignal.map(window => {
const phasors = fft.fft(window);
return mfccMatrix(fft.util.fftMag(phasors));
});
console.log(mfccSignal);
// mfccSignal contains the mel-frenquencies
```

Computes the number of times the signal cross 0. Must be computed on the signal.

`zeroCrossingRate(window)`

Formal application of the formula.

######`zeroCrossingRateClipping(window, threshold)`

Allows you to use a threshold for better noise resistance. This method gives the
same result but has better performance than the formal one.

`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.

`spectralCentroid(frame)`

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).

`spectralCentroidSRF(frame, sampleRate)`

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

`deltaFrameAllSignal(acousticVectors, overlap)`

Uses `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.

`deltaCustomAllSignal(acousticVectors)`

and `deltaDeltaCustomAllSignal(acousticVectors)`

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.

`modulusFFT(frame, removeHalf)`

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.
If `removeHalf`

is true, the second half of the fft will be removed before computing the fft.

`remarkableEnergyRate(arrayDecoded, framedSound)`

Computed the RER on the signal

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:
`arrayDecoded`

) ; - The framed sound (key:
`framedSound`

) ; - MFCC (key :
`mfcc`

) ; - FFT (key :
`fft`

) ; - Zero crossing rate (key :
`zcr`

) ; - Spectral Centroid (key :
`sc`

) ; - Spectral Centroid computed via spectral roll of method (key :
`sc2`

) ; - Spectral Roll-Off Point (key :
`srf`

) ; - Remarkable energy rate (key :
`rer`

).

`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 : `'file.raw'`

)

`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 : `./not/existing/yet`

)

- package on npmhttps://npmjs.com/package/sound-parameters-extractor
- licenseMIT

RunKit is a free, in-browser JavaScript dev environment for prototyping **Node.js** code, with every **npm** package installed. Sign up to share your code.

Sign Up for Free