@rewbs/wavesurfer.js
v8.0.0-beta.1
Published
Audio waveform player - temporary fork for experiments
Maintainers
Readme
wavesurfer.js
Wavesurfer.js is an interactive waveform rendering and audio playback library, perfect for web applications. It leverages modern web technologies to provide a robust and visually engaging audio experience.
Gold sponsor 💖 Closed Caption Creator
🎉 v8 Beta Available! Try the new reactive streams and state management features. Learn more →
Table of contents
- Getting started
- What's new in v8
- API reference
- Plugins
- CSS styling
- Frequent questions
- Contributing
- Tests
- Feedback
Getting started
Install and import the package:
npm install wavesurfer.jsimport WaveSurfer from 'wavesurfer.js'Alternatively, insert a UMD script tag which exports the library as a global WaveSurfer variable:
<script src="https://unpkg.com/wavesurfer.js@7"></script>Create a wavesurfer instance and pass various options:
const wavesurfer = WaveSurfer.create({
container: '#waveform',
waveColor: '#4F4A85',
progressColor: '#383351',
url: '/audio.mp3',
})
// Subscribe to events
wavesurfer.on('ready', () => {
wavesurfer.play()
})TypeScript types are included in the package, so there's no need to install @types/wavesurfer.js.
See more examples.
What's new in v8
v8 is 100% backward compatible – your existing code works without changes!
Reactive Event Streams
Subscribe to events with powerful stream operators:
// Debounce time updates for better performance
wavesurfer.getEventStream('timeupdate')
.debounce(100)
.subscribe(time => {
updateUI(time)
})
// Chain multiple operators
wavesurfer.getEventStream('timeupdate')
.filter(() => wavesurfer.isPlaying())
.throttle(1000)
.map(time => Math.floor(time))
.distinct()
.subscribe(time => {
console.log(`Second ${time}`)
})State Management
React to application state changes:
// Subscribe to playing state
wavesurfer.state
.select(s => s.playback.isPlaying)
.subscribe(isPlaying => {
button.textContent = isPlaying ? 'Pause' : 'Play'
})
// Combine multiple state values
wavesurfer.state
.selectMany(
s => s.playback.currentTime,
s => s.audio.duration
)
.subscribe(([time, duration]) => {
const progress = (time / duration) * 100
updateProgressBar(progress)
})Available Stream Operators
map(fn)– Transform valuesfilter(fn)– Filter valuesdebounce(ms)– Debounce updatesthrottle(ms)– Throttle updatesdistinct()– Only emit unique valuestake(n)– Take first n emissionstakeUntil(notifier)– Take until another stream emits
Try the beta:
npm install wavesurfer.js@betaLearn more:
- Beta Announcement – What's new and how to try it
- User Guide – Complete v8 documentation
- Migration Guide – Upgrading from v7 (if you want to)
API reference
See the wavesurfer.js documentation on our website:
For v8 features, see the v8 API Reference.
Plugins
We maintain a number of official plugins that add various extra features:
- 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 (written by @akreal)
- Hover – shows a vertical line and timestamp on waveform hover
To import a plugin (v7):
import Regions from 'wavesurfer.js/dist/plugins/regions.esm.js'Or as a script tag:
<script src="https://unpkg.com/wavesurfer.js@7/dist/plugins/regions.min.js"></script>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 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 to play around with styling.
Questions
Have a question about integrating wavesurfer.js on your website? Feel free to ask in our Discussions forum.
However, please keep in mind that this forum is dedicated to wavesurfer-specific questions. If you're new to JavaScript and need help with the general basics like importing NPM modules, please consider asking ChatGPT or StackOverflow first.
FAQ
Contributing
We welcome contributions! Here's how to get started:
Development Setup
- Install dependencies:
npm install- Start the development server:
npm run devThis command will start the Vite dev server with live reload at http://localhost:5173.
- Run tests:
npm testPlugin Development
Interested in building plugins for wavesurfer.js? Check out our comprehensive guides:
- Plugin Development Guide – Complete guide to building plugins
- Contributing Guide – Development workflow and guidelines
- API Reference – Full API documentation
Project Structure
wavesurfer.js/
├── src/
│ ├── streams/ # Reactive streams
│ ├── state/ # State management
│ ├── core/ # Pure functions
│ ├── plugins/ # Plugin system
│ └── ... # Core components
├── examples/ # Example files
└── docs/ # DocumentationTests
The project uses Vitest for unit tests and Cypress for e2e/visual regression tests.
Running Unit Tests
npm testRunning E2E Tests
First build the project:
npm run buildThen launch the tests:
npm run cypressFeedback
We appreciate your feedback and contributions!
If you encounter any issues or have suggestions for improvements, please don't hesitate to post in our forum.
We hope you enjoy using wavesurfer.js and look forward to hearing about your experiences with the library!
License: BSD-3-Clause
Made with ♥ by the wavesurfer.js community
