@flyskywhy/react-native-loudness
v2.0.5
Published
Read microphone loudness in React Native
Downloads
5
Maintainers
Readme
react-native-loudness
Read microphone loudness in React Native
Getting started
$ npm install @flyskywhy/react-native-loudness --save
$ react-native link @flyskywhy/react-native-loudness
For RN>0.60, no need to link but please run pod install
in the project ios
directory.
Required Additional Steps
iOS
- In
Info.plist
, addPrivacy - Micronphone Usage Description
using XCode.
Android
- In
AndroidManifest.xml
, add<uses-permission android:name="android.permission.RECORD_AUDIO" />
.
Permission
The app needs to ask permission for microphone usage. If the loudness reading is not a number or is always a fixed number, check the app permission first. For Android 6.0 (API level 23) or later, the permission needs to be asked when running the app. Learn more here. For iOS devices, the permission will be automatically asked when needed. It can also be manually asked. Check out react-native-permissions.
Usage
Loudness is in dbFS from -160 to 0, where -160 represents near absolute silence and 0 represents the maximum loudness the microphone can sense.
import Loudness from '@flyskywhy/react-native-loudness';
Loudness.start();
Loudness.getLoudness((loudness) => {
console.log(loudness);
});
Loudness.stop();
While reading the loudness, this module can save the microphone reading into a WAV audio file at the same time. The file is 16 bit, 44.1kHz, and mono channel both for iOS and Android. The file is located in the document directory of the app. Please use another library such as rn-fetch-blob to move, delete, or copy the file.
Loudness.start('test'); // Supply a file name string to save the file
Example
Check out this example app LoudnessMeter for more details.