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

Recording does not start using the iOS 16.1 emulator #51

Closed DurandA closed 1 year ago

DurandA commented 1 year ago

Hello and thank you for this great plugin.

I tried porting my Android app that uses mic_stream 0.6.2 to iOS. As the recording didn't work, I tried the example app. The recording doesn't start and the app never asks for permission to use the microphone. The key NSMicrophoneUsageDescription is present in Info.plist and there are no error messages.

I modified the Podfile as described by the permission_handler documentation to fix the permission request.

The debug console output the following:

START LISTENING
wait for stream

However, the following awaits never complete: https://github.com/anarchuser/mic_stream/blob/61a5c35d0842e6be6b59e7ee80e6fc20135a3a8b/example/lib/main.dart#L104

Even if I disable these awaits, I do not receive any sample when listening to the stream.

I tried updating mic_stream to 0.6.3-dev which doesn't solve the issue. I use the iPhone 14 (iOS 16.1) simulator and XCode 14.1 (14B47b). I am not familiar with the Apple/iOS ecosystem and didn't found a similar existing issue here. Maybe there was a breaking change in the latest iOS version?

anarchuser commented 1 year ago

Thank you for your detailed report. This is a known issue (see #27), so it's probably unrelated to the iOS version. Like you, I am also not familiar with the Apple ecosystem; both the iOS and MacOS backends were added as Pull Requests from volunteers. Thus, I'm sorry but I cannot help you.

DurandA commented 1 year ago

Thanks, I can confirm that this is a Simulator-only issue. I will close the issue then.

Btw, are you aware of any existing audio downsampling solution? I just noticed that only 44.1 kHz is guaranteed to be available on iOS. I might need to do some native iOS dev for this. :grimacing:

Thank you again for this great library.

anarchuser commented 1 year ago

Regarding downsampling: The simplest option is to just drop every nth to get a new sample rate (n-1)/n times the old one. This obviously loses 1/n times the data and this resampling means you'll have sampling biases twice. A slightly more sophisticated variant is to interpolate your data first (upsampling), and then drop samples at regular intervals; this way you don't lose whole samples but fractions of every sample instead. This also allows you to get arbitrary fractions of the original sample rate. Interpolation also reinforces sampling bias, though.

If you want to improve the iOS backend, feel free to do so and open a PR if you've got a more flexible solution working.