mic_stream icon indicating copy to clipboard operation
mic_stream copied to clipboard

Ignoring the given bitrate on ios

Open rootux opened this issue 1 year ago • 5 comments

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

rootux avatar Jul 10 '23 06:07 rootux

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

anarchuser avatar Jul 10 '23 06:07 anarchuser

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 avatar Jul 10 '23 06:07 rootux

@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

rootux avatar Jul 10 '23 06:07 rootux

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.

anarchuser avatar Jul 10 '23 07:07 anarchuser

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.

DurandA avatar Oct 08 '23 23:10 DurandA