
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-sound-visualizer
Advanced tools
This library acts as a lightweight React wrapper for sound-visualizer.
You can check it out by visiting the codesandbox.
npm install react-sound-visualizer
You'll mainly want to use the Visualizer component (you can see more documentation for it below):
import { useEffect, useState } from 'react';
import { Visualizer } from 'react-sound-visualizer';
function App() {
const [audio, setAudio] = useState<MediaStream | null>(null);
useEffect(() => {
navigator.mediaDevices
.getUserMedia({
audio: true,
video: false,
})
.then(setAudio);
}, []);
return (
<Visualizer audio={audio}>
{({ canvasRef, stop, start, reset }) => (
<>
<canvas ref={canvasRef} width={500} height={100} />
<div>
<button onClick={start}>Start</button>
<button onClick={stop}>Stop</button>
<button onClick={reset}>Reset</button>
</div>
</>
)}
</Visualizer>
);
}
export default App;
If you need even more control over the visualization, the useVisualizer hook (used by Visualizer behind the scenes) is also exported.
| Prop | Type | Default | Explanation | |
|---|---|---|---|---|
| audio | MediaStream | null | The audio to visualize. Can be null since usually that's how your state will be initialized, but note that the functions will not be defined while it is null. | ||
| children | React.FC | See Types section below. | ||
| mode | "current" | "continuous" | "continuous" | The visualizer version to use. You can check out the sound-visualizer docs to learn more about what each version means. | |
| lineWidth | number | "thin" | "thick" | "default" | "default" | The width of each line drawn onto the canvas for the visualization. If a thickness string is provided, it will be translated into a percentage of the canvas's width; if a number is provided it will be used a px value. | |
| strokeColor | string | "#000" | The color of each line drawn onto the canvas for the visualization. | |
| autoStart | boolean | false | When set to true, the start function will be called as soon as the audio is available. | |
| slices | number | 100 | The number of slices drawn onto the canvas to make up the wave. Only available as a prop when mode is "continuous" | |
| heightNorm | number | 1 | A number used to normalize the height of the wave; the wave function is multiplied by this number, so a number larger than 1 will exaggerate the height of the wave, while a number between 0 and 1 will minimize it. Only available as a prop when mode is "current" |
export function useVisualizer(
audio: MediaStream | null,
canvas: HTMLCanvasElement | null,
options?: UseVisualizerOptions
): Partial<VisualizerFunctions>;
The useVisualizer hook acts as a simple wrapper for both the currentVisualizer and continuousVisualizer functions from
sound-visualizer, which allows the user to pass null for the audio and canvas parameters
and returns an empty object if null is passed for either.
It also wraps the VisualizerFunctions that are returned in a useMemo hook.
(Note: if you would rather not use a memo, you can directly use the visualizerWrapper function)
export interface VisualizerChildrenProps {
canvasRef: (canvas: HTMLCanvasElement) => void;
start?: () => void;
stop?: () => void;
reset?: () => void;
}
The Visualizer's children prop must be a function that returns a ReactNode.
The canvasRef must be passed as the ref prop to an HTML canvas element,
or else the visualizer will not draw anything!
export type UseVisualizerOptions =
| { mode: "current" } & DrawCurrentOptions
| { mode?: "continuous" & DrawContinuousOptions
Where DrawCurrentOptions and DrawContinuousOptions are the types from sound-visualizer.
The visualizerWrapper function, used internally by useVisualizer, is exposed for convenience.
FAQs
A lightweight wrapper for the sound-visualizer library
The npm package react-sound-visualizer receives a total of 6,401 weekly downloads. As such, react-sound-visualizer popularity was classified as popular.
We found that react-sound-visualizer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.