Peaks.js: Navigating Audio Waveforms Like a Pro

Posted by on 7 August 2023

In today's ever-growing digital world, audio processing has become a significant part of various industries such as music, film, and broadcasting. Handling and manipulating audio data can be complex. That's where Peaks.js comes into play.

What is Peaks.js?

Peaks.js is an open-source JavaScript library that enables web developers to create interactive, navigable waveforms of audio content. Born out of a collaboration between BBC R&D and Chris Finch, Peaks.js offers an impressive set of tools to visualize audio waveforms, making it a go-to library for many audio-centric applications.

Key Features:

  1. Waveform Visualization: Offers different views like waveform and spectrogram.
  2. Zooming and Scrolling: Users can zoom in/out and scroll to navigate the waveform.
  3. Segmentation and Point Markers: Define segments and point markers for annotation.
  4. Resizable: Automatically resizes based on the container's dimensions.
  5. Customizable: A highly customizable API that allows developers to modify the appearance.

Setting Up Peaks.js

Integration of Peaks.js into a project is quite simple. Here's a brief walkthrough:

1. Installation

You can install Peaks.js through npm:

npm install peaks.js
npm install --save konva@8.4.3
npm install --save waveform-data

NOTE: I specified a version for konva because as of this writing peaks.js doesn't like the current version of konva.

or include it from a CDN:

<script src=""></script>

2. Create a Peaks Instance

First, create an HTML5 <audio> element, then initialize Peaks.js:

var audioElement = document.getElementById('audio');
var peaksInstance = Peaks.init({
  container: document.getElementById('waveform-container'),
  mediaElement: audioElement

3. Customize Appearance

You can further customize Peaks.js to fit your application’s look and feel:

  container: document.getElementById('waveform-container'),
  mediaElement: audioElement,
  waveformBuilderOptions: {
    scale: 4
  zoomLevels: [512, 1024, 2048, 4096]

Real-life Use Cases

Peaks.js has been implemented in various scenarios:

  • Music Production Software: For navigating and editing audio files.
  • Audio Transcription Services: Assisting in annotating and transcribing spoken content.
  • Educational Platforms: Helping students visualize sound waves in physics or music studies.


Peaks.js is an indispensable library for anyone working with audio data in the browser. With its feature-rich toolkit, easy integration, and strong community support, it opens up new horizons for developers in the multimedia domain.

Whether you are building a professional audio editing software or a small tool for your personal project, Peaks.js provides the flexibility to cater to your needs. Explore more about Peaks.js and elevate your audio processing capabilities to a professional level.

The full documentation and examples can be found on the Peaks.js GitHub page. Happy coding!

Example project on GitHub

Tags: #javascript #react

Categories: #technology