Giter Site home page Giter Site logo

anselrain / flutter_audio_recorder Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fayeed/flutter_audio_recorder

0.0 1.0 1.0 7.58 MB

Flutter plugin that can support audio recording and level metering

License: MIT License

Java 30.44% Ruby 7.09% Swift 19.83% Objective-C 1.00% Dart 40.06% Shell 1.25% Kotlin 0.33%

flutter_audio_recorder's Introduction

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 Format Audio 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
Name Description
path String
extension String
duration Duration
audioFormat AudioFormat
metering AudioMetering
status RecordingStatus
Recording.metering
Name Description
peakPower double
averagePower double
isMeteringEnabled bool
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.

flutter_audio_recorder's People

Contributors

alanxyh avatar fayeed avatar nikli2009 avatar towerjoo avatar

Watchers

 avatar

Forkers

aliasgarlabs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.