Flutter (web-only at this moment) plugin for recording audio through the microphone.
To use this plugin, follow the installing guide.
Recording microphone audio
You need to create and initialize a
MicrophoneRecorder in order to record audio.
Note that a single recorder can only make a single recording. Simply create a new recorder if you want to make another recording. Further note that you can also record simultaneously.
import 'package:microphone/microphone.dart'; // ... // Create and initialize a recorder. final microphoneRecorder = MicrophoneRecorder()..init();
The initialization happens asynchronously, which means that you might need to
Now, you can start a recording.
import 'package:microphone/microphone.dart'; // ... // Start recording audio. microphoneRecorder.start();
Stopping it will give you access to a
MicrophoneRecording in the
import 'package:microphone/microphone.dart'; // ... // Stop the recording. await microphoneRecorder.stop(); final recordingUrl = microphoneRecorder.value.recording.url;
Do not forget to dispose the recorder:
import 'package:microphone/microphone.dart'; // ... // Dispose the recorder. microphoneRecorder.dispose();
Listening to state changes
MicrophoneRecorder is also a
ValueNotifier, which means that it can e.g. be used with a Flutter
or you can attach a listener using
MicrophoneRecorder.value.stopped changed, you will be notified. See the
example app for an example usage.
If you want to learn more about how this plugin works, how to contribute, etc., you can read through the main README on GitHub.