anarchuser / mic_stream

Flutter plugin to get an infinite audio stream from the microphone
https://pub.dev/packages/mic_stream
GNU General Public License v3.0
100 stars 68 forks source link

[Suggestion] MicStream.microphone() should return a Stream<Uint8List> #64

Closed mirland closed 1 year ago

mirland commented 1 year ago

Hi, thanks for the plugin, I have a API suggestion

Right now MicStream.microphone() returns a Future<Stream<Uint8List>?>. However, it's strange and also I think it's not needed to return a Future, it should return just a Stream<Uint8List> (not nullable)

anarchuser commented 1 year ago

Thank you for your suggestion. It used to return just a Stream<Uint8List>, and this was obviously the cleaner interface.

Setting up the internal stream initially may take some time though. And thus, in order to allow seamless integration into asynchronous applications, a Future is returned instead. In fact, in order to apply your suggestions, all I'd do is block the function call until the Future resolves - which goes against the concept of asynchronous programming entirely.

In case your only interested in android applications: you can use an older version which still uses the old interface. The Future is a result of iOS and MacOS support integration.

mirland commented 1 year ago

But you can combine streams, so I'd use a Stream.fromFuture(permissionStatus) and then I'd combine the mic stream with a asyncExpand.

Let me submit a pr, we can discuss the implementation

anarchuser commented 1 year ago

preliminary implementation published as 0.7.0-dev