0.0.4 • Published 7 years ago

wav-spectrogram v0.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

wav-spectrogram

A Node.js library for loading WAV files and drawing a spectrogram to a canvas.

Usage

Load WAV file using a input object, read contents as an array buffer and pass to function with a canvas of the desired dimensions:

var wavSpectro = require('wav-spectrogram');

var fileInput = document.getElementById('file-input');
var canvasElem = document.getElementById('spectrogram-canvas');

var reader = new FileReader();

reader.onload = function() {

    var arrayBuffer = reader.result;

    wavSpectro.drawSpectrogram({arrayBuffer: arrayBuffer, canvasElem: canvasElem, cmap: 'jet'}, function () {
    
        console.log("Done.");
    
    });

};

reader.readAsArrayBuffer(fileInput.files[0]);

Functions

The draw function must be handed parameters in an object, named as such. Parameters with default values can be left out.

OptionDefaultDescription
arrayBuffer-Array buffer read from WAV file
canvasElem-Canvas element to draw to (spectrogram will fill dimensions)
cmap-Colour map to draw using colormap module
nfft512Buffer size of Fast Fourier Transform
frameLengthMs0.1Length of frames signal is divided into before FFT is applied (given in milliseconds)
frameStepMs0.005Size of steps forward each frame takes (if less than frameLengthMs then frames overlap)
errorHandler-An error handling function which will be called if loading the wav file fails

As well as the params object, the draw function accepts a callback function.

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago