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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-live-audio

v0.1.1

Published

Real-Time Audio Engine for React (Streaming + VAD + PCM/Opus)

Readme

React Live Audio 🎙️

🔥 Real-Time Audio Engine for React (Streaming + VAD + PCM/Opus + Visualization)

⚠️ Note: This is an advanced audio engine, not just a simple recorder. It uses modern browser APIs (AudioWorklet, WebCodecs) which may have varying support across browsers (especially Safari/iOS).

A robust, headless React hook for real-time audio processing. Designed for Voice AI, streaming, and advanced audio applications.

🌟 Features

  • ⚡ Low Latency: Uses AudioWorklet for non-blocking audio processing.
  • 🧠 AI & Energy VAD: Built-in energy detection + support for Silero VAD (ONNX).
  • 📦 Smart Buffering: Control buffer size and metadata (sequence, timestamps).
  • 🎼 Multi-Format: Raw PCM (Int16) or compressed Opus (WebCodecs).
  • 📊 Visualization: Real-time frequency data hook.
  • 🔌 Streaming Ready: WebSocket helper and chunk-based architecture.

🥊 Why use this?

| Feature | react-live-audio | Standard Recorders | | :--- | :--- | :--- | | Focus | Real-time Streaming / AI | Saving WAV files | | Latency | Ultra-low (Worklet) | High (MediaRecorder) | | VAD | Advanced (AI/Energy) | None / Basic | | Encoding | PCM / Opus (WebCodecs) | WAV / MP3 | | Complexity | High (Engine) | Low (Widget) |

  • 🎛️ Advanced Config: Control echo cancellation, noise suppression, and VAD threshold.
  • ⚛️ React Hook: Easy-to-use useAudioRecorder and useAudioVisualizer hooks.
  • 📦 Lightweight: Minimal dependencies.
  • 🌐 Browser Support: Works in modern browsers (Chrome, Edge, Firefox, Safari). Opus encoding requires Chrome/Edge/Safari 16.4+.

Installation

npm install react-live-audio
# or
yarn add react-live-audio
# or
pnpm add react-live-audio

Usage

Basic Recording

import React from 'react';
import { useAudioRecorder } from 'react-live-audio';

const AudioApp = () => {
  const { start, stop, isRecording, isSpeaking, recordingBlob } = useAudioRecorder({
    sampleRate: 16000, // Default is 16kHz
  });

  const handleStart = async () => {
    await start((payload) => {
      // payload.data is Int16Array or Uint8Array
      // Send to WebSocket or process here
    });
  };

  return (
    <div>
      <p>Status: {isRecording ? 'Recording' : 'Idle'}</p>
      <p>VAD: {isSpeaking ? '🗣️ Speaking' : '🤫 Silent'}</p>
      
      <button onClick={handleStart} disabled={isRecording}>Start</button>
      <button onClick={stop} disabled={!isRecording}>Stop</button>
      
      {recordingBlob && (
        <audio controls src={URL.createObjectURL(recordingBlob)} />
      )}
    </div>
  );
};

Visualization

import React, { useRef, useEffect } from 'react';
import { useAudioRecorder, useAudioVisualizer } from 'react-live-audio';

const Visualizer = () => {
  const { start, stop, getVisualizerData } = useAudioRecorder();
  const frequencyData = useAudioVisualizer(getVisualizerData);
  const canvasRef = useRef<HTMLCanvasElement>(null);

  useEffect(() => {
    const canvas = canvasRef.current;
    if (!canvas) return;
    const ctx = canvas.getContext('2d');
    
    // Draw your visualization using frequencyData (Float32Array)
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    // ... drawing logic ...
  }, [frequencyData]);

  return (
    <div>
      <button onClick={() => start()}>Start</button>
      <canvas ref={canvasRef} />
    </div>
  );
};

API Reference

useAudioRecorder(options)

Options

| Property | Type | Default | Description | |----------|------|---------|-------------| | sampleRate | number | 16000 | Target sample rate for output audio. | | vadThreshold | number | 0.01 | Sensitivity for Voice Activity Detection (0.0 to 1.0). | | vadModelUrl | string | undefined | URL to Silero VAD ONNX model for AI-based detection. | | bufferSize | number | 0 | Size of audio chunks in samples. 0 = immediate. | | encoder | 'pcm' \| 'opus' | 'pcm' | Audio encoding format. 'opus' uses WebCodecs. | | audioConstraints | MediaTrackConstraints | { echoCancellation: true, ... } | Constraints passed to getUserMedia. |

Returns

| Property | Type | Description | | :--- | :--- | :--- | | start(onData?) | fn | Start recording. Optional callback for real-time data. | | stop() | fn | Stop recording and finalize Blob (if keepBlob is true). | | pause() / resume() | fn | Pause/Resume recording. | | isRecording | boolean | Current recording state. | | isSpeaking | boolean | VAD status (true when user is talking). | | recordingBlob | Blob | Final recording (WAV for PCM, Raw packets for Opus). | | recordingTime | number | Duration of current recording in ms. | | getVisualizerData | fn | Returns Float32Array of frequency data for visualization. |

🌐 Browser Support & Fallbacks

This library uses advanced browser APIs.

| Feature | Chrome / Edge | Firefox | Safari (iOS) | Fallback Behavior | | :--- | :--- | :--- | :--- | :--- | | AudioWorklet | ✅ Supported | ✅ Supported | ✅ Supported | Throws Error (Secure Context required) | | WebCodecs (Opus) | ✅ Supported | ⚠️ Partial | ❌ Not Supported | Auto-falls back to PCM | | Silero VAD | ✅ Supported | ✅ Supported | ✅ Supported | Falls back to Energy VAD |

Note on Opus: If encoder: 'opus' is used on a browser without WebCodecs (like iOS Safari), the library will automatically fall back to pcm encoding and log a warning. The onDataAvailable payload will indicate encoding: 'pcm'.

🧠 AI Integration

Streaming to OpenAI / Gemini

Use encoder: 'pcm' and sampleRate: 24000 (Gemini) or 16000 (OpenAI).

start((payload) => {
  // payload.data is Int16Array (PCM)
  // Convert to Base64 and send via WebSocket
});

Using Silero VAD

Download the ONNX model and serve it from your public folder.

useAudioRecorder({
  vadModelUrl: '/silero_vad.onnx', // Path to your model
  onVADChange: (isSpeaking) => console.log('User is:', isSpeaking ? '🗣️' : '🤫')
});

useAudioSocket(url, options)

A helper hook for WebSocket streaming.

import { useAudioSocket } from 'react-live-audio';

const { connect, disconnect, send, state } = useAudioSocket('wss://your-server.com', {
  onOpen: () => console.log('Connected'),
  onMessage: (event) => console.log('Message:', event.data),
  onError: (error) => console.error('Error:', error),
  onClose: () => console.log('Closed')
});

// Usage with recorder
start((payload) => {
  if (state === 'open') {
    send(payload.data);
  }
});

useAudioVisualizer(getVisualizerData)

Hook that drives an animation loop to fetch frequency data.

Arguments

  • getVisualizerData: The function returned from useAudioRecorder.

Returns

  • Float32Array: Real-time frequency data for visualization.