You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP β†’
Socket
Book a DemoInstallSign in
Socket

use-audio-capture

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-audio-capture

πŸŽ™οΈ A lightweight React hook for audio recording using native Web APIs (MediaRecorder, getUserMedia). Start, stop, pause, resume audio recordings with customizable callbacks. Perfect for voice notes, interviews, podcasts, and real-time audio processing in

1.0.1
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

πŸŽ™οΈ use-audio-capture

npm version License: MIT TypeScript

A lightweight, zero-dependency React hook for audio recording using native Web APIs (MediaRecorder, getUserMedia). Perfect for building voice notes, podcasts, interviews, and real-time audio processing applications in React.

πŸš€ Why use-audio-capture?

Stop struggling with complex audio libraries! This React hook leverages native browser APIs to provide:

  • 🎯 Simple API - Start recording with just one function call
  • πŸͺΆ Lightweight - Zero external dependencies, uses native Web APIs
  • πŸ”§ TypeScript Support - Fully typed for excellent developer experience
  • πŸŽ›οΈ Full Control - Start, stop, pause, resume recordings programmatically
  • πŸ“Š Real-time Data - Access audio chunks as they're recorded
  • 🚨 Error Handling - Built-in error management for robust applications
  • 🌐 Cross-browser - Works in all modern browsers supporting MediaRecorder API

πŸ“¦ Installation

npm install use-audio-capture
yarn add use-audio-capture
pnpm add use-audio-capture

🎯 Use Cases

Perfect for building:

  • πŸŽ™οΈ Voice note applications
  • 🎧 Podcast recording tools
  • πŸ“ž Interview and meeting recorders
  • 🎡 Music practice apps
  • πŸ—£οΈ Voice memos and dictation tools
  • πŸ“± Audio chat applications
  • 🎬 Content creation platforms
  • πŸ”Š Audio feedback systems
  • 🎀 Karaoke and singing apps
  • πŸ“š Language learning tools with pronunciation

🏁 Quick Start

Basic Audio Recording

import { useAudioCapture } from 'use-audio-capture';

export const VoiceRecorder = () => {
  const { start, stop, pause, resume } = useAudioCapture({
    onStart: () => console.log('πŸŽ™οΈ Recording started'),
    onChunk: (blobEvent) => console.log('Blob event here'),
    onStop: (event, chunks) => {
      // You can create audio file from recorded chunks on stop
      const blob = new Blob(chunks, { type: chunks[0].type });
      const file = new File([blob], 'sampleFile.webm', {
        type: chunks[0].type,
      });
      console.log(file);
    },
    onError: (_event, { error }) => {
      console.error('Recording error:', error);
    },
  });

  return (
    <div>
      <button onClick={start}>πŸŽ™οΈ Start Recording</button>
      <button onClick={stop}>⏹️ Stop</button>
      <button onClick={pause}>⏸️ Pause</button>
      <button onClick={resume}>▢️ Resume</button>
    </div>
  );
};

πŸ“– See Live Example | 🎨 Storybook Demo

More Advanced Example

Component example built based on use-audio-capture hook - See live example

πŸ“š API Reference

Hook Usage

const { start, stop, pause, resume } = useAudioCapture(options);

Available Functions

FunctionDescriptionUsage
start()Start audio recordingawait start()
stop()Stop recording and trigger onStop callbackawait stop()
pause()Pause current recording sessionawait pause()
resume()Resume paused recordingawait resume()

Callback Options

CallbackTriggered WhenParameters
onStartRecording begins(event, { mediaStream })
onChunkNew audio data available(blobEvent, { mediaStream })
onStopRecording stops(event, chunks[], { mediaStream })
onPauseRecording paused(event, chunks[], { mediaStream })
onResumeRecording resumed(event, chunks[], { mediaStream })
onErrorError occurs(event, { mediaStream, error })

🌐 Browser Support

This hook works in all modern browsers that support:

BrowserSupport
Chromeβœ… 47+
Firefoxβœ… 29+
Safariβœ… 14+
Edgeβœ… 79+

πŸ“„ License

MIT Β© breeg554

Keywords: react hook, audio recording, web api, mediarecorder, getusermedia, voice notes, podcast, interview, real-time audio, browser recording, typescript, react audio, voice recorder, audio capture, microphone access

Keywords

react

FAQs

Package last updated on 29 Jun 2025

Did you know?

Socket

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.

Install

Related posts