Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including audio-analyser with all npm packages installed. Try it out:

var audioAnalyser = require("audio-analyser")

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

audio-analyser v1.0.2

Audio analyser stream

Audio analyser stream. Provides API of the AnalyserNode for audio-streams. In all respects can be used in the same way.

Usage

npm install audio-analyser

var Analyser = require('audio-analyser');
var Generator = require('audio-generator');


var analyser = new Analyser({
    // Magnitude diapasone, in dB
    minDecibels: -100,
    maxDecibels: -30,

    // Number of time samples to transform to frequency
    fftSize: 1024,

    // Number of frequencies, twice less than fftSize
    frequencyBinCount: 1024/2,

    // Smoothing, or the priority of the old data over the new data
    smoothingTimeConstant: 0.2,

    // Number of channel to analyse
    channel: 0,

    // Size of time data to buffer
    bufferSize: 44100,

    // Windowing function for fft, https://github.com/scijs/window-functions
    applyWindow: function (sampleNumber, totalSamples) {
    }

    //...pcm-stream params, if required
});


//AnalyserNode methods

// Copies the current frequency data into a Float32Array array passed into it.
analyser.getFloatFrequencyData(arr);

// Copies the current frequency data into a Uint8Array passed into it.
analyser.getByteFrequencyData(arr);

// Copies the current waveform, or time-domain data into a Float32Array array passed into it.
analyser.getFloatTimeDomainData(arr);

// Copies the current waveform, or time-domain data into a Uint8Array passed into it.
analyser.getByteTimeDomainData(arr);


//Shortcut methods

//return array with frequency data in decibels of size <= fftSize
analyser.getFrequencyData(size);

//return array with time data of size <= self.bufferSize (way more than fftSize)
analyser.getTimeData(size);


//Can be used both as a sink or pass-through
Generator().pipe(analyser);

Related

audio-render — render audio streams.
audio-spectrum — render audio spectrum.
audio-spectrogram — render audio spectrogram.
audio-waveform — render audio waveform.
audio-stat — render any kind of audio info: waveform, spectrogram etc.
pcm-util — utils for work with pcm-streams.
ndarray-fft — implementation of fft for ndarrays.

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