This is a modern audio recorder which actually works cross platform
A compact, high-performance audio recorder library for React Native that records directly to MP3 format on both Android and iOS.
- ποΈ Direct MP3 Recording: Records audio directly to MP3 format
- π± Cross-Platform: Works seamlessly on iOS and Android
- ποΈ Configurable: Adjust bitrate, sample rate, and channels
- βΈοΈ Pause/Resume: Full control over recording with pause and resume
- β±οΈ Real-time Duration: Get continuous recording duration updates via callback
- βΆοΈ MP3 Playback: Built-in audio player with play/pause/resume/stop/seek
- π Permission Handling: Built-in permission checking and requesting
- πΎ File Management: Automatic file naming and directory management
- π¦ Compact: Minimal dependencies, optimized for bundle size
``sh`
npm install nosnia-audio-recorderor
yarn add nosnia-audio-recorder
`js
import { NosniaAudioRecorder } from 'nosnia-audio-recorder';
// Request microphone permission
const hasPermission = await NosniaAudioRecorder.requestPermission();
`
`js
// Start recording
await NosniaAudioRecorder.startRecording({
bitrate: 128000,
channels: 1,
sampleRate: 44100,
});
// ... recording in progress ...
// Stop and save
const filePath = await NosniaAudioRecorder.stopRecording();
console.log('Recording saved to:', filePath);
`
`js
import { NosniaAudioRecorder, NosniaAudioPlayer } from 'nosnia-audio-recorder';
import { useState } from 'react';
// Check and request permission
const hasPermission = await NosniaAudioRecorder.checkPermission();
if (!hasPermission) {
await NosniaAudioRecorder.requestPermission();
}
// Start recording with real-time duration updates
await NosniaAudioRecorder.startRecording();
// Add listener for recording duration updates (every 100ms)
const removeListener = NosniaAudioRecorder.addRecordingProgressListener(
({ duration, isRecording }) => {
console.log(Recording ${Math.floor(duration / 1000)}s);
}
);
// Pause if needed
await NosniaAudioRecorder.pauseRecording();
await NosniaAudioRecorder.resumeRecording();
// Get status
const status = await NosniaAudioRecorder.getStatus();
console.log(Recording: ${status.isRecording}, Duration: ${status.duration}ms);
// Stop and save
const filePath = await NosniaAudioRecorder.stopRecording();
// Remove listener when done
removeListener();
// Or cancel (discard)
await NosniaAudioRecorder.cancelRecording();
// Play it back
await NosniaAudioPlayer.startPlaying({ filePath });
// Optionally listen to progress
const removePlayback = NosniaAudioPlayer.addPlaybackProgressListener(({ currentTime, duration }) => {
console.log(Progress: ${Math.floor(currentTime / 1000)} / ${Math.floor(duration / 1000)}s);`
});
// Stop playback
await NosniaAudioPlayer.stopPlaying();
removePlayback();
- requestPermission(): Promise - Request microphone permissioncheckPermission(): Promise
- - Check if permission is grantedstartRecording(options?: RecorderOptions): Promise
- - Start recordingstopRecording(): Promise
- - Stop and save (returns file path)pauseRecording(): Promise
- - Pause recordingresumeRecording(): Promise
- - Resume recordingcancelRecording(): Promise
- - Cancel and discardgetStatus(): Promise
- - Get recorder statusaddRecordingProgressListener(callback: RecordingProgressCallback): () => void
- - Add listener for duration updates (returns cleanup function)removeRecordingProgressListener(): void
- - Remove duration listener
- startPlaying(options: PlayOptions): Promise - Start playing an audio filestopPlaying(): Promise
- - Stop playback and resetpausePlaying(): Promise
- - Pause playbackresumePlaying(): Promise
- - Resume playbackseekToTime(time: number): Promise
- - Seek to time (seconds)setVolume(volume: number): Promise
- - Set playback volume (0.0β1.0)getPlayerStatus(): Promise
- - Get playback statusaddPlaybackProgressListener(callback: PlaybackProgressCallback): () => void
- - Listen to playback progressaddPlaybackCompleteListener(callback: () => void): () => void
- - Listen for playback completionremovePlaybackProgressListener(): void
- - Remove progress listenerremovePlaybackCompleteListener(): void
- - Remove completion listener
`ts
interface RecorderOptions {
filename?: string; // Auto-generated if not provided
bitrate?: number; // Default: 128000 (128 kbps)
channels?: number; // 1 = mono (default), 2 = stereo
sampleRate?: number; // Default: 44100 (44.1 kHz)
}
interface RecorderStatus {
isRecording: boolean;
duration: number; // In milliseconds
currentFilePath?: string;
}
type RecordingProgressCallback = (data: {
duration: number; // In milliseconds
isRecording: boolean;
}) => void;
interface PlayOptions {
filePath: string;
volume?: number; // 0.0 - 1.0
loop?: boolean; // repeat playback
}
interface PlayerStatus {
isPlaying: boolean;
duration: number; // In milliseconds
currentTime: number; // In milliseconds
currentFilePath?: string;
}
type PlaybackProgressCallback = (data: {
currentTime: number;
duration: number;
isPlaying: boolean;
}) => void;
`
Add permission to android/app/src/main/AndroidManifest.xml:
`xml`
Add microphone permission to ios/[AppName]/Info.plist:
`xml`
| Setting | Value |
|---------|-------|
| Format | MP3 |
| Bitrate | 128 kbps |
| Sample Rate | 44.1 kHz |
| Channels | 1 (Mono) |
- Speech: 64 kbps, 16 kHz, mono
- Music: 192-320 kbps, 44.1-48 kHz, stereo
- Balanced: 128 kbps, 44.1 kHz, mono
- Android: Documents/NosniaAudioRecorder/ (API 29+) or Music/NosniaAudioRecorder/Documents/NosniaAudioRecorder/`
- iOS:
- Lightweight native implementation
- Minimal memory footprint
- Direct encoding to M4A format
- Efficient file handling
For detailed usage guide, see USAGE.md
- Development workflow
- Sending a pull request
- Code of conduct
MIT
---
Made with create-react-native-library