
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
react-audio-recorder-hook
Advanced tools
A powerful TypeScript-based React hook that provides complete audio recording capabilities with pause/resume functionality, recording management, and audio processing
A powerful, TypeScript-based React hook for recording, managing, and processing audio in web applications with minimal setup and maximum flexibility.
If you find this package helpful, you can support its development by buying me a coffee:
npm install react-audio-recorder-hook
# or
yarn add react-audio-recorder-hook
For comprehensive documentation, see the following resources:
import React from 'react';
import useAudioRecorder from 'react-audio-recorder-hook';
function AudioRecorderComponent() {
const {
startRecording,
stopRecording,
cancelRecording,
pauseRecording,
resumeRecording,
playRecording,
saveRecording,
isRecording,
isPaused,
recordingDuration,
} = useAudioRecorder({
audioConstraints: { echoCancellation: true },
});
const handlePlay = async () => {
const audioUrl = await playRecording();
if (audioUrl) {
const audio = new Audio(audioUrl);
audio.play();
}
};
const handleSave = async () => {
const recording = await saveRecording();
if (recording) {
console.log('Recording saved:', recording.blob);
// You can upload the blob or use it as needed
}
};
return (
<div>
<div>
Recording: {isRecording ? 'Yes' : 'No'}
{isPaused && ' (Paused)'}
</div>
<div>Duration: {recordingDuration}s</div>
<div>
{!isRecording && <button onClick={startRecording}>Start Recording</button>}
{isRecording && !isPaused && <button onClick={pauseRecording}>Pause</button>}
{isRecording && isPaused && <button onClick={resumeRecording}>Resume</button>}
{isRecording && <button onClick={stopRecording}>Stop</button>}
{isRecording && <button onClick={cancelRecording}>Cancel</button>}
<button onClick={handlePlay}>Play</button>
<button onClick={handleSave}>Save</button>
</div>
</div>
);
}
audioConstraints
: MediaTrackConstraints - Audio constraints to pass to getUserMediachunkInterval
: number - Recording data chunk interval in milliseconds (default: 500)preferredMimeType
: string - Custom MIME type to use if supportedonNotSupported
: () => void - Called when recording is unsupported on the browserAn object with the following properties:
startRecording
: () => Promise - Starts recording audiostopRecording
: () => Promise - Stops the current recordingcancelRecording
: () => void - Cancels the current recordingpauseRecording
: () => void - Pauses the current recordingresumeRecording
: () => Promise - Resumes a paused recordingsaveRecording
: () => Promise<{ blob: Blob; url: string } | null> - Creates a blob and URL for the recordingplayRecording
: () => Promise<string | null> - Creates a URL for the recording that can be used with AudioisRecording
: boolean - Whether recording is in progressisPaused
: boolean - Whether recording is pausedrecordingDuration
: number - Current recording duration in secondsmediaStream
: MediaStream | null - The current media streamThis package includes an example component that demonstrates how to implement audio waveform visualization with the hook:
import { AudioRecorderWithVisualization } from 'react-audio-recorder-hook/examples';
function App() {
return (
<div className="app">
<h1>Audio Recorder with Visualization</h1>
<AudioRecorderWithVisualization
width={500}
height={100}
backgroundColor="#f0f0f0"
barColor="#3a86ff"
/>
</div>
);
}
The package includes a comprehensive test suite that ensures all functionality works as expected. All tests are now passing.
# Run the test suite
pnpm test
# Generate test coverage report
pnpm test:coverage
We welcome contributions! Please see our Contributing Guide for details on how to submit pull requests, report issues, and suggest enhancements.
See our improvements document for planned enhancements and future features.
MIT
Version 1.0.5 and later includes improved compatibility with iOS devices by automatically detecting iOS browsers and using compatible audio formats (mp4/aac). If you experience issues with audio recording on iOS:
preferredMimeType
option:
useAudioRecorder({
preferredMimeType: 'audio/mp4',
});
If you still encounter issues on iOS devices, please report them on our GitHub issues page.
[1.0.5] - 2024-03-25
FAQs
A powerful TypeScript-based React hook that provides complete audio recording capabilities with pause/resume functionality, recording management, and audio processing
The npm package react-audio-recorder-hook receives a total of 47 weekly downloads. As such, react-audio-recorder-hook popularity was classified as not popular.
We found that react-audio-recorder-hook demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.