Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignoring the given bitrate on ios #72

Open
rootux opened this issue Jul 10, 2023 · 5 comments
Open

Ignoring the given bitrate on ios #72

rootux opened this issue Jul 10, 2023 · 5 comments

Comments

@rootux
Copy link

rootux commented Jul 10, 2023

for the following code -

Stream<Uint8List>? stream = await MicStream.microphone(
    sampleRate: 16000,
    channelConfig: ChannelConfig.CHANNEL_IN_MONO,
    audioFormat:AudioFormat.ENCODING_PCM_16BIT
);

final sampleRate = await MicStream.sampleRate;
final bitDepth = await MicStream.bitDepth;
final bufferSize = await MicStream.bufferSize;
logger.i(
  'Microphone settings: sampleRate = $sampleRate, bitDepth = $bitDepth, bufferSize = $bufferSize',
);

I get back this -

flutter: Microphone settings: sampleRate = 48000.0, bitDepth = 16, bufferSize = 1024

Hence the library is ignoring the settings.
I know @anarchuser you did not write that part :)
Trying to figure out a solution

@anarchuser
Copy link
Owner

anarchuser commented Jul 10, 2023

Yeah, I remember there were issues regarding iOS settings/sample rate. You can try out some of the older versions, I think the recording API used in the iOS backend changed in-between

@rootux
Copy link
Author

rootux commented Jul 10, 2023

There is this comment in the code that may be related -
https://github.com/anarchuser/mic_stream/blob/main/ios/Classes/SwiftMicStreamPlugin.swift#L148

// neither does setting AVLinearPCMBitDepthKey on audioOutput.audioSettings (unavailable on iOS)
// 99% sure it's not possible to set streaming sample rate/bitrate
// try AVAudioSession.sharedInstance().setPreferredOutputNumberOfChannels(numChannels)

@rootux
Copy link
Author

rootux commented Jul 10, 2023

@anarchuser Not sure what do you mean.
Can you please elaborate?

I see some change in the area here - https://github.com/anarchuser/mic_stream/pull/61/files#diff-92b5a8c491b845cd6d9e20f37fe82c7d10f0410693426936cb7515f4dd23007eR118

@anarchuser
Copy link
Owner

It will take me some time to look into it. If you want please give it a look yourself. I think it shouldn't be difficult; I just cannot test it myself.

@DurandA
Copy link

DurandA commented Oct 8, 2023

On iOS, setPreferredSampleRate() is used and there is no guarantee that it will be applied. In fact, it is ignored on most devices and the actual sampling rate is device dependent.

If you require a specific sampling rate for your application, you have to resample the audio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants