microphone: ^0.1.0 copied to clipboard
Plugin (web-only at this time) for recording audio through the microphone. This is an audio recorder plugin.
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;
Additionally, you can retrieve the recorded bytes from a recorder (after the recording has been stopped and while the recorder has not yet been disposed).
import 'package:microphone/microphone.dart'; // ... // Retrieves the recorded bytes. final bytes = await microphoneRecorder.toBytes();
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.
Learn more #
If you want to learn more about how this plugin works, how to contribute, etc., you can read through the main README on GitHub.