Closed Uuttssaavv closed 11 months ago
Cancelling the stream subscription should suffice. On my android 13 device the "mic currently recording" notifier definitely disappears a short time after cancelling the stream (one second, max). Please tell me
Alternatively you can also try to build my example app and see how starting/stopping the stream there affects your mic notifier.
I am using the plugin version mic_stream: ^0.7.1
I am providing the sample
if (!state.isMicOn) {
stream = await MicStream.microphone(
audioSource: AudioSource.MIC,
sampleRate: 16000,
channelConfig: ChannelConfig.CHANNEL_IN_MONO,
audioFormat: AudioFormat.ENCODING_PCM_16BIT,
);
listener = stream?.listen(print);
} else {
listener?.cancel();
}
And you can confirm that the prints definitely start and stop, accordingly, and the mic notifier doesn't disappear even after 2-3 seconds?
Yes, print stops but the mic notifier does not disappear.
Is there a reason for the await
? It's hard to tell without context but I think you should be able to simply omit it
Yes, because microphone returns the Future<Stream>
The return type was changed in 0.7.0
to just Stream<Uint8list>
. The future got merged into the stream and the nullability was changed to emit an error instead.
It seems you didn't update your project yet to reflect the new version, so please run flutter pub upgrade
, remove the await
and try again.
I updated the version and tested it. It's working now. But still it would be better if there would be a proper way to turn off the microphone :)
What do you mean with a proper way?
This plugin is modelled after the official sensors
plugin. A microphone is just another sensor. Dart's asynchronous framework lays the foundation to fit something as complex as audio recording into something as simple as a single stream.
If you do have ideas to improve the API feel free to make suggestions in the form of Issues or Pull Requests and we may find common ground.
When I cancel the stream subscription, the mic is still on(shown by android platform). What is the proper way to turn off the microphone after we complete listening to the audio?