Reputation: 49
Im building a react-native application. Im trying to meter the current sound level (in decibel).
Libraries in use: react-native-audio and react-native-sound.
There is anybody familiar with this feature?
Thank you.
Upvotes: 1
Views: 6662
Reputation: 836
With the react-native-audio library, you can get the count for the only iOS.
For the currentMetering
in Android, you need to customize in a native module. I have updated it add the following things in your package.json
file instead of your code. You will get the currentMetering
count for the Android as well as iOS.
"react-native-audio": "git+https://github.com/Harsh2402/react-native-audio.git",
Upvotes: 5
Reputation: 3934
You can use react-native-audio
currentMetering value - in order to get the sound level in real-time.
First, you will have to initialise your recorder (which i will assume youve done). I use prepareRecordingAtPath
in a similar way to below
AudioRecorder.prepareRecordingAtPath(audioPath, {
SampleRate: 22050,
Channels: 1,
AudioQuality: "Low",
AudioEncoding: "aac",
MeteringEnabled: true
});
then once you've called AudioRecorder.startRecording();
(Note you have access to .pause()
and .stop()
methods also
Now for handling the audio level, you are going to have to retrieve the data that is returned by the onProgress
method. From what i remember, there should be some currentMetering
value that you can access. Note that defining this behaviour will trigger the action every time a different decibel reading is retrieved. Like so
AudioRecorder.onProgress = data => {
let decibels = Math.floor(data.currentMetering);
//DO STUFF
};
Hope this helps,
Upvotes: 3