Flutter Audio Recorder Plugin Integration Example

You are currently viewing Flutter Audio Recorder Plugin Integration Example
Flutter Audio Recorder

Flutter Audio Recorder

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

Flutter Audio Recorder
Flutter Audio Recorder

Code Samples:

Installation


addย flutter_audio_recorderย to yourย pubspec.yaml

iOS Permission


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

Android Permission


  • 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"/>
...
  • Then useย hasPermissionย api to ask user for permission when needed
See also  Dynamic ListView Example in Flutter

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

See also  Flutter Sound Recorder and Player Example
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);

Credit

This project is developed byย rmbrone
Download this project from the below link.
https://github.com/rmbrone/flutter_audio_recorder/archive/refs/heads/master.zip
You can visit original source page from the below link:
https://github.com/rmbrone/flutter_audio_recorder

See also  E-commerce App Example With Flutter GetX

Spread the love

Leave a Reply