npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

audica

v0.2.2

Published

Extract waveform and frequency data from any audio source to create beautiful audio visualizations

Downloads

22

Readme

Audica

Extract Bytetime/Frequency data from audio or video elements, to create awesome audio visualizations.

Demo site here

What is it?

Audica is a lightweight abstraction around AudioContext and webkitAudioContext. It allows for quick and easy extraction of data via WebAudioAPI's AnalyserNode to capture data into an array so you can easily create fun and beautiful audio visualizations.

Features

  • Dead simple API
  • Use either bytetime data, frequency data, or both!
  • Connects to either <audio> or <video> HTML elements
  • Built in TypeScript support for IDE embedded documentation in VSCode.

How to use

Install with npm install audica if you're using Node.js

Bundled client side applications

const audica = require('audica');
// OR
import audica from 'audica';

Client side app

<!-- Install via unpkg -->

<script src="https://unpkg.com/audica"></script>
<!-- Your HTML here -->

<script>
  const myAudica = audica({ /* options */});
</script>

Examples of usage

Barebones/Minimum

const myAudica = audica({
  element: document.getElementById('audio-element'),
  size: 256
});

const animationLoop = () => {
  window.requestAnimationFrame(animationLoop);

  // array of ByteTime data
  const data = myAudica.getData();

  for (let i = 0; i < 256; i++) {
    // Do something with this array of integers representing byte time data
  }
}

Get frequency data and show some bars moving at 60 FPS

const myAudica = audica({
  element: document.getElementById('audio-element'),
  size: 256,
  dataType: 'hz' // defaults to 'time' if left undefined
});

const animationLoop = () => {
  window.requestAnimationFrame(animationLoop);

  // array of ByteTime data
  const data = myAudica.getData();

  // Get 256 divs that are on the DOM
  const bars = Array.from(document.querySelectorAll('.bar'));

  for (let i = 0; i < bars.length; i++) {
    // Color every bar white and make it as tall as the frequency data
    bars[i].style = `height: ${data[i]}px; width: 3px; background-color: white;`;
  }
}

Audica API

Create a new Audica instance

const options = {
  /**
   * Size of the array of audio data to be returned from Audica.
   * A larger number means more fine grained control, but lowers performance.
   * This number must be larger than 8, and divisible by 8.
   *
   * NOTE FOR NERDS: This value becomes analyzer.fftSize.
   * analyzer.fftSize = size * 2
   *
   * @default 256
   */
  size: 256,

  /**
   * The Audio or video element to draw audio data from. This value cannot
   * be null or falsy.
   * @required
   */
   element: document.querySelector('audio'),

   /**
   * Type of Frequency data to retrieve.
   * 'time' returns byte time frequency data (think waveform)
   * 'hz' returns frequency data, where data[0] starts with lower (bass) frequencies,
   * and the later elements in the array (data[255]) are higher (treble) frequencies
   *
   * @default 'time'
   */
    dataType: 'time' || 'hz';
}
const myAudica = audica(audicaOptions);

/**
 *  The heart of Audica - retrives bytetime or frequency data from the attached
 *  audio/video element at the current time
 */
myAudica.getData();

/**
 * Change the type of data Audica is returning, can be set to 'time' or 'hz'
 * */
myAudica.setDataType('time' || 'hz');

Created with <3 by Ben Junya @MrBenJ