noise_meter 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 75

noise_meter #

pub package

Install #

Add noise_meter as a dependency in pubspec.yaml. For help on adding as a dependency, view the documentation.

On Android you need to add a permission to AndroidManifest.xml:

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

On iOS enable the following:

  • Capabilities > Background Modes > Audio, AirPlay and Picture in Picture
  • In the Runner Xcode project edit the Info.plist file. Add an entry for 'Privacy - Microphone Usage Description'

Usage #

Initalization #

Keep these three variables accessible:

bool _isRecording = false;
StreamSubscription<NoiseReading> _noiseSubscription;
NoiseMeter _noiseMeter;

Start listening #

The easiest thing to do is to create a new instance of the NoiseMeter every time a new recording is started.

void startRecorder() async {
  try {
    _noiseMeter = new NoiseMeter();
    _noiseSubscription = _noiseMeter.noiseStream.listen(onData);
  } on NoiseMeterException catch (exception) {

On data #

When data comes in through the stream, it will be caught by the onData method, specified when the subscription was created. The incoming data points are of type NoiseReading which have a single field with a getter, namely the db value of type double.

void onData(NoiseReading noiseReading) {
  this.setState(() {
    if (!this._isRecording) {
      this._isRecording = true;
  /// Do someting with the noiseReading object

Stop listening #

To stop listening, the .cancel() method is called on the subscription object.

void stopRecorder() async {
  try {
    if (_noiseSubscription != null) {
      _noiseSubscription = null;
    this.setState(() {
      this._isRecording = false;
  } catch (err) {
    print('stopRecorder error: $err');

Technical documentation #

Sample rate #

The sample rate for both native implementations is 44,100.

Microphone data #

The native implementations record PCM data using the microphone of the device, and uses an audio buffer array to store the incoming data. When the buffer is filled, the contents are emitted to the Flutter side. The incoming floating point values are between -1 and 1 which is the PCM values divided by the max amplitude value which is 2^15.

Conversion to Decibel #

Firstly an average of the absolute value of the two highest peaks (usually a negative and a positive peak) is computed in order to reduce the window of data into a the maximum amplitude

avg = 0.5*abs(min) + 0.5*abs(max)

Thereafter computing the decibel value is performed as follows:

db = 20 * log10(2**15 * avg)

0.1.1 #

  • fix of issue #22 (UIThread exception in Android)

0.1.0 #

  • Initial release.


noise_meter_example #

Demonstrates how to use the noise_meter plugin.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  noise_meter: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:noise_meter/noise_meter.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Oct 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/noise_meter.dart. (-1 points)

Analysis of lib/noise_meter.dart reported 2 hints:

line 19 col 1: Prefer using /// for doc comments.

line 52 col 1: Prefer using /// for doc comments.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8