简体   繁体   中英

AVAudioEngine Input Mic Tap influences Music PlayerNode - SWIFT

I am creating an app that lets the user talk into the microphone while music is playing (similar to Karaoke). I have managed to get this working using the AudioEngine with multiple inputs going into the mixer. However, when the mic is enabled, the sound quality of the music is also lost. It almost sounds like the music is being payed through the microphone. I figure this is due to the mic and music having different AVAudioFormats, but I cannot find a format that works for the mic other than:

var format = AVAudioFormat(commonFormat: AVAudioCommonFormat.PCMFormatFloat32, sampleRate: 8000.0, channels:AVAudioChannelCount(2), interleaved: false)

where my music output format is simply

mixer.outputFormatForBus(0)

which sounds clear when the mic is disabled.

it is worth noting I am also using the AvAudioSessionCategory:

session.setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions:AVAudioSessionCategoryOptions.AllowBluetooth, error: nil)

I have run out of ideas as to what I am doing wrong. Any help is greatly appreciated!

Need to see more of your code, mainly how you have setup your input and output in AVAudioSession.

Don't know from your description what your input or output setup is. For iPhone you have 3 input mics (front, back & bottom) and 2 outputs (receiver (ear) & speaker (bottom)). If you have input set to bottom mic, then very likely the output is set to receiver which is meant to be held to ear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM