flutter-pi
flutter-pi copied to clipboard
Get sound decibel of microphone
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.
@ardera can you please suggest me a solution?
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.