A React Native module that provides high-performance, cross-platform access to raw audio data for analysis, visualization, and custom DSP in JavaScript and native code.
Powered by Nitro Modules and dr_libs for stable, efficient C++ audio decoding.
- ⚡️ High Performance: Uses C++ directly via JSI for near-native performance.
- � Asynchronous: All decoding and waveform generation runs on background threads to keep the UI smooth.
- �🪶 Lightweight: Zero heavy dependencies like FFmpeg. Uses
dr_libsfor minimal footprint. - 🔊 Format Support: Decodes MP3, WAV, and FLAC files.
- 🌊 Waveform Generation: High-speed waveform data generation for visualization. Multiple methods supported including RMS, LUFS and Abs Mean.
- 🎹 Raw PCM Data: Access raw
Float32audio samples for finding peaks, normalization, or custom processing. - 📱 Cross-Platform: Works on iOS and Android.
npm install react-native-audio-data react-native-nitro-modulesNote:
react-native-nitro-modulesis a required peer dependency.
No additional setup is required.
Install Pods:
cd ios && pod installDecode an audio file to get the full raw PCM data (Float32).
import { getRawPcmData } from 'react-native-audio-data';
// ...
try {
const result = await getRawPcmData('path/to/audio/file.mp3');
console.log('Channels:', result.channels);
console.log('Sample Rate:', result.sampleRate);
console.log('Total Frames:', result.totalPCMFrameCount);
// The raw buffer (ArrayBuffer)
// You can create a Float32Array view on it:
const float32Data = new Float32Array(result.buffer);
} catch (error) {
console.error("Failed to decode audio", error);
}Quickly generate simplified waveform data for UI visualization (e.g., an audio player progress bar).
import { getWaveformDataByPoints, getWaveformData } from 'react-native-audio-data';
// ...
// Option A: Request points by time resolution (e.g. one point every 50ms)
const timeBasedPoints = await getWaveformData('path/to/audio/file.mp3', 50);
console.log(timeBasedPoints);
// Output: [0.02, 0.45, ...] (length depends on audio duration)
// Option B: Request a fixed number of data points (e.g. 100 points)
const fixedPoints = await getWaveformDataByPoints('path/to/audio/file.mp3', 100);
console.log(fixedPoints);
// Output: [0.05, 0.23, ...] (100 items)Decodes the audio file and returns the raw PCM data.
- Parameters:
filePath(string): Absolute path or URI to the audio file.
- Returns:
Promise<AudioDataResult>buffer(ArrayBuffer): Raw PCM data (Float32).channels(number): Number of audio channels.sampleRate(number): Sample rate in Hz.totalPCMFrameCount(number): Total number of PCM frames.
Generates a waveform where each point represents a specific duration of audio.
- Parameters:
filePath(string): Absolute path or URI to the audio file.millisecondsPerPoint(number): The duration each point should represent (e.g., 100ms).method(WaveformMethod, optional): Calculation method. Values:'RMS'(default),'AbsMean','LUFS'.
- Returns:
Promise<number[]>containing normalized values.
Generates a waveform with a specific fixed number of points.
- Parameters:
filePath(string): Absolute path or URI to the audio file.targetPoints(number): The number of data points you want in the output array.method(WaveformMethod, optional): Calculation method. Values:'RMS'(default),'AbsMean','LUFS'.
- Returns:
Promise<number[]>containing normalized values.
Utility to resolve platform-specific file paths (e.g., Android Content URIs) to absolute system paths usable by C++.
- Parameters:
filePath(string): The raw file path or URI.
- Returns:
Promise<string>resolving to the absolute file path.
- Support decoding while recording (Real-time Analysis)
- Full multi-threading supported decoding
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
