Coder Social home page Coder Social logo

ffxsam / wavesurfer.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from katspaugh/wavesurfer.js

0.0 0.0 0.0 44.4 MB

Audio waveform player

Home Page: https://wavesurfer-js.org

License: BSD 3-Clause "New" or "Revised" License

Shell 0.19% JavaScript 21.92% TypeScript 74.50% HTML 3.39%

wavesurfer.js's Introduction

logo wavesurfer.js

npm

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.

waveform screenshot

Getting started

Install and import the package:

npm install --save wavesurfer.js
import 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',
})

To import one of the plugins, e.g. the Regions plugin:

import Regions from 'wavesurfer.js/dist/plugins/regions.js'

Or as a script tag that will export WaveSurfer.Regions:

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

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

See more examples.

API reference

See the wavesurfer.js documentation on our website:

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 timestmap on waveform hover

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.

v7 – a 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
Screenshot 2023-12-06 at 09 06 30

Upgrading from v6

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

Notable differences

  • 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

  • audioContext, closeAudioContext, audioScriptProcessor
  • autoCenterImmediatelyautoCenter is now always immediate unless the audio is playing
  • backgroundColor, hideCursor – this can be easily set via CSS
  • mediaType – you should instead pass an entire media element in the media option. Example.
  • partialRender – done by default
  • pixelRatiowindow.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.
  • drawingContextAttributes, maxCanvasWidth, forceDecode – removed to reduce code complexity
  • xhr - please use fetchParams instead
  • barMinHeight - the minimum bar height is now 1 pixel by default

Removed methods

  • getFilters, setFilter – see the Web Audio example
  • drawBuffer – to redraw the waveform, use setOptions instead and pass new rendering options
  • cancelAjax – you can pass an AbortSignal in fetchParams
  • skipForward, skipBackward, setPlayEnd – can be implemented using setTime(time)
  • exportPCM is replaced with exportPeaks that returns arrays of floats
  • 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

Does wavesurfer support large files? Since wavesurfer decodes audio entirely in the browser using Web Audio, large clips may fail to decode due to memory constraints. We recommend using pre-decoded peaks for large files (see this example). You can use a tool like bbc/audiowaveform to generate peaks.
What about streaming audio? Streaming audio is supported only with pre-decoded peaks and duration.
There is a mismatch between my audio and the waveform. How do I fix it? If you're using a VBR (variable bit rate) audio file, there might be a mismatch between the audio and the waveform. This can be fixed by converting your file to CBR (constant bit rate).

Alternatively, you can use the Web Audio shim which is more accurate.

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, first build the project:

yarn build

Then launch the tests:

yarn cypress

Feedback

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!

wavesurfer.js's People

Contributors

katspaugh avatar thijstriemstra avatar mspae avatar mwise avatar jabr avatar rgagnon24 avatar osheroff avatar fluffywaffles avatar entonbiba avatar marizuccara avatar panda-go-panda avatar chrisparton1991 avatar akreal avatar naomiaro avatar fzyukio avatar tf avatar agamemnus avatar sundayz avatar ffxsam avatar gintelllect avatar x-raym avatar binron avatar lorenzos avatar roboswank avatar lionelb avatar marcelblum avatar whenov avatar vikeen avatar nabiulin avatar n-st avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.