A clustered nods.js module to create spectrograms from pcm audio data
Spectro can be installed via npm:
npm install spectro
By using a cluster of workers to process the computational expensive stuff the execution time can be decreased dramatically. The spectrogram class is a writable stream where the data can be piped into. So the easiest way to use it is to pipe a wav file into it:
const Spectro =const fs =var sp =var audioFile = fs // Note: The first 44 bytes are the wav-header// The file stream can simply be piped into the Spectro instanceaudioFile// Check when the file stream completedvar fileRead = falseaudioFile// The data event can be used to work with recently processed data from the workersspectrospectro
The constructor can be called with an options object with these options:
||16||Bits per second of the audio|
||1||The channels count of the audio (allowed: 1)|
||1024||The window size being used for the dct|
||'Hamming'||The window function to use|
||0||The overlap size:
||<CPU cores>||How many workers should be created to process the data|
stop()- Stops all workers from further processing of incoming data
start()- Recreates the workers that compute the spectrogram on incoming data
start()will automatically be called with the constructor
stop()and resets all data and the time measuring
executionTime(): number- Returns the execution time in ms
colorize(colorMap): Function- Returns colorization function for the amplitudes.
maxApplitude(): number- Returns the maximum applitude of a spectrogram
minApplitude(): number- Returns the minimum applitude of a spectrogram
||When a new frame was processed.
||When all possible windows where processed. This event can be called several times before the complete audio has been piped into the Spectro instance.
The following window functions are implemented:
Only mono is supported at the moment.