react-native-live-audio-record
v1.1.7
Published
Get live audio recorder data for React Native
Downloads
117
Maintainers
Readme
react-native-live-audio-record
Get live audio stream data for React Native with Android background recording support. Ideal for live voice recognition, transcribing, and continuous audio monitoring.
📖 About
This library is forked from xiqi/react-native-live-audio-stream and enhanced with background audio recording capabilities.
What's New:
- Android: Foreground service with wake lock and battery optimization awareness
Install
yarn add react-native-live-audio-record
cd ios
pod installPermissions and Setup
iOS
Add these lines to ios/[YOUR_APP_NAME]/info.plist
<key>NSMicrophoneUsageDescription</key>
<string>This app needs access to microphone to record audio for streaming.</string>
<!-- Background modes for audio recording -->
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
<string>background-processing</string>
</array>
<!-- Required device capabilities -->
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>microphone</string>
</array>Android
Add the following permissions to android/app/src/main/AndroidManifest.xml
<!-- Required permissions -->
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Service declaration -->
<application>
<service
android:name="com.imxiqi.rnliveaudiostream.RNLiveAudioStreamService"
android:enabled="true"
android:exported="false"
android:foregroundServiceType="microphone" />
</application>Background Recording Support
This library now supports background audio recording on both platforms:
- Android: Uses foreground service with persistent notification
Important: For reliable background recording, users should:
- iOS: Enable "Background App Refresh" for your app
- Android: Disable battery optimization for your app in device settings
Usage
import LiveAudioStream from 'react-native-live-audio-record';
// yarn add buffer
import { Buffer } from 'buffer';
const options = {
sampleRate: 32000, // default is 44100 but 32000 is adequate for accurate voice recognition
channels: 1, // 1 or 2, default 1
bitsPerSample: 16, // 8 or 16, default 16
audioSource: 6, // android only (see below)
bufferSize: 4096 // default is 2048
};
LiveAudioStream.init(options);
LiveAudioStream.on('data', data => {
// base64-encoded audio data chunks
var chunk = Buffer.from(data, 'base64');
});
...
LiveAudioStream.start();
...
LiveAudioStream.stop();
...audioSource should be one of the constant values from here. Default value is 6 (VOICE_RECOGNITION).
Contributing
Feel free to submit issues and pull requests. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
git clone <your-fork>
cd react-native-live-audio-record
npm install
# Test on example project
cd example
npm install
npx react-native run-ios
npx react-native run-androidCredits/References
Original Library:
- xiqi/react-native-live-audio-stream - Base implementation
Background Recording Enhancements:
- react-native-audio-record - Audio recording concepts
- iOS Audio Queues - iOS audio implementation
- Android AudioRecord - Android audio API
- Background Tasks - iOS background processing
- Foreground Services - Android background services
Additional References:
License
MIT
Support
- 📖 Background Recording Guide - Detailed technical documentation
- 🐛 Issues - Bug reports and feature requests
- 💬 Discussions - Community support
