0.1.4 • Published 7 months ago

audio-visualizer.js v0.1.4

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

audio-visualizer.js

audio-visualizer.js is a lightweight and customizable JavaScript library for creating stunning audio visualizations using Three.js. Whether you need 2D shapes, 3D objects, waveform displays, or dynamic lighting, audio-visualizer.js provides flexible options to bring your audio to life.

Features

  • Multiple Visualization Presets: Choose from 2D shapes, 3D shapes, waveforms, line waveforms, and dynamic lighting.
  • Three.js Integration: Harness the power of Three.js for high-performance 3D rendering.
  • Customizable Layers: Stack multiple visualization layers with independent settings.
  • React Support: Built with React compatibility for seamless UI integration.
  • Easy to Use: Simple configuration and extensive customization options.

Installation

Install via npm:

npm install audio-visualizer.js

Usage

Basic Example

import React, { useRef } from "react";
import { AudioVisualizer } from "audio-visualizer.js";

const App = () => {
  const audioRef = useRef(null);

  const config = {
    layers: [
      {
        preset: "Shape3D",
        settings: {
          shape: "sphere",
          color: "#ff0000",
          amplitude: 5,
          size: 2,
        },
      },
      {
        preset: "Waveform",
        settings: {
          color: "#00ff00",
          amplitude: 3,
          period: 1,
          lineWidth: 2,
        },
      },
    ],
  };

  return (
    <div>
      <audio ref={audioRef} src="path/to/audio.mp3" controls />
      <AudioVisualizer audioRef={audioRef} config={config} backgroundColor="#000" />
    </div>
  );
};

export default App;

Available Props

AudioVisualizerProps

PropTypeDescription
audioRefReact.RefObject<HTMLAudioElement>Reference to the audio element.
srcstringURL of the audio source.
styleReact.CSSPropertiesInline styles for the container.
classNamestringCustom CSS class name.
configConfigConfiguration object for visualizer layers.
backgroundColorstringBackground color of the visualization canvas.

Configuration

The config prop defines the visualizer layers. Each layer includes a preset and its specific settings.

Presets and Settings

Shape2D

SettingTypeDescription
shape"circle" \| "square" \| "triangle"Shape of the 2D object.
colorstringColor of the shape.
sizenumberSize of the shape.
rotationAmplitudenumberAmplitude of rotation.

Shape3D

SettingTypeDescription
shape"cube" \| "sphere" \| "torus" \| "dodecahedron" \| "icosahedron"3D shape type.
colorstringColor of the shape.
rotationXAmplitudenumberAmplitude of rotation on X-axis.
rotationYAmplitudenumberAmplitude of rotation on Y-axis.
rotationZAmplitudenumberAmplitude of rotation on Z-axis.

Waveform

SettingTypeDescription
colorstringColor of the waveform.
amplitudenumberWaveform amplitude.
periodnumberWaveform period.
lineWidthnumberThickness of the waveform line.

Light

SettingTypeDescription
colorstringLight color.
type"ambient" \| "directional" \| "point" \| "spot"Type of light.
intensitynumberLight intensity.
position[number, number, number]Position of the light in 3D space.

For the full list of options, refer to the audio-visualizer.js type definitions.

API Reference

AudioVisualizerRef

MethodDescription
playPlays the audio.
pausePauses the audio.
getAudioElementReturns the audio element instance.

Default Values

Each preset has default settings. You can customize these settings as needed in the config prop.

License

MIT

Contributions

Contributions are welcome! Feel free to submit issues or pull requests on the GitHub repository.

Acknowledgments

Built with Three.js and inspired by FLStudio's audio visualizer.

0.1.0

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.4

7 months ago

0.1.3

7 months ago

0.0.10

7 months ago

0.0.9

7 months ago

0.0.8

7 months ago

0.0.7

7 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago

0.0.0

7 months ago