react-native-aec
v1.0.0
Published
React Native native module for Acoustic Echo Canceler (AEC) on Android
Maintainers
Readme
react-native-aec
React Native native module for Acoustic Echo Canceler (AEC) on Android.
Features
- Enable/disable Acoustic Echo Canceler on Android devices
- Uses
AudioRecordwithVOICE_COMMUNICATIONaudio source - Automatic device compatibility checking
- Proper resource management and cleanup
- TypeScript support
Installation
npm install react-native-aec
# or
yarn add react-native-aecLinking
React Native 0.60+
The library is automatically linked thanks to autolinking.
React Native < 0.60
react-native link react-native-aecManual linking
- Add the following to
android/settings.gradle:
include ':react-native-aec'
project(':react-native-aec').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-aec/android')- Add the following to
android/app/build.gradle:
dependencies {
implementation project(':react-native-aec')
}- Add the following to
android/app/src/main/java/com/yourapp/MainApplication.java:
import com.reactnativeaec.AECPackage;
// In the getPackages() method:
packages.add(new AECPackage());Permissions
Add the following permissions to your android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />Usage
import { enableAEC, disableAEC } from 'react-native-aec';
// Enable AEC
try {
const result = await enableAEC();
console.log('AEC enabled:', result);
} catch (error) {
console.error('Failed to enable AEC:', error);
}
// Disable AEC
try {
const result = await disableAEC();
console.log('AEC disabled:', result);
} catch (error) {
console.error('Failed to disable AEC:', error);
}API
enableAEC(): Promise<string>
Enables Acoustic Echo Canceler on the device.
Returns: Promise that resolves with a success message or rejects with an error.
Possible errors:
AEC_NOT_SUPPORTED: Device doesn't support AECAUDIO_CONFIG_ERROR: Invalid audio configurationAUDIO_RECORD_ERROR: Failed to initialize AudioRecordAUDIO_TRACK_ERROR: Failed to initialize AudioTrackAEC_CREATE_ERROR: Failed to create AcousticEchoCancelerAEC_ENABLE_ERROR: Failed to enable AcousticEchoCanceler
disableAEC(): Promise<string>
Disables Acoustic Echo Canceler and releases all resources.
Returns: Promise that resolves with a success message or rejects with an error.
Requirements
- Android API level 21+ (Android 5.0+)
- React Native 0.60+
- Device must support Acoustic Echo Canceler
License
MIT
