Last updated:
0 purchases
microphone
microphone #
Flutter (web-only at this moment) plugin for recording audio through the microphone.
Usage #
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();
copied to clipboard
The initialization happens asynchronously, which means that you might need to await the init method.
Now, you can start a recording.
import 'package:microphone/microphone.dart';
// ...
// Start recording audio.
microphoneRecorder.start();
copied to clipboard
Stopping it will give you access to a MicrophoneRecording in the value property:
import 'package:microphone/microphone.dart';
// ...
// Stop the recording.
await microphoneRecorder.stop();
final recordingUrl = microphoneRecorder.value.recording.url;
copied to clipboard
The recording is accessible through a URL and can be played back using e.g. just_audio's "read from URL"
(requires adding a just_audio_web dependency as well; see the example app).
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();
copied to clipboard
Do not forget to dispose the recorder:
import 'package:microphone/microphone.dart';
// ...
// Dispose the recorder.
microphoneRecorder.dispose();
copied to clipboard
Listening to state changes #
MicrophoneRecorder is also a ValueNotifier, which means that it can e.g. be used with a Flutter ValueListenableBuilder
or you can attach a listener using MicrophoneRecorder.addListener.
Whenever MicrophoneRecorder.value.started or 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.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.