flutter-pi icon indicating copy to clipboard operation
flutter-pi copied to clipboard

Get sound decibel of microphone

Open BigGitWorld opened this issue 1 year ago • 2 comments

Hello. How can I measure the decibel level of a microphone connected to a Raspberry Pi (inside of a flutter-pi based application)? I found the flutter package noise_meter, but it does not have linux implementation.

BigGitWorld avatar Mar 27 '23 08:03 BigGitWorld

@ardera can you please suggest me a solution?

BigGitWorld avatar Jul 05 '23 09:07 BigGitWorld

That's definitely something you'll have to write a plugin for, unfortunately it's not possible in pure dart (except if you want a hacky solution)

For the implementation, I'd recommend you use gstreamer and the level plugin to detect the noise level.

  • examples on how to use gstreamer in native code is already in src/plugins/gstreamer_video_player/player.c
  • the level plugin also has some examples: https://gstreamer.freedesktop.org/documentation/level/index.html?gi-language=c#level
  • some flutter-pi plugin examples are here: https://github.com/ardera/flutter-pi/blob/feature/camera-plugin/src/plugins/camera/plugin.c

As a proof of concept, this here will log the noise level of some auto-detected microphone to console (look at the message: RMS ...dB logs):

GST_DEBUG=level:7 gst-launch-1.0 autoaudiosrc ! audioconvert ! level post-messages=true ! fakesink sync=true

If you want a really really hacky solution you can just run that with normal dart Process.start and use regexes to extract the noise level from the process output.

ardera avatar Jul 21 '23 11:07 ardera