mic_stream icon indicating copy to clipboard operation
mic_stream copied to clipboard

MicStream.sampleRate seems never completes

Open westlinkin opened this issue 1 year ago • 9 comments

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

westlinkin avatar Nov 20 '23 14:11 westlinkin

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

anarchuser avatar Nov 20 '23 14:11 anarchuser

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.

westlinkin avatar Nov 21 '23 00:11 westlinkin

 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 avatar Nov 21 '23 05:11 anarchuser

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

anarchuser avatar Nov 21 '23 05:11 anarchuser

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

timmolter avatar Jan 12 '24 12:01 timmolter

@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 avatar Feb 20 '24 02:02 westlinkin

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.

westlinkin avatar Feb 20 '24 02:02 westlinkin

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

anarchuser avatar Feb 20 '24 06:02 anarchuser

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

anarchuser avatar Feb 20 '24 06:02 anarchuser