AVAudioSession .defaultToSpeaker changes mic input

后端 未结 1 516
轻奢々
轻奢々 2020-12-06 13:04

I have an app taps the microphone and also play sounds depending on mic input(don\'t have to be simultaneously tho) This code below works. But one problem is the output play

相关标签:
1条回答
  • 2020-12-06 13:31

    Thanks to everyone who took the time to comment. I learned new things from each comment. Seems like I found a solution. Which is actually very simple. When AVAudioSession category is .defaultToSpeaker (Or overrideOutputAudioPort) apparently the tap input buffer framelength changes to 4800 from 4410.

    This strangely happens regardless of which microphone is used. So using

    AVAudioSession.sharedInstance().setInputDataSource(datasource);
    

    Does not help.

    This difference seems to cause problems later in my code. So mic was actually working, but later in code it was failing to do its job due to a different framelength.

    Solution/workaround was I basically hardcoded the framelength in the tap. Since I use a converter I don't expect this to be a problem. This means I can set ".defaultToSpeaker" And mic is still working as expected.

    capacity = 4410 (DUH!)

    Maybe there are different/better ways to approach this problem. So feel free to add your answer if so.

    0 讨论(0)
提交回复
热议问题