• Stars
    star
    8,703
  • Rank 4,190 (Top 0.09 %)
  • Language
    TypeScript
  • License
    BSD 3-Clause "New...
  • Created over 12 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Audio waveform player

logo wavesurfer.js

npm

New TypeScript version

wavesurfer.js v7 beta is a TypeScript rewrite of wavesurfer.js that brings several improvements:

  • Typed API for better development experience
  • Enhanced decoding and rendering performance
  • New and improved plugins
waveform screenshot

โ„น๏ธ Looking for the old stable version? V6 is here: https://github.com/katspaugh/wavesurfer.js/tree/v6


Try it out:

npm install --save wavesurfer.js@beta
import WaveSurfer from 'wavesurfer.js'

Alternatively, import it from a CDN as a ES6 module directly in the browser:

<script type="module">
  import WaveSurfer from 'https://unpkg.com/wavesurfer.js@beta'

  const wavesurfer = WaveSurfer.create({ ... })
</script>

Or, as a UMD script tag which exports the library as a global WaveSurfer variable:

<script src="https://unpkg.com/wavesurfer.js@beta/dist/wavesurfer.min.js"></script>

To import a plugin, e.g. the Timeline plugin:

import Timeline from 'https://unpkg.com/wavesurfer.js@beta/dist/plugins/timeline.js'

TypeScript types are included in the package, so there's no need to install @types/wavesurfer.js.

See more examples.

Documentation

See the documentation on wavesurfer.js methods, options and events on our website.

Plugins

The "official" plugins have been completely rewritten and enhanced:

  • Regions โ€“ visual overlays and markers for regions of audio
  • Timeline โ€“ displays notches and time labels below the waveform
  • Minimap โ€“ a small waveform that serves as a scrollbar for the main waveform
  • Envelope โ€“ a graphical interface to add fade-in and -out effects and control volume
  • Record โ€“ records audio from the microphone and renders a waveform
  • Spectrogram โ€“ visualization of an audio frequency spectrum

CSS styling

wavesurfer.js v7 is rendered into a Shadow DOM tree. This isolates its CSS from the rest of the web page. However, it's still possible to style various wavesurfer.js elements via CSS using the ::part() pseudo-selector. For example:

#waveform ::part(cursor):before {
  content: '๐Ÿ„';
}
#waveform ::part(region) {
  font-family: fantasy;
}

You can see which elements you can style in the DOM inspector โ€“ they will have a part attribute. See this example for play around with styling.

Upgrading from v6

Most options, events, and methods are similar to those in previous versions.

Notable differences

  • The backend option is removed โ€“ HTML5 audio (or video) is the only playback mechanism. However, you can still connect wavesurfer to Web Audio via MediaElementSourceNode. See this example.
  • The Markers plugin is removed โ€“ use the Regions plugin with just a startTime.
  • No Microphone plugn โ€“ superseded by the new Record plugin with more features.
  • No Cursor and Playhead plugins yet โ€“ to be done.

Removed options

  • backend, audioContext, closeAudioContext', 'audioScriptProcessor โ€“ there's no Web Audio backend, so no AudioContext
  • autoCenterImmediately โ€“ autoCenter is now always immediate unless the audio is playing
  • backgroundColor, hideCursor โ€“ this can be easily set via CSS
  • mediaType, mediaControls โ€“ you should instead pass an entire media element in the media option. Example.
  • normalize โ€“ peaks are normalized to -1..1 by default
  • partialRender โ€“ done by default
  • pixelRatio โ€“ window.devicePixelRatio is used by default
  • renderer โ€“ there's just one renderer for now, so no need for this option
  • responsive โ€“ responsiveness is enabled by default
  • scrollParent โ€“ the container will scroll if minPxPerSec is set to a higher value
  • skipLength โ€“ there's no skipForward and skipBackward methods anymore
  • splitChannelsOptions โ€“ you should now use splitChannels to pass the channel options. Pass height: 0 to hide a channel. See this example.
  • xhr, drawingContextAttributes, maxCanvasWidth, forceDecode โ€“ removed to reduce code complexity

Removed methods

  • getFilters, setFilter โ€“ as there's no Web Audio "backend"
  • drawBuffer โ€“ to redraw the waveform, use setOptions instead and pass new rendering options
  • cancelAjax โ€“ ajax is replaced by fetch
  • loadBlob โ€“ use URL.createObjectURL() to convert a blob to a URL and call load(url) instead
  • skipForward, skipBackward, setPlayEnd โ€“ can be implemented using setTime(time)
  • exportPCM is renamed to getDecodedData and doesn't take any params
  • toggleMute is now called setMuted(true | false)
  • setHeight, setWaveColor, setCursorColor, etc. โ€“ use setOptions with the corresponding params instead. E.g., wavesurfer.setOptions({ height: 300, waveColor: '#abc' })

See the complete documentation of the new API.

Questions

Have a question about integrating wavesurfer.js on your website? Feel free to ask in our Discussions forum.

FAQ

  • Q: Does wavesurfer support large files?
  • A: Since wavesurfer decodes audio entirely in the browser, large files may fail to decode due to memory constrains. We recommend using pre-decoded peaks for large files (see this example). You can use a tool like bbc/audiowaveform to generate peaks.

Development

To get started with development, follow these steps:

  1. Install dev dependencies:
yarn
  1. Start the TypeScript compiler in watch mode and launch an HTTP server:
yarn start

This command will open http://localhost:9090 in your browser with live reload, allowing you to see the changes as you develop.

Tests

The tests are written in the Cypress framework. They are a mix of e2e and visual regression tests. To run the test suite locally:

yarn cypress

Feedback

We appreciate your feedback and contributions! Join the conversation and share your thoughts here: #2789

If you encounter any issues or have suggestions for improvements, please don't hesitate to open an issue or submit a pull request on the GitHub repository.

We hope you enjoy using wavesurfer.ts and look forward to hearing about your experiences with the library!

More Repositories

1

videobook

Subtitles as a language learning tool
TypeScript
61
star
2

kindle-flashcards

Scripts to extract Kindle dictionary look-ups into CSV
Shell
59
star
3

youtube-flashcards

Extract screenshots & audio clips from YouTube videos into Anki cards
Shell
58
star
4

fluentcards

Flashcards from dictionary look-ups
JavaScript
56
star
5

whiteboard

Real-time multiplayer whiteboard with multitouch support.
JavaScript
54
star
6

arduino-modular-synth

Arduino sketches for the modular synthesizer
C++
53
star
7

ido-at-point

ido-at-point
Emacs Lisp
49
star
8

launchpad-seq

Novation Launchpad sequencer
JavaScript
31
star
9

tj-mode

Highlight JavaScript with Tern
JavaScript
30
star
10

fluentcards-extension

Chrome extension to look up words in a dictionary and save as flashcards.
JavaScript
20
star
11

fluentcards-grammar

Grammar exercises generated from books & subtitles
JavaScript
20
star
12

interlinear.io

Read books with interlinear translation
JavaScript
16
star
13

canvas-bucket

Flood fill for Canvas
JavaScript
15
star
14

kanji-press

A kanji-based word game
JavaScript
14
star
15

kuromoji.el

้ป’ๆ–‡ๅญ—ใฎEmacsใƒ—ใƒฉใ‚ฐใ‚คใƒณใงใ™
Emacs Lisp
12
star
16

kuromoji-gloss

Automated glossing of Japanese texts based on the Kuromoji tokenizer
JavaScript
12
star
17

wooky.el

Eval-defun for JavaScript in Chrome
Emacs Lisp
11
star
18

wavesurfer.ts

A new version of wavesurfer.js written in TypeScript
TypeScript
8
star
19

lambda.quest

Lambda Quest
JavaScript
8
star
20

.emacs.d

Totally.
Emacs Lisp
6
star
21

speak-api

Espeak-based serverless API for IPA transcriptions
JavaScript
4
star
22

subflix-extension

Enhanced subtitles on Netflix
JavaScript
3
star
23

seal-adventure

A scrolling obstacle game
C
2
star
24

xerox-nlp-client

JavaScript
2
star
25

wavesurfer-react

React component for wavesurfer.js
TypeScript
1
star
26

3ds-life

Game of Life on 3DS
Makefile
1
star
27

safe-nfts

Buy NFTs from the comfort of your Safe
TypeScript
1
star
28

language-roulette-api

JavaScript
1
star
29

ng-gem-puzzle

A match-three puzzle game in CoffeeScript and AngularJS
CSS
1
star
30

parselmouth

A game of snake in HTML5 Canvas.
JavaScript
1
star
31

safe-copycat

Copy a Safe to another chain
TypeScript
1
star
32

language-roulette

JavaScript
1
star