wavesurfer.js + Spectrogram

wavesurfer.js Spectrogram Plugin

Adds a simple spectrogram to your wavesurfer.js instances.

Quick Start

var wavesurfer = WaveSurfer.create({
    // your options here
    plugins: [
        WaveSurfer.spectrogram.create{
            wavesurfer: wavesurfer,
            container: "#wave-spectrogram",
            labels: true
        })
    ]
});

wavesurfer.load('../media/demo.wav');


Options

  • wavesurfer - required - a WaveSurfer instance.
  • container - required - the element in which to place the spectrogram, or a CSS selector to find it.
  • fftSamples - number of FFT samples (512 by default). Number of spectral lines and height of the spectrogram will be a half of this parameter.
  • frequenciesDataUrl - URL to load spectral data from.
  • labels - Whether or not to display frequency labels.
  • colorMap - Specifies the colormap to be used when rendering the spectrogram.

Generating a colorMap

The colormap npm can be used to generate a colormap. In this example, the colormap has been saved to a json file and is retrieved by the client before initializing the spectrogram.

const colormap = require('colormap');
const colors = colormap({
    colormap: 'hot',
    nshades: 256,
    format: 'float'
});
const fs = require('fs');
fs.writeFile('hot-colormap.json', JSON.stringify(colors));                        

Fork me on GitHub