This library previous consisted of a single script tag to be included in the browser. I'm deprecating that version and replacing it with a new,
babel version. If you have been using the old version, please check out the
legacy branch, which consists of the old code. However, I will not be supporting it going forwards. Version 2 is bringing many improvements, unit tests, and more.
If you'd like a version that uses compiled C++ code and runs much faster, check out this repo. However, it will not work in the browser.
npm install --save pitchfinder
All pitchfinding algorithms provided operate on
Float32Arrays. To find the pitch of a
wav file, we can use the
wav-decoder library to extract the data into such an array.
const fs = ;const WavDecoder = ;const Pitchfinder = ;// see below for optional constructor parameters.const detectPitch = ;const buffer = fs;const decoded = WavDecoder; // get audio data from file using `wav-decoder`const float32Array = decodedchannelData0; // get a single channel of soundconst pitch = ; // null if pitch cannot be identified
This assumes you are using an npm-compatible build system, like Webpack or Browserify, and that your target browser supports WebAudio. Ample documentation on WebAudio is available online, especially on Mozilla's MDN.
const Pitchfinder = ;const detectPitch = Pitchfinder;const myAudioBuffer = ; // assume this returns a WebAudio AudioBuffer objectconst float32Array = myAudioBuffer; // get a single channel of soundconst pitch = ; // null if pitch cannot be identified
Set a tempo and a quantization interval, and an array of pitches at each interval will be returned.
const Pitchfinder = ;const detectPitch = Pitchfinder;const frequencies = Pitchfinder;// or use multiple detectors for better accuracy at the cost of speed.const detectors = detectPitch Pitchfinder;const moreAccurateFrequencies = Pitchfinder;
sampleRate- defaults to 44100
threshold- used by the algorithm
probabilityThreshold- don't return a pitch if probability estimate is below this number.
minFrequency- Lowest frequency detectable
maxFrequency- Highest frequency detectable
no special config
teoriaor another music theory tool to add more intelligent parsing.
Several of these algorithms were ported from Jonas Six's excellent TarsosDSP library (written in Java). If you're looking for a far deeper set of tools than this, check out his work on his website or on Github.
Thanks to Aubio for his YIN code