An audio recording and playback library for React Native iOS apps.
On iOS, it supports most iOS AVAudioRecorder class configuration options.
Install the package via npm, and link the binary to your iOS and Android projects:
npm install react-native-audio
react-native link react-native-audio
Update AndroidManifest.xml by adding the RECORD_AUDIO
permission:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
In the AudioExample
directory:
npm install
react-native run-ios
In the AudioExample
directory:
npm install
react-native run-android
This library supports recording, basic playback and progress reporting. Progress reporting is iOS only for now.
To record in AAC format, at 22050 KHz in low quality mono with metering enabled:
import {AudioRecorder, AudioUtils} from 'react-native-audio';
let audioPath = AudioUtils.DocumentDirectoryPath + '/test.aac';
AudioRecorder.prepareRecordingAtPath(audioPath, {
SampleRate: 22050,
Channels: 1,
AudioQuality: "Low",
AudioEncoding: "aac",
MeteringEnabled: true
});
See the example for more options, including playback and callbacks. For more audio play options, check out React Native Sound
A subset of formats listed here are supported: https://developer.apple.com/reference/coreaudio/1572096-audio_data_format_identifiers
Currently supported format arguments: lpcm, ima4, aac, MAC3, MAC6, ulaw, alaw, mp1, mp2, alac.
MP3 recording is not supported on iOS.
Thanks to Brent Vatne, Johannes Lumpe, Kureev Alexey and Matthew Hartman for their assistance.
Progress tracking code borrowed from https://github.com/brentvatne/react-native-video.