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

waveform-generator-web

v0.0.4

Published

Client-side waveform generator

Downloads

109

Readme

WaveformGenerator

WaveformGenerator.js is a simple and small library for JavaScript which generates waveform from audio, either as PNG or SVG data.

You can change the color of the waveform, the width of bars, width of gaps between bars and the bars alignment.

Licensed under GNU GPL 3.0.

##Install

Grab the JavaScript file from the dist directory.

WaveformGenerator can also be inststalled with Bower:

bower install waveform-generator

##Usage

Create a waveform by creating a new instance of WaveformGenerator and passing an array buffer and a settings object. The WaveformGenerator will return a Promise with the URL to the generated waveform.

###Creating a waveform

You can create a new generator without any settings. The generator will then use the default settings which is a normal waveform aligned in the center with a #bada55 (badass) color.

new WaveformGenerator(arrayBuffer).then(function(pngWaveformUrl) {
	document.querySelector('#awesome-png-waveform').src = pngWaveformUrl;
});

To generate waveform with your own settings, put an object with the settings in the second argument of the WaveformGenerator, right after the arrayBuffer.

new WaveformGenerator(arrayBuffer, myAwesomeSettings).then(function(pngWaveformUrl) {
	document.querySelector('#awesome-png-waveform').src = pngWaveformUrl;
});

You can change he following settings in the WaveformGenerator by passing your own settings object.

|Setting|Explanation| |--- | ---| |waveformWidth|Width of the final image (Default: 500)| |waveformHeight|Height of the final image (Default: 80)| |waveformColor|Color of the waveform (Default: #bada55)| |barAlign|Alignment of the bars in the waveform. Can be either 'center', 'bottom' or 'top' (Default: 'center')| |barWidth|Width of the bars. (Default: 1)| |barGap|Width of the gaps between bars. Float value. Gap formula is barWidth *= abs(1 - gap) (Default: 0)| |drawMode|Controls output format. Can be 'png' or 'svg'. (Default 'png')|

##Example usage

####HTML

<input type="file">
<img id="png-waveform" alt="PNG Waveform Destination">
<img id="svg-waveform" alt="SVG Waveform Destination">

####JavaScript

document.querySelector('input').addEventListener('change', function(e) {
	// Create file reader to read the file as an ArrayBuffer
	var reader = new FileReader();

	// Tell the reader to read the file as an ArrayBuffer
	reader.readAsArrayBuffer(e.target.files[0]);

	// When the reader has loaded the read the file as an ArrayBuffer
	reader.onload = function(event) {
		var arrayBuffer = event.target.result;

		var pngSettings = {drawMode: 'png'}; // 'png' is default. Can be omitted.
		var svgSettings = {drawMode: 'svg'};

		new WaveformGenerator(arrayBuffer, pngSettings).then(function(pngWaveformUrl) {
			document.querySelector('#png-waveform').src = pngWaveformUrl;
		});

		new WaveformGenerator(arrayBuffer, svgSettings).then(function(svgWaveformUrl) {
			document.querySelector('#svg-waveform').src = svgWaveformUrl;
		});
	};
}, false);
```

##Demo

###Using local media

[codepen.io/enjikaka/full/azyvae](http://codepen.io/enjikaka/full/azyvae)

###Using Spotify

[codepen.io/enjikaka/full/DrFEk](http://codepen.io/enjikaka/full/DrFEk)

##Dependencies

This demo uses ```Object.assign``` and JavaScript Promises.
Here are polyfills:

- [Object.assign()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
- [es6-promise](https://github.com/jakearchibald/es6-promise)