wavesurfer.jswavesurfer.js v7 beta is a TypeScript rewrite of wavesurfer.js that brings several improvements:
ℹ️ 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:
<script type="module">
  import WaveSurfer from 'https://unpkg.com/wavesurfer.js@beta'
  const wavesurfer = WaveSurfer.create({
    container: '#waveform',
    waveColor: '#4F4A85',
    progressColor: '#383351',
    url: '/audio.mp3',
  })
</script>
Or, as a UMD script tag which exports the library as a global WaveSurfer variable:
<script type="text/javascript" src="https://unpkg.com/wavesurfer.js@beta/dist/wavesurfer.min.cjs"></script>
To import one of the plugins, e.g. the Timeline plugin:
import Timeline from 'wavesurfer.js/dist/plugins/timeline.js'
// or with a CDN:
import Timeline from 'https://unpkg.com/wavesurfer.js@beta/dist/plugins/timeline.js'
// or as a script tag
<script type="text/javascript" src="https://unpkg.com/wavesurfer.js@beta/dist/plugins/timeline.min.cjs"></script>
TypeScript types are included in the package, so there's no need to install @types/wavesurfer.js.
See more examples.
See the documentation on wavesurfer.js methods, options and events on our website.
The "official" plugins have been completely rewritten and enhanced:
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 with CSS via 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.
Most options, events, and methods are similar to those in previous versions.
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.startTime.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 the media 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 if minPxPerSec is set to a higher valueskipLength – there's no skipForward and skipBackward methods anymoresplitChannelsOptions – 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 complexitybarMinHeight - the minimum bar height is now 1 pixel by defaultgetFilters, setFilter – as there's no Web Audio "backend"drawBuffer – to redraw the waveform, use setOptions instead and pass new rendering optionscancelAjax – ajax is replaced by fetchloadBlob – use URL.createObjectURL() to convert a blob to a URL and call load(url) insteadskipForward, skipBackward, setPlayEnd – can be implemented using setTime(time)exportPCM is renamed to getDecodedData and doesn't take any paramstoggleMute 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.
Have a question about integrating wavesurfer.js on your website? Feel free to ask in our Discussions forum.
To get started with development, follow these steps:
yarn
yarn start
This command will open http://localhost:9090 in your browser with live reload, allowing you to see the changes as you develop.
The tests are written in the Cypress framework. They are a mix of e2e and visual regression tests.
To run the test suite locally, first build the project:
yarn build
Then launch the tests:
yarn cypress
We appreciate your feedback and contributions! Join the conversation and share your thoughts here: https://github.com/wavesurfer-js/wavesurfer.js/discussions/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!
Generated using TypeDoc