Navigable waveform built on Web Audio and Canvas
Clone or download
Farbenkollektiv and thijstriemstra fix removeOnAudioProcess for Safari
When using "WebAudio" in Safari the "audioprocess" event doesn't get fired anymore once you pause/play the current song or load a new one into your wavesurfer object preventing the following piece of code to be executed:

this.backend.on('audioprocess', time => {
    this.drawer.progress(this.backend.getPlayedPercents());
    this.fireEvent('audioprocess', time);
});

This commit fixes the bug, so it is not needed anymore to use "MediaElement" on Safari as a workaround (which has its own drawbacks).
Latest commit 799faba Jan 14, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Next: Ports from master and bugfixes (#1035) Mar 8, 2017
assets add logo images (#1420) Aug 19, 2018
build-config use short date format in copyright header (#1479) Oct 4, 2018
example examples: add syntax highlighting (#1522) Dec 3, 2018
spec Fix computing peaks when buffer is not set (#1530) Dec 16, 2018
src fix removeOnAudioProcess for Safari Jan 14, 2019
.babelrc bump version: 2.1.0 (#1470) Oct 1, 2018
.editorconfig Es6 (#863) Nov 23, 2016
.esdoc.json Fix #1241: Updated dependencies & refactored build config into sepera… Nov 7, 2017
.eslintrc.js make WaveSurfer.VERSION available (#1431) Aug 20, 2018
.gitignore plugins: add showTime option to cursor plugin (#1511) Nov 17, 2018
.htmlhintrc update dev dependencies and add prepublish command (#1274) Dec 18, 2017
.npmignore Next: Ports from master and bugfixes (#1035) Mar 8, 2017
.prettierrc Fix #1241: Updated dependencies & refactored build config into sepera… Nov 7, 2017
.travis.yml update dev dependencies: upgrade babel (#1469) Sep 28, 2018
CHANGES.md Release 2.1.2 (#1545) Jan 7, 2019
CNAME Update CNAME Aug 6, 2015
LICENSE Release 2.1.2 (#1545) Jan 7, 2019
README.md Release 2.1.2 (#1545) Jan 7, 2019
UPGRADE.md Release 2.1.2 (#1545) Jan 7, 2019
appveyor.yml update dev dependencies: upgrade babel (#1469) Sep 28, 2018
bower.json Release 2.1.2 (#1545) Jan 7, 2019
karma.conf.js update dev dependencies: upgrade babel (#1469) Sep 28, 2018
package.json Release 2.1.2 (#1545) Jan 7, 2019

README.md

wavesurfer.js

npm version npm Join the chat at https://gitter.im/katspaugh/wavesurfer.js

Interactive navigable audio visualization using Web Audio and Canvas.

Screenshot

See a tutorial and examples on wavesurfer-js.org.

Browser support

wavesurfer.js works only in modern browsers supporting Web Audio.

It will fallback to Audio Element in other browsers (without graphics). You can also try wavesurfer.swf which is a Flash-based fallback.

FAQ

Can the audio start playing before the waveform is drawn?

Yes, if you use the backend: 'MediaElement' option. See here: https://wavesurfer-js.org/example/audio-element/. The audio will start playing as you press play. A thin line will be displayed until the whole audio file is downloaded and decoded to draw the waveform.

Can drawing be done as file loads?

No. Web Audio needs the whole file to decode it in the browser. You can however load pre-decoded waveform data to draw the waveform immediately. See here: https://wavesurfer-js.org/example/audio-element/ (the "Pre-recoded Peaks" section).

API in examples

Choose a container:

<div id="waveform"></div>

Create an instance, passing the container selector and options:

var wavesurfer = WaveSurfer.create({
    container: '#waveform',
    waveColor: 'violet',
    progressColor: 'purple'
});

Subscribe to some events:

wavesurfer.on('ready', function () {
    wavesurfer.play();
});

Load an audio file from a URL:

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

Documentation

See the documentation on all available methods, options and events on the homepage.

Upgrade

See the upgrade document if you're upgrading from a previous version of wavesurfer.js.

Using with a module bundler

Wavesurfer can be used with a module system like this:

// import
import WaveSurfer from 'wavesurfer.js';

// commonjs/requirejs
var WaveSurfer = require('wavesurfer.js');

// amd
define(['WaveSurfer'], function(WaveSurfer) {
  // ... code
});

Related projects

For a list of projects using wavesurfer.js, check out the projects page.

Development

npm version npm Build Status Coverage Status

Install development dependencies:

npm install

Development tasks automatically rebuild certain parts of the library when files are changed (start – wavesurfer, start:plugins – plugins). Start a dev task and go to localhost:8080/example/ to test the current build.

Start development server for core library:

npm run start

Start development server for plugins:

npm run start:plugins

Build all the files. (generated files are placed in the dist directory.)

npm run build

Running tests only:

npm run test

Build documentation with esdoc (generated files are placed in the doc directory.)

npm run doc

Editing documentation

The homepage and documentation files are maintained in the gh-pages branch. Contributions to the documentation are especially welcome.

Credits

Initial idea by Alex Khokhulin. Many thanks to the awesome contributors!

License

License

This work is licensed under a BSD 3-Clause License.