qiuxiang / react-native-recording

React Native audio recording module used for DSP with Android + iOS
MIT License
110 stars 62 forks source link

How to find real-time audio level #22

Closed yigithanyucedag closed 3 years ago

yigithanyucedag commented 4 years ago
 for (let d = 0; d < this.globalBuffer.length; d++) {
      rms += this.globalBuffer[d] * this.globalBuffer[d];
    }

 rms = Math.sqrt(rms / this.globalBuffer.length);

I use this algorithm which called root-mean-square It basically calculates the amount of signal in the buffer but when there is no sound it gives values which are more than 0.

My question: What is the proper way to determine input audio level in react native by using this library?

Note: I'm trying to implement this tuner to my react native app it is written with javascript web audio api

https://github.com/googlearchive/guitar-tuner/blob/master/src/elements/audio-processor/audio-processor.js

I think I need to use AnalyserNode in react native but how? https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode

carlmagumpara commented 4 years ago

try this using buffer ` Recording.init({ bufferSize: 4096, sampleRate: 44100, bitsPerChannel: 16, channelsPerFrame: 1, });

const dataToLevel = data => {
  const chunk = Buffer.from(data, 'base64');
  level.current = Math.round((Object.values(chunk)[0] * audioMax) / 256);

console.log( level.current) };

const listener = Recording.addRecordingEventListener(dataToLevel);

Recording.start();`