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

MicStream.sampleRate seems never completes #88

Open westlinkin opened 9 months ago

westlinkin commented 9 months ago

double? sampleRate = await MicStream.sampleRate; works fine in 0.6.5

but in 0.7.1+2, use int sampleRate = await MicStream.sampleRate never completes. Is there something I am missing? the same code upgraded from 0.6.5 to 0.7.1+2

anarchuser commented 9 months ago

Does the await complete once you start listening to the stream?

westlinkin commented 9 months ago

Does the await complete once you start listening to the stream?

I get the sampleRate after creating the stream. I was not tested after listening.

But I have to get the sample rate beforehand, to connect wss server (as a parameter). I read somewhere in the document, even if i set the sample rate, the iOS platform may not obey the configuration i set, so i have to get it after creating the stream and before listening.

I will try it later though, and get back to you.

anarchuser commented 9 months ago

 even if i set the sample rate, the iOS platform may not obey the configuration i set

This is correct and the main issue. There is no good semantic to resolve this. Either you assert that your preferred sample rate will be the actually used one, then you can send the sample rate you're configuring the stream with to your server. Or you send whatever the platform tells you is correct, requiring at least one set of samples to have been recorded.

I'm still looking for ways to improve this situation but I cannot circumvent platform limitations. You will have to adjust your server semantics, or not support iOS for the time being. Or you start recording before connecting to the server.

anarchuser commented 9 months ago

also have a look at #72 for a previous discussion the topic

timmolter commented 7 months ago

@westlinkin How are you piping the audio to a WS server? I'm trying to accomplish the same thing.

westlinkin commented 6 months ago

@westlinkin How are you piping the audio to a WS server? I'm trying to accomplish the same thing.

Sorry for the late reply. You can just listen to the stream, and _channel.sink.add(uint8List);, _channel is the websocket channel, uint8List is the onData call of the StreamSubscription.

westlinkin commented 6 months ago

even if i set the sample rate, the iOS platform may not obey the configuration i set

This is correct and the main issue. There is no good semantic to resolve this. Either you assert that your preferred sample rate will be the actually used one, then you can send the sample rate you're configuring the stream with to your server. Or you send whatever the platform tells you is correct, requiring at least one set of samples to have been recorded.

I'm still looking for ways to improve this situation but I cannot circumvent platform limitations. You will have to adjust your server semantics, or not support iOS for the time being. Or you start recording before connecting to the server.

Even after I start listening to the stream, the await MicStream.sampleRate did not complete. version 0.6.5, on my iPad (ios 17.2.0) and macOS, it works fine. on ios simulator( ios 17.0.1), it brokes. but vesion 0.7.1+2, it brokes even on macOS.

anarchuser commented 6 months ago

oh alright. If the problem occurs on an iOS emulator, this is a duplicate of #27

anarchuser commented 6 months ago

I'll give it another look to see what changes could have resulted in a different behaviour for macOS