How can I get current microphone volume? #698
-
Hi! I'm trying make a way to detect when user is speaking, I thought that to reach it maybe through current volume/frequency. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You need to inspect the values of your samples that you get from the data callback. Take the absolute value of your samples to determine the volume. If you set your sample format to floating point ( |
Beta Was this translation helpful? Give feedback.
You need to inspect the values of your samples that you get from the data callback. Take the absolute value of your samples to determine the volume. If you set your sample format to floating point (
ma_format_f32
), you can consider 0 to be silence and 1 to be maximum. For presentation on the UI, considering averaging your samples over a period of time and storing that in a variable (maybe average all of your samples from each data callback instantiation). Then scale the value (which will be between 0 and 1) to an appropriate value for presentation on your UI.