mic_stream
mic_stream copied to clipboard
Ignoring the given bitrate on ios
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
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
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)
@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
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.
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.