mic_stream icon indicating copy to clipboard operation
mic_stream copied to clipboard

calculate amplitude

Open paxbo opened this issue 2 years ago • 11 comments

Is there a way to calculate the amplitude of the streamed microphone data?

paxbo avatar Jul 02 '22 18:07 paxbo

You can calculate the amplitude from the sampled data. How you do this depends on what type of amplitude you want (e.g., average amplitude over some delta time or mean squared amplitude).

Maybe have a look through this website: http://www.sengpielaudio.com/calculator-amplitude.htm Figure out what exactly you want to know, search for the right formula, and turn it into a discrete function.

anarchuser avatar Jul 02 '22 19:07 anarchuser

Thank you! Could you explain to me what exactly you calculate in the _calculateIntensitySamples(samples) function?

paxbo avatar Jul 03 '22 08:07 paxbo

It extracts the local minimum and maximum from each list of samples to calculate the local amplitude

anarchuser avatar Jul 03 '22 16:07 anarchuser

@paxbo did you manage to do it?

0x15F9 avatar Sep 15 '22 14:09 0x15F9

Unfortunately not.. I switched to a native implementation in Java

paxbo avatar Sep 23 '22 10:09 paxbo

Again, the important question is which kind of amplitude you want to calculate

anarchuser avatar Sep 23 '22 11:09 anarchuser

@anarchuser my goal is to determine whether there is an active speaker or if the microphone is only registering background noise. I was thinking that the amplitude would be a good indicator of that, however, I'm unsure of the kind of amplitude that's more appropriate.

0x15F9 avatar Sep 27 '22 03:09 0x15F9

Then you want to have a look at calculating the mel-frequency cepstral coefficients. The mel-frequency cepstrum was invented for human voice recognition and as such allows you to easily distinguish between speech and noise

anarchuser avatar Sep 27 '22 05:09 anarchuser

Coincidentally, there seems to be a package available for calculating the MFCCs: https://pub.dev/packages/mfcc

anarchuser avatar Sep 27 '22 05:09 anarchuser

You can transform the audio stream to an mfcc stream. Do make sure to first transform the audio stream to Double. Then you can read out the right coefficient every now and then (You probably want the first one)

anarchuser avatar Sep 27 '22 05:09 anarchuser

@anarchuser thank you for the help! Much appreciated

0x15F9 avatar Oct 01 '22 06:10 0x15F9