audio_recorder 0.0.5

  • Example
  • Installing
  • Versions
  • 79

Audio recorder #

pub package Record audio and store it locally

Usage #

To use this plugin, add audio_recorder as a dependency in your pubspec.yaml file.

Android #

Make sure you add the following permissions to your Android Manifest

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

iOS #

Make sure you add the following key to Info.plist for iOS

<string>Record audio for playback</string>

Example #

// Import package
import 'package:audio_recorder/audio_recorder.dart';

// Check permissions before starting
bool hasPermissions = await AudioRecorder.hasPermissions;

// Get the state of the recorder
bool isRecording = await AudioRecorder.isRecording;

// Start recording
await AudioRecorder.start(path: _controller.text, audioOutputFormat: AudioOutputFormat.AAC);

// Stop recording
Recording recording = await AudioRecorder.stop();
print("Path : ${recording.path},  Format : ${recording.audioOutputFormat},  Duration : ${recording.duration},  Extension : ${recording.extension},");

Encoding format #

For now, the plugin only use the AAC compression to encode audio. You can specify the extension of the output audio file in the file path that you give to the start method. The recognized extensions are :

  • .m4a
  • .mp4
  • .aac

If the file path does not finish with these extensions, the ".m4a" extension is added by default.

Exceptions #

The start method raise an exception if :

  • A file already exists at the given file path
  • The parent directory of the file path does not exist

Getting Started #

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

For help on editing plugin code, view the documentation.

[0.0.1] - Published Feb 8, 2018.

  • Record audio and store it locally

[0.0.2] - Published May 16, 2018.

  • Support Dart 2

[0.0.3] - Published June 11, 2018.

  • Update readme

[0.0.4] - Published June 11, 2018.

  • Added path of application directory to user's file name so that a valid file can be written in iOS.
  • Added diagnostic info to help user find the location of their recorded file.

[0.0.5] - Published August 16, 2018.

  • Fix readme with the right class name
  • Make Volume up when recording on iOS


import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:flutter/material.dart';
import 'dart:math';
import 'package:audio_recorder/audio_recorder.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  _MyAppState createState() => new _MyAppState();

class _MyAppState extends State<MyApp> {

  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Plugin audio recorder'),
        body: new AppBody(),

class AppBody extends StatefulWidget{

  State<StatefulWidget> createState() => new AppBodyState();

class AppBodyState extends State<AppBody>{
  Recording _recording = new Recording();
  bool _isRecording = false;
  Random random = new Random();
  TextEditingController _controller = new TextEditingController();

  Widget build(BuildContext context) {
    return new Center(
      child: new Padding(
        padding: new EdgeInsets.all(8.0),
        child: new Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: <Widget>[
              new FlatButton(onPressed: _isRecording ? null : _start, child: new Text("Start"), color:,),
              new FlatButton(onPressed: _isRecording ? _stop : null, child: new Text("Stop"), color:,),
              new TextField(controller: _controller, decoration: new InputDecoration(hintText: 'Enter a custom path',),),
              new Text("File path of the record: ${_recording.path}"),
              new Text("Format: ${_recording.audioOutputFormat}"),
              new Text("Extension : ${_recording.extension}"),
              new Text("Audio recording duration : ${_recording.duration.toString()}" )

  _start() async {
    try {
      if (await AudioRecorder.hasPermissions) {
        if (_controller.text != null && _controller.text != "") {
          String path = _controller.text;
          if (!_controller.text.contains('/')) {
            Directory appDocDirectory = await getApplicationDocumentsDirectory();
            path = appDocDirectory.path + '/' + _controller.text;
          print("Start recording: $path");
          await AudioRecorder.start(path: path, audioOutputFormat: AudioOutputFormat.AAC);
        } else {
          await AudioRecorder.start();
        bool isRecording = await AudioRecorder.isRecording;
        setState(() {
          _recording = new Recording(duration: new Duration(), path: "");
          _isRecording = isRecording;
      } else {
        Scaffold.of(context).showSnackBar(new SnackBar(content: new Text("You must accept permissions")));
    } catch (e){

  _stop() async {
    var recording = await AudioRecorder.stop();
    print("Stop recording: ${recording.path}");
    bool isRecording = await AudioRecorder.isRecording;
    File file = await new File(recording.path);
    print("  File length: ${await file.length()}");
    setState(() {
      _recording = recording;
      _isRecording = isRecording;
    _controller.text = recording.path;

Use this package as a library

1. Depend on it

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

  audio_recorder: ^0.0.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:audio_recorder/audio_recorder.dart';
Version Uploaded Documentation Archive
0.0.6 Sep 9, 2018 Go to the documentation of audio_recorder 0.0.6 Download audio_recorder 0.0.6 archive
0.0.5 Aug 16, 2018 Go to the documentation of audio_recorder 0.0.5 Download audio_recorder 0.0.5 archive
0.0.4 Jun 11, 2018 Go to the documentation of audio_recorder 0.0.4 Download audio_recorder 0.0.4 archive
0.0.3 Jun 11, 2018 Go to the documentation of audio_recorder 0.0.3 Download audio_recorder 0.0.3 archive
0.0.2 May 16, 2018 Go to the documentation of audio_recorder 0.0.2 Download audio_recorder 0.0.2 archive
0.0.1 Feb 8, 2018 Go to the documentation of audio_recorder 0.0.1 Download audio_recorder 0.0.1 archive
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 May 8, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.0
  • pana: 0.12.15
  • Flutter: 1.5.8


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Fix lib/audio_recorder.dart. (-25 points)

Analysis of lib/audio_recorder.dart failed with 1 error:

line 41 col 44: The constructor 'Map.from' does not have type parameters.

Document public APIs. (-1 points)

20 out of 20 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.40.0.flutter-f981f09760 <3.0.0
flutter 0.0.0
path ^1.5.1 1.6.2
path_provider ^0.4.1 0.4.1 1.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