New TypeScript version
wavesurfer.js v7 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
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 viaMediaElementSourceNode
. See this example. - The Markers plugin is removed – you should use the Regions plugin with just a
startTime
. - No Microphone plugin – superseded by the new Record plugin with more features.
- The Cursor plugin is replaced by the Hover plugin.
Removed options
backend
,audioContext
,closeAudioContext
,audioScriptProcessor
– there's no Web Audio backend, so no AudioContextautoCenterImmediately
–autoCenter
is now always immediate unless the audio is playingbackgroundColor
,hideCursor
– this can be easily set via CSSmediaType
,mediaControls
– you should instead pass an entire media element in themedia
option. Example.partialRender
– done by defaultpixelRatio
–window.devicePixelRatio
is used by defaultrenderer
– there's just one renderer for now, so no need for this optionresponsive
– responsiveness is enabled by defaultscrollParent
– the container will scroll ifminPxPerSec
is set to a higher valueskipLength
– there's noskipForward
andskipBackward
methods anymoresplitChannelsOptions
– you should now usesplitChannels
to pass the channel options. Passheight: 0
to hide a channel. See this example.drawingContextAttributes
,maxCanvasWidth
,forceDecode
– removed to reduce code complexityxhr
- please usefetchParams
insteadbarMinHeight
- the minimum bar height is now 1 pixel by default
Removed methods
getFilters
,setFilter
– as there's no Web Audio "backend"drawBuffer
– to redraw the waveform, usesetOptions
instead and pass new rendering optionscancelAjax
– you can pass an AbortSignal infetchParams
loadBlob
– useURL.createObjectURL()
to convert a blob to a URL and callload(url)
insteadskipForward
,skipBackward
,setPlayEnd
– can be implemented usingsetTime(time)
exportPCM
is replaced withgetDecodedData
that returns a decoded audio buffertoggleMute
is now calledsetMuted(true | false)
setHeight
,setWaveColor
,setCursorColor
, etc. – usesetOptions
with the corresponding params instead. E.g.,wavesurfer.setOptions({ height: 300, waveColor: '#abc' })
See the complete documentation of the new API.