flutter_audio_recorder 0.5.5

flutter_audio_recorder #

pub version Awesome Flutter

English | 简体中文

Flutter Audio Record Plugin that supports Record Pause Resume Stop and provide access to audio level metering properties average power peak power

Works for both Android and iOS

Code Samples: #

Installation #

add flutter_audio_recorder to your pubspec.yaml

iOS Permission #

  1. Add usage description to plist
<key>NSMicrophoneUsageDescription</key>
<string>Can We Use Your Microphone Please</string>
  1. Then use hasPermission api to ask user for permission when needed

Android Permission #

  1. Add uses-permission to ./android/app/src/main/AndroidManifest.xml in xml root level like below
    ...
    </application>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    ...
</manifest>
  1. Then use hasPermission api to ask user for permission when needed

Configuration #

iOS Deployment Target is 8.0 above #

Android #

  • AndroidX: use latest version (0.5.x)
  • Legacy Android: use old version (0.4.9)

Usage #

Recommended API Usage: hasPermission => init > start -> (pause <-> resume) * n -> stop, call init again before start another recording

Always check permission first(it will request permission if permission has not been set to true/false yet, otherwise it will return the result of recording permission) #

bool hasPermission = await FlutterAudioRecorder.hasPermissions;

Initialize (run this before start, so we could check if file with given name already exists)

var recorder = FlutterAudioRecorder("file_path.mp4"); // .wav .aac .m4a
await recorder.initialized;

or

var recorder = FlutterAudioRecorder("file_path", audioFormat: AudioFormat.AAC); // or AudioFormat.WAV
await recorder.initialized;
Sample Rate #
var recorder = FlutterAudioRecorder("file_path", audioFormat: AudioFormat.AAC, sampleRate: 22000); // sampleRate is 16000 by default
await recorder.initialized;
Audio Extension and Format Mapping #
Audio FormatAudio Extension List
AAC.m4a .aac .mp4
WAV.wav

Start recording #

await recorder.start();
var recording = await recorder.current(channel: 0);

Get recording details #

var current = await recording.current(channel: 0);
// print(current.status);

You could use a timer to access details every 50ms(simply cancel the timer when recording is done)

new Timer.periodic(tick, (Timer t) async {
        var current = await recording.current(channel: 0);
        // print(current.status);
        setState(() {
        });
      });
Recording #
NameDescription
pathString
extensionString
durationDuration
audioFormatAudioFormat
meteringAudioMetering
statusRecordingStatus
Recording.metering #
NameDescription
peakPowerdouble
averagePowerdouble
isMeteringEnabledbool
Recording.status #

Unset,Initialized,Recording,Paused,Stopped

Pause #

await recorder.pause();

Resume #

await recorder.resume();

Stop (after stop, run init again to create another recording)

var result = await recorder.stop();
File file = widget.localFileSystem.file(result.path);

Example #

Please check example app using Xcode.

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

0.5.5 #

migrate to Android X.

0.5.4 #

  • Remove default result call on permission call back for Android

0.5.3 #

  • Fix Android sample rate issue
  • Fix Stop API
  • Fix metering API for Android and iOS

0.5.2 #

  • Explicitly asking for WRITE_EXTERNAL_STORAGE permission as it's required in Android
  • Updated documentation for Android Permission Section
  • Add null check for temp file deletion

0.5.1 #

  • Fix Android duration API
  • Complete plugin public API doc

0.5.0 #

  • Support AndroidX
  • Update documentation

0.4.9 #

  • Fixed minor issues for Android

0.4.8 #

  • Fix version number in .podspec

0.4.7 #

  • Remove extra pkg from lib
  • Update example app

0.4.6 #

  • Add swift version compiler code

0.4.5 #

  • Update documentation of usage
  • Specify Swift version in podspec

0.4.4 #

  • fix another issue of iOS hasPermission;

0.4.3 #

  • fix iOS hasPermission result issue;

0.4.2 #

  • fix the Android's audio file path, now you can get it from current method

0.4.1 #

  • Change Android dependencies version

0.4.0 #

  • Supports Android

0.3.0 #

  • Support Sample Rate.

0.2.2 #

  • Correct iOS deployment target to 8.0.

0.2.1 #

  • Simplify usage example for initialize recorder.

0.2.0 #

  • Fix issue of init method.
  • Fix issue of wav format recording initialization.
  • audioFormat of FlutterAudioRecorder now is optional when instantiating.
  • Overwrite file extension when there is conflicts between extension and audioFormat.
  • Update Example app.
  • Update README.

0.1.3 #

  • Fix README.md errors.

0.1.2 #

  • Updated package description.

0.1.1 #

  • Chinese documentation added.

0.1.0 #

  • Documentation added.

0.0.1 #

  • Initial release.

example/README.md

flutter_audio_recorder_example #

Demonstrates how to use the flutter_audio_recorder plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_audio_recorder: ^0.5.5

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

We analyzed this package on Feb 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
file ^5.0.4 5.1.0
flutter 0.0.0
path ^1.5.1 1.6.4
Transitive dependencies
collection 1.14.11 1.14.12
intl 0.16.1
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test