1.0.1 โข Published 7 months ago
react-audio-recrd v1.0.1
React Student Audio Recorder
A React component for recording audio with a student-friendly UI. Features include audio compression, time limits, and a clean, intuitive interface.
Features
- ๐๏ธ Simple audio recording interface
- โฑ๏ธ Configurable recording time limit
- ๐๏ธ Audio compression (opus codec)
- ๐ฏ Customizable callbacks for save/delete actions
- ๐ฑ Responsive design with Tailwind CSS
- ๐จ Clean, intuitive UI with clear status indicators
- โฟ Accessible with ARIA labels
- ๐งช Fully tested with Jest
Installation
npm install react-audio-recrd
Usage
import { AudioRecorder } from 'react-audio-recrd';
function App() {
const handleSave = (blob) => {
// Handle the recorded audio blob
console.log('Recorded audio:', blob);
// Example: Upload to server
const formData = new FormData();
formData.append('audio', blob, 'recording.webm');
// fetch('/api/upload', { method: 'POST', body: formData });
};
const handleDelete = () => {
// Handle deletion
console.log('Recording deleted');
};
return (
<AudioRecorder
onSave={handleSave}
onDelete={handleDelete}
maxDuration={300} // 5 minutes
compressionBitsPerSecond={96000} // 96kbps
/>
);
}
Props
Prop | Type | Default | Description |
---|---|---|---|
onSave | (blob: Blob) => void | () => {} | Callback when recording is saved |
onDelete | () => void | () => {} | Callback when recording is deleted |
maxDuration | number | 300 | Maximum recording duration in seconds |
compressionFormat | string | 'audio/webm;codecs=opus' | Audio compression format |
compressionBitsPerSecond | number | 96000 | Audio bitrate in bits per second |
Browser Support
This component uses the MediaRecorder API. Check browser compatibility for support details.
The component requires these browser features:
- MediaRecorder API
- getUserMedia API
- Web Audio API
Development
# Install dependencies
npm install
# Run tests
npm test
# Build package
npm run build
# Lint code
npm run lint
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
MIT ยฉ Artur Gomes
Notes
- The component uses Opus codec for audio compression, providing good quality at low bitrates
- Recording automatically stops when reaching maxDuration
- Designed with accessibility in mind, including proper ARIA labels and keyboard navigation
- Uses Tailwind CSS for styling - make sure Tailwind is configured in your project
Support
If you find any bugs or have feature requests, please create an issue in the GitHub repository.