noise_meter 0.1.0

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" />

Usage #

Initalization #

Noise data will be streamed, and for this a few objects need to be initialized, such as a boolean representing the recording state, a stream and a NoiseMeter object.

bool _isRecording = false;
StreamSubscription<NoiseEvent> _noiseSubscription;
Noise _noise;

Furthermore, handling incoming events in a seperate method is also a good idea:

void onData(NoiseEvent e) {
    print("${e.decibel} dB");
}

Where frequency is the update rate in milliseconds of type int, this means the lower the update rate, the more frequently events will come in.

Start listening #

void startRecorder() async {
    try {
      _noise = new Noise(500); // New observation every 500 ms
      _noiseSubscription = _noise.noiseStream.listen(onData);
    } on NoiseMeterException catch (exception) {
      print(exception);
    }
}

Where onData() handles the events from StreamSubscription. An example could be:

void onData(NoiseEvent event) {
  print("noise level is ${event.decibel} decibel.");
}

Each incoming NoiseEvent has an integer field named decibel containing the noise level of the reading.

Stop listening #

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

0.0.1 #

  • TODO: Describe initial release.

example/README.md

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:


dependencies:
  noise_meter: ^0.1.0

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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
50
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
75
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3

Platforms

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 18 col 1: Prefer using /// for doc comments.

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8

Admin