A pitch-detection library for node (using C++ Addon)
npm install node-pitchfindernpm install --save node-pitchfinder> For node < 10 use version ^1.x, version 2+ is for node >= 10
javascript
const fs = require('fs')
const WavDecoder = require('wav-decoder')
const { YIN } = require('node-pitchfinder')// see below for option parameters.
const detectPitch = YIN({ sampleRate: 44100 })
const buffer = fs.readFileSync(PATH_TO_FILE)
const decoded = WavDecoder.decode(buffer) // get audio data from file using
wav-decoder
const float64Array = decoded.channelData[0] // get a single channel of sound
const pitch = detectPitch(float64Array) // All detectors are using float64Array internally, but you can also give an ordinary array of numbers
`Configuration
$3
- sampleRate - defaults to 44100$3
- threshold - used by the algorithm
- probabilityThreshold - don't return a pitch if probability estimate is below this number.$3
- minFrequency - Lowest frequency detectable
- maxFrequency - Highest frequency detectable
- sensitivity
- ratio$3
- bufferSize - Maximum data size (default 1024)
- cutoff - Defines the relative size the chosen peak (pitch) has. 0.93 means: choose
the first peak that is higher than 93% of the highest peak detected. 93% is the default value used in the Tartini user interface.
- freqCutoff - Minimum frequency to be detected (default 80Hz)
- probabilityThreshold - don't return a pitch if probability estimate is below this number.$3
no special configMORE API
$3
- method: getResult (data) - does not use probabilityThreshold, returns an object with probability instead, like { pitch: number, probability: number }#### Usage
`js
const {MacLeod} = require('node-pitchfinder')
const detectPitch = MacLeod().getResultdetectPitch(data)
// {pitch: 440, probability: 1}
``Thanks to Aubio for his YIN code