flutter audio recorder
flutter #1 audio recorder & storer. record audio and store it locally.
usage
to use audio recorder 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
<key>nsmicrophoneusagedescription</key>
<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 uses 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
Comments are closed.