0.2.3 • Published 1 year ago

react-audio-spectrum3 v0.2.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

React Audio Spectrum

An audio spectrum visualizer for react, made in Typescript.

This is a fork of Mitch Mason's react-av package

Getting Started

<audio id="audio-element"
  src="path/to/song.mp3"
  controls
>
</audio>
<AudioSpectrum
  id="audio-canvas"
  height={200}
  width={300}
  audioId={'audio-element'}
  capColor={'red'}
  capHeight={2}
  meterWidth={2}
  meterCount={512}
  meterColor={[
    {stop: 0, color: '#4CAF40'},
    {stop: 0.5, color: '#0CD7FD'},
    {stop: 1, color: '#000'}
  ]}
  gap={4}
/>

you can also pass the audio element itself to the component

this.audioEle = new Audio('path/to/your/song.mp3')
<AudioSpectrum
  id="audio-canvas"
  height={200}
  width={300}
  audioEle={this.audioEle}
/>

if you use both audioId and audioEle props, the component will ignore audioEle.

Props

propertydescriptiontypedefault
idcanvas idnumber/stringa random string
widthcanvas widthnumber300
heightcanvas heightnumber200
audioIdid of the target audio elementnumber/string-
audioEletarget audio elementaudio object-
capColorcolor of capsstring#FFF
capHeightheight of capsstring2
disableCapshows or hides capsbooleanfalse
meterWidthwidth of metersnumber2
meterColorcolor of metersstring/array{stop: 0, color: '#f00'},{stop: 0.5, color: '#0CD7FD'},{stop: 1, color: 'red'}
gapgap between metersnumber10
fftSizewindow size in samplesnumber2048 (must be between 32-32768 & a power of 2)
smoothingTimeConstantaveraging constant with the last analysis framenumber0.8 (must be between 0-1)
audioContextoptional AudioContext to use (or will create its own instance)AudioContextundefined

As well as any props available for the <canvas> element.

Main differences between this fork and Mytch Mason version:

  • Removed the "Hyper-hacky way to reinit" part as it prevents to pause the Audio element
  • Updated dependencies
  • Refactored a few things
  • Changed some functions to useCallbacks as they had some dependencies