csdcorp / speech_to_text

A Flutter plugin that exposes device specific text to speech recognition capability.
BSD 3-Clause "New" or "Revised" License
351 stars 218 forks source link

level is negative #453

Closed niwococo closed 6 months ago

niwococo commented 6 months ago

Before I recording, I print the lastSoundLevel, Its a negative number. flutter:level:-48.05121612548828 When I am recording, in onSoundLevelChange the level is still negative Can anyone help me ?

agladyshev commented 6 months ago

Hey, @niwococo. As far as I understand, this value is something called RMS dB. 0 is the reference level, in this case I think it's the maximum of what your input device can record. Values closer to 0 dB correspond with greater perceived loudness. What it is that you originally wanted to do with the volume level?

niwococo commented 6 months ago

I want to use the 'level' parameter as an animation indicator for monitoring sound. I thought it represents decibel values, which theoretically should start from 0. However, the initial value I'm printing here is around -48.

agladyshev commented 6 months ago

It depends on what kind of animation you do.

  1. If you are displaying some kind of histogram and need actual values, you can say that 100db is you max, and just add 100 to the negative value.
  2. If it's like a volume bar, you can use values from 0 to 1 to animate it. For 0, you need to track minVolume, let's say -48. I you get like -60, you update minVolume to that value. Your maxVolume is 0db. So, the difference between minVolume and maxVolume is 48, it's your range. When you get current volume, for example -30, you normalize it by that range: (-30 + 48) / 48 = 0.375, so that's like 37.5% of maxVolume.

It's not ideal for sure, but can be useful. If there is a better way, I hope someone would suggest it.

niwococo commented 6 months ago

Thx a lot, I will try~