npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

spectro

v1.0.1

Published

A clustered nods.js module to create spectrograms from pcm audio data

Downloads

25

Readme

A clustered nods.js module to create spectrograms from pcm audio data

Install

Spectro can be installed via npm:

npm install spectro

Usage

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 = require('spectro')
const fs = require('fs')

var sp = new Spectro()
var audioFile = fs.createReadStream('file.wav', {start: 44}) // Note: The first 44 bytes are the wav-header

// The file stream can simply be piped into the Spectro instance
audioFile.pipe(sp)

// Check when the file stream completed
var fileRead = false
audioFile.on('end', () => fileRead = true)

// The data event can be used to work with recently processed data from the workers
spectro.on('data', (err, frame) => {
    if (err) console.error('Spectro data event has an error', err)
    // frame contains an index of the processed frame and a data section with the processed data
})

spectro.on('end', (err, data) => {
    if (err) return console.error('Spectro ended with an error', err)
    // The 'end' event always fires when spectro has reached the end of the currently processable data
    // Therefore we should check if the file was read completely before using the data
    if (fileRead !== true) return

    // Stop spectro from waiting for data and stop all of it's workers
    spectro.stop()

	// The spectrogram can e.g. be drawn with third party modules such as pngjs
	// Examples therefor can be found in examples/...
})

Methods

Constructor

The constructor can be called with an options object with these options:

Option | Default | Description -----------|---------------|------------ bps | 16 | Bits per second of the audio channels | 1 | The channels count of the audio (allowed: 1) wSize | 1024 | The window size being used for the dct wFunc | 'Hamming' | The window function to use overlap | 0 | The overlap size: 0 <= overlap < 1 workers | <CPU cores> | How many workers should be created to process the data

Instance methods

  • stop() - Stops all workers from further processing of incoming data
  • start() - Recreates the workers that compute the spectrogram on incoming data
    Note: start() will automatically be called with the constructor
  • clear() - Triggers stop() and resets all data and the time measuring
  • executionTime(): number - Returns the execution time in ms

Static methods

  • 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

Events

Event | Parameters | Description -------|----------------|------------ data | err, frame | When a new frame was processed. frame has an index and a data array end | err, data | When all possible windows where processed. This event can be called several times before the complete audio has been piped into the Spectro instance. data is a two-dimensional array with the amplitudes

Window functions

The following window functions are implemented:

  • Square
  • Hamming
  • VonHann (Hanning)
  • Blackman (default)
  • BlackmanHarris
  • BlackmanNuttall
  • Bartlett

Limitations

Only mono is supported at the moment.