
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
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 = 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/...
})
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 datastart()
- Recreates the workers that compute the spectrogram on incoming datastart()
will automatically be called with the constructorclear()
- Triggers stop()
and resets all data and the time measuringexecutionTime(): number
- Returns the execution time in msStatic methods
colorize(colorMap): Function
- Returns colorization function for the amplitudes.maxApplitude(): number
- Returns the maximum applitude of a spectrogramminApplitude(): number
- Returns the minimum applitude of a spectrogramEvent | 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 |
The following window functions are implemented:
Square
Hamming
VonHann
(Hanning)Blackman
(default)BlackmanHarris
BlackmanNuttall
Bartlett
Only mono is supported at the moment.
FAQs
A clustered nods.js module to create spectrograms from pcm audio data
The npm package spectro receives a total of 3 weekly downloads. As such, spectro popularity was classified as not popular.
We found that spectro demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.