Sound metering react-native

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.

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,

Comments

Popular posts from this blog

Meaning of `{}` for return expression

Get current scroll position of ScrollView in React Native

flutter websocket connection issue