Audio visualizer library for javascript. Create dynamic animations that react to an audio file or audio stream.

Overview

Wave.js

Audio visualizer library for javascript.

Installation

Install With CDN

<script src="https://cdn.jsdelivr.net/gh/foobar404/wave.js/dist/bundle.js"></script>

Or NPM

npm i @foobar404/wave

Setup

If your using NPM:

import {Wave} from "@foobar404/wave";

Usage

let audioElement = document.querySelector("#audioElmId");
let canvasElement = document.querySelector("#canvasElmId");
let wave = new Wave(audioElement, canvasElement);

// Simple example: add an animation
wave.addAnimation(new wave.animations.Wave());

// Intermediate example: add an animation with options
wave.addAnimation(new wave.animations.Wave({
    lineWidth: 10,
    lineColor: "red",
    count: 20
}));

// Expert example: add multiple animations with options
wave.addAnimation(new wave.animations.Square({
    count: 50,
    diamater: 300
}));

wave.addAnimation(new wave.animations.Glob({
    fillColor: {gradient: ["red","blue","green"], rotate: 45},
    lineWidth: 10,
    lineColor: "#fff"
}));

// The animations will start playing when the provided audio element is played

// 'wave.animations' is an object with all possible animations on it.

// Each animation is a class, so you have to new-up each animation when passed to 'addAnimation'

Contributing

  1. Fork Wave.js repo.
  2. Clone to your local computer.
  3. Run "npm i" in the root folder to install dependencies.
  4. Run "npm start" to start the code watcher.
  5. Open the src folder and make a change to one of the src files.
  6. Push to remote branch and create a pull request to the Wave.js main branch.

License

MIT

Comments
  • Fixing Safari Bugs

    Fixing Safari Bugs

    • Unexpected token issue caused by Safari, as class variables should be declared in constructor
    • Fixing Safari Bug for not finding audio context with fallback to webkitAudioContext
    opened by imCorfitz 30
  • Allowing to externalise sources storage to be able to create / destroy / create again the player

    Allowing to externalise sources storage to be able to create / destroy / create again the player

    When using one-page apps which will render the DOM depending on the current route, if the current route has to render the Wave.js visualizer, then it has to be destroyed then created again, it will result in the following error :

    bundle.cjs.js:13 Uncaught DOMException: Failed to execute 'createMediaElementSource' on 'AudioContext': HTMLMediaElement already connected previously to a different MediaElementSourceNode.

    This error occurs because the sources are being stored in the class itself which is destroyed and created again :

    this.sources[element.toString()] = {
                    "audioCtx": audioCtx,
                    "analyser": analyser,
                    "source": source
                };
    

    For classic webpages there won't be any problem since the visualizer will normally not be destroyed, but for all modern frameworks like React, Angular, VueJS, etc.. it will fail.

    I think we should allow a way to override the default sources storage if needed by passing a setSource method which will be used instead of all such cases

    this.sources[element.toString()] = {
                    "audioCtx": audioCtx,
                    "analyser": analyser,
                    "source": source
                };
    

    And a getSource method which will be be used as a getter in such cases :

    this.sources[element.toString()].animation

    I created a simple working fiddle : http://jsfiddle.net/ma3zu8n5/1/

    opened by korbav 19
  • Is there a playFile instead of playStream?

    Is there a playFile instead of playStream?

    Uncaught TypeError: this.current_stream.loop is not a function at Wave.playStream (bundle.iife.js:266)

    It's a small file. I am using codepen to learn this. I am using fromFile - so do I need playStream()?

    Here's the link to my pen: https://codepen.io/KoniKodes/pen/mdmEpMV

    opened by KoniKodes 17
  • Not showing up on iPhone safari

    Not showing up on iPhone safari

    Hi, first off what an amazing script you got here. Great job on this!

    I was able to successfully display the waves in firefox and chrome, desktop and android devices. But for some reason the waves do not appear on safari iPhone.

    I'm running an icecast server and displaying the waves via audio tag like so..

    <audio id="radio" crossorigin="anonymous">
           <source src="https://mystation.com/stream" type="audio/mpeg" />
           <source src="https://mystation.com/stream.ogg" type="audio/ogg" />
    </audio>
    

    and I am triggering the playing of the audio like this..

    var player = document.getElementById('radio');
    player.load();
    player.play();
    

    I have a canvas html element on the page like this.. <canvas id="wavesCanvas" height="250" width="500"></canvas>

    The waves is set like this..

    var wave = new Wave();
    var options = {type:"shockwave", colors: ["#6c2a99", "#e01919", "#b4751d"]};
    wave.fromElement("radio","wavesCanvas",options);
    

    The audio plays on all devices including safari on iPhone. The wavesjs shows on all browsers except safari on iPhone. I should note that I have not tested on safari on a mac because I do not own a mac at the moment.

    Is this a known issue? Is there any special configurations needed for this to work on safari?

    opened by 9thwall 14
  • Package does not have Angular ng-add support

    Package does not have Angular ng-add support

    Wave.js doesn't seem to have ng-add support for Angular. This is making it difficult to use with Angular, especially since this package can't be recognized by Angular even after an NPM install.

    Error: src/app/components/posts/record/record.component.ts:7:20 - error TS7016: Could not find a declaration file for module '@foobar404/wave'. '/home/electrenator/Documents/Code/[redacted]/front-end/node_modules/@foobar404/wave/dist/bundle.cjs.js' implicitly has an 'any' type.
      Try `npm i --save-dev @types/foobar404__wave` if it exists or add a new declaration (.d.ts) file containing `declare module '@foobar404/wave';`
    
    7 import {Wave} from '@foobar404/wave';
                         ~~~~~~~~~~~~~~~~~
    

    I installed this package via the Angular CLI. This yields the same result as installing it via NPM. My install log:

    $ ng add @foobar404/wave
    ℹ Using package manager: npm
    ✔ Found compatible package version: @foobar404/[email protected].
    ✔ Package information loaded.
    
    The package @foobar404/[email protected] will be installed and executed.
    Would you like to proceed? Yes
    ✔ Package successfully installed.
    The package that you are trying to add does not support schematics. You can try using a different version of the package or contact the package author to add ng-add support.
    

    Currently I can't figure out how I can still use this package within my project. It would be nice if I would be able too :)

    Software versions

    Angular CLI: 12.2.13 Node: 12.21.0 Package Manager: npm 8.1.3 OS: linux x64 typescript: 4.3.5

    opened by Electrenator 7
  • MediaStream with multiple tracks

    MediaStream with multiple tracks

    hi, first. you did a great work.

    am trying to visualize stream with multiple tracks, but visuals are only based on one track (the first track in the stream ) am new to web audio api. i would really appreciate your help.

    opened by pauzha-lab 5
  • IWaveOptions types and density (trying to reproduce shockwave)

    IWaveOptions types and density (trying to reproduce shockwave)

    (2.0 - I just upgraded today)

    I'm trying to program some pre-sets for wave options and frequencies, and finding that IWaveOptions (and its enum for frequencyBand) are hidden away, meaning I have to go through an any or do hacks like frequencyBand: f as "base" | "lows" | "mids" | "highs" to get it to work. I'm trying to reconstruct what was "shockwave" in version 1 (3 frequency waves, each a different color).

    Also, Wave (the animation) is kind over-powered when not frequency-split. I find that on a small canvas, it is often at 100% and so isn't really a very interesting visualization.

    opened by acroyear 4
  • v2.0 - changes to Wave types

    v2.0 - changes to Wave types

    Hello, I've been using v1.x version of your lib and I was able to make effect like on attached image with Flower type.

    flower_old

    I wanted to migrate to v 2.0, but effect of flower is completely different. Shine is kind of looking similiar, but:

    1. The lines go only outside of diameter
    2. When I slide the volume to max, lines are too big and I couldn't fix it with any options

    This is old Flower with maximum volume:

    old_flower_max

    This is new Shine with maximum volume:

    shine_max

    Do you think I can achieve such effect with v2.0? Or wouldnt be possible to get an option to specify max width / height of the specific animation types somehow?

    Thank you.

    opened by frankykubo 4
  • Uncaught TypeError: this.current_stream.loop is not a function

    Uncaught TypeError: this.current_stream.loop is not a function

    Followed the guide to use the CDN version and how to start the stream, etc but I am getting the following error.

    wave.js:266 Uncaught TypeError: this.current_stream.loop is not a function at Wave.playStream (wave.js:266) at playSound (player.js:46) at change (player.js:72) at HTMLElement.onclick ((index):214)

    opened by DubStepMad 4
  • Visualise Audio with muted audio

    Visualise Audio with muted audio

    Is there a way you could implement visualising audio while the audio tag is muted? I want the bars to jump on autoplay but the user has to unmute it for a better UX. In a previous issue, someone suggested { connectDestination: false } but that no longer works

    opened by becasmar 3
  • [Evolution Proposition] Full rewrite of Wave.js in Typescript, general improvements & fixes

    [Evolution Proposition] Full rewrite of Wave.js in Typescript, general improvements & fixes

    Hello @foobar404,

    Since we are more and more persons to use Wave.js, I think this is the right moment to go a step further and to rewrite the library to make it cleaner, more consistent, and easier to maintain, using Typescript. I spent some days on this task and I'm coming with an available tested proposition.

    Since it would be a huge PR and I'm not sure how you wish (or don't wish) to integrate it, I put the proposition in my own temporary repository for the moment. You can take a look and decide what to do with it Here.

    I'd be happy to help you with the integration if you need anything.

    I tried to address the following concerns :

    • Taking benefit of all typescript features.
    • Typing variables (safer usage, clearer exposure, compiler checks benefit, easier readability & easier maintainability, autocompletion).
    • Separation (isolation) of concerns for the different helpers (eg. skipUserCheck is only used with fromElement).
    • Sanitization (Removing dead code, useless variables, optimizing code when possible, adding more consistency to the style).
    • Using ESLint to adopt strong standards and protect commits.
    • Using Webpack to facilitate (and make it more customizable) the build generation.
    • Removal of draw-round-layers (was not doing anything, origamijs is no longer needed).
    • Creating unit tests with the Jest framework (It would be wonderful to increase the coverage rate in the future).
    • Using "standardized-audio-context" to deal with browsers specificities.
    • Important note about fromFile: From my understanding, this helper is supposed to regularly call a callback with a single argument corresponding to a base64 image. If so, according to the code base, it seems this one was not correctly implemented (calling the callback at 'ended' event instead of during playing, I adjusted it correspondingly to make it work based on the understanding explained right before).
    • Adding width & height options for fromFile (which will allow optimizing the rendering and will still default to window size)
    • Adding an existingMediaStreamSource option to fromElement options, so that if the user already has a source it can pass it to be used safely without facing an Error from the browser. Null by default. Useful if, for example, an existing source does exist on the audio element (to apply audio effects for example).
    • Adding a format parameter to be used to render the canvas with fromFile, default to "png"
    • Fixing the multi-types feature (that was not working for me, ctx.clearRect(0, 0, w, h) was being called for each type instead of once before all).
    • Automatically closing the AudioContext for all 3 helpers, except if an existingMediaStreamSource is passed to fromElement helper, if so, then it's not expectable to close the context since it's been created externally and might be still in use somewhere else.
    • Removing the "react-test" since it will lead to incompatibility issues with babel-jest that we are now using, creating instead 3 examples with vanilla js in examples/ folder. Appropriate npm scripts are available to launch these examples (npm run example-from-file /npm run example-from-stream /npm run example-from-element).
    • The fromElement example shows an advanced example of multiple canvas with multiple effects on each one, the 2 other examples are basic.
    • WaveJS.fromStream(...), WaveJS.fromFile(...) and WaveJS.fromElement(...) will now all return a on object containing a deactivate() method. This method will stop all the operations (the examples files use it to automatically deactivate the visualizers after an arbitrary time of 10 seconds). If needed, in the future, we will be able to add more methods to this object in order to have more control over the current execution.
    • When used inside a browser, the library is available through the global object WaveJS.
    • When used server-side or with ES6, the library is available using import WaveJS from 'wave.js-typescript'; and hopefully after the integration: import WaveJS from '@foobar404/wave';.

    The spirit and the usage of the library have not been altered. Though, there's a breaking change (which led me to set the 2.0.0 version) with the options parameter since it's now proper to different handlers (fromFile, fromStream, fromElement). These per-helper options must now be passed as a third argument instead of being mixed with the second argument.

    This rewrite might also address the following issues :

    • https://github.com/foobar404/Wave.js/issues/18
    • https://github.com/foobar404/Wave.js/issues/24
    • https://github.com/foobar404/Wave.js/issues/25
    • https://github.com/foobar404/Wave.js/issues/20

    And it integrates the following PRs :

    • https://github.com/foobar404/Wave.js/pull/26
    • https://github.com/foobar404/Wave.js/pull/16
    opened by korbav 3
Releases(v2.0.0)
Owner
Austin Michaud λ

Full-Stack Web Developer

Austin Michaud λ
:musical_score: ts-audio is an agnostic library that makes it easy to work with AudioContext and create audio playlists in the browser

ts-audio · ts-audio is an agnostic and easy-to-use library to work with the AudioContext API and create Playlists. Features Simple API that abstracts

Evandro Leopoldino Gonçalves 284 Dec 25, 2022
AmplitudeJS: Open Source HTML5 Web Audio Library. Design your web audio player, the way you want. No dependencies required.

Documentation • Examples • Tutorials • Support Us • Get Professional Help AmplitudeJS is a lightweight JavaScript library that allows you to control t

Server Side Up 3.9k Jan 2, 2023
Home Assistant custom component for viewing IP cameras RTSP stream in real time using WebRTC technology

Home Assistant custom component for viewing IP cameras RTSP stream in real time using WebRTC technology

Alex X 742 Jan 4, 2023
Simple example script that receives the signal from one iptv channel and relays it via websocket to another server to replicate the stream to multiple players

Simple example script that receives the signal from one iptv channel and relays it via websocket to another server to replicate the stream to multiple players

Ericky Thierry 3 Feb 20, 2022
Swaps video ads for an ad-free stream.

VideoAdBlockForTwitch This video adblock for Twitch extension will swap Twitch video ads for an ad-free version of the stream at 480p and then automat

cleanlock 1.5k Jan 2, 2023
HTML5 fmp4 live stream (ll-fmp4) player written in TypeScript

umataste HTML5 fmp4 live stream (ll-fmp4) player written in TypeScript Feature Playback for fmp4 stream Extremely low latency of less than 0.1 second

もにょ~ん 5 Oct 21, 2022
Automatically stream lo-fi hiphop at system startup on the Lofipi

Lofipi-mpv This runs as a system service on Raspberry Pi inside my "lofipi" speaker to automatically stream music from YouTube playlists on startup. F

Nicholas Sherlock 38 Nov 15, 2022
🎸 foolproof wrapper to stream what you're currently listening to

A lightweight Spotify API wrapper that allows you to display the music you're currently listening to ?? ?? ?? Getting started ⏪ Prerequisites Create a

null 11 Dec 29, 2022
🎬 super easy recording for p5.js animations

About • Why p5.capture? • Getting started • API Options • Browser compatibility • Limitations About Assuming you would like to record p5.js animations

tapioca24 110 Jan 5, 2023
create a bandcamp-style audio player for selling albums on itch.io

blamscamp Mmh, options, runnin' out of options, Mmh, options, used to have options bandcamp is great (at time of writing,) but it would be great to ha

Blackle Morisanchetto 154 Dec 21, 2022
Buzz, a Javascript HTML5 Audio library

Buzz is a small but powerful Javascript library that allows you to easily take advantage of the new HTML5 audio element. It tries to degrade silently on non-modern browsers.

Jay Salvat 1.2k Dec 10, 2022
This is a simple web based media player for playing video and audio. Build with pure HTML, CSS and Javascript. No framework or library included.

Aim-Player This is a simple web based media player for playing video and audio. Build with pure HTML, CSS and Javascript. No framework or library incl

Aim Mikel 2 Jun 27, 2021
A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and DailyMotion

ReactPlayer A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia, M

Pete Cook 7.2k Jan 4, 2023
Aviatojs - A simple library to trim, cut and join audio files.

Aviatojs A simple library to trim, cut and join audio files. Usage For a fully working example refer to this example Importing import {AviatoAudio}

null 6 Oct 7, 2022
Library to calculate a Mean Opinion Score (MOS) from 1 to 5 for audio and video real time communications

RTC SCORE Library to calculate a Mean Opinion Score (MOS) from 1 to 5 for audio and video real time communications. The first version of the algorithm

Gustavo Garcia 25 Nov 27, 2022
Saturn Stealer is a tool for create a server and the create malware, themalware is discord token straler/grabber.

Saturn-Stealer ⚠️ It is strictly forbidden to use this software for illegal purposes. This software was coded for educational purposes. The developer

ENDLEPH 13 Aug 28, 2022
Create videos using React!

Reactive Videos are videos created using HTML and React components. This allows you to leverage the almost limitless possibilities of the web browser

Mikael Finstad 76 Dec 25, 2022
Enables

HTML5 video made easy All it takes is a single line of code to make HTML5 video and audio tags work in all major browsers. How to enable video and aud

Dave Hall 1.3k Dec 17, 2022
HTML5

One file. Any browser. Same UI. Author: John Dyer http://j.hn/ Website: http://mediaelementjs.com/ License: MIT Meaning: Use everywhere, keep copyrigh

MediaElement.js 8k Dec 27, 2022