npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sound-parameters-extractor

v2.0.3

Published

Calculation of sound parameters

Downloads

56

Readme

# Sound parameters extractor

XO code style

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.

Contents

Installation

npm install --save sound-parameters-extractor

Usage

Basic usage

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');
});
 

Advanced usage

Framer

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], ...]

MFCC

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

Parameters

Zero Crossing Rate

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.

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.

Spectral centroid
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

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

FFT Modulus
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.

Remarkable energy rate
remarkableEnergyRate(arrayDecoded, framedSound)

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

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 : '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)