You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS录制时能否选择底部左右内置麦克风?AVAudioSession API疑问

Can we use Left/Right orientation to record with individual bottom microphones on iPhone 6s+?

Great question! Let’s break this down clearly for you:

Short Answer

You cannot directly use AVAudioSessionOrientationLeft or AVAudioSessionOrientationRight to select a single bottom microphone on iPhone 6s and later models with dual bottom mics. Those orientation enums serve a completely different purpose than individual mic selection.

Why Those Enums Don’t Work for This

  • The AVAudioSessionOrientation* values are tied to the physical orientation of the device (e.g., when you rotate your iPhone to landscape left/right), not to picking specific microphones. Their job is to align audio input/output with the device’s current orientation, not to target individual mics.
  • Apple treats the two bottom mics as a single "Bottom" audio source group. There’s no official API to target just the left or right bottom mic directly via session orientation settings.

How to Record with a Single Bottom Mic (Workaround)

If you need to capture audio from only one of the two bottom mics, you’ll need to work with the stereo audio input they produce and isolate a single channel. Here’s how you can approach it:

  1. Identify the bottom microphone device
    Use AVCaptureDevice to find the built-in bottom microphone (you can filter by name or position, though position may be .unspecified for bottom mics).
  2. Access the stereo audio channels
    The bottom mics output a 2-channel stereo signal, where each channel corresponds to one of the two mics.
  3. Isolate the desired channel
    During recording (via AVCaptureAudioDataOutput or AVAudioEngine), process the audio samples to keep only the left or right channel.

Here’s a quick Swift code snippet to get you started:

// Discover all built-in microphones
let micDiscoverySession = AVCaptureDevice.DiscoverySession(
    deviceTypes: [.builtInMicrophone],
    mediaType: .audio,
    position: .unspecified
)

// Locate the bottom microphone (adjust the filter based on your device's mic naming)
if let bottomMic = micDiscoverySession.devices.first(where: {
    $0.localizedName.lowercased().contains("bottom")
}) {
    do {
        try bottomMic.lockForConfiguration()
        print("Bottom mic supports \(bottomMic.activeFormat.channelCount) channels")
        bottomMic.unlockForConfiguration()
        
        // Set up capture session to receive audio data
        let captureSession = AVCaptureSession()
        let audioInput = try AVCaptureDeviceInput(device: bottomMic)
        if captureSession.canAddInput(audioInput) {
            captureSession.addInput(audioInput)
        }
        
        let audioOutput = AVCaptureAudioDataOutput()
        audioOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "audioQueue"))
        if captureSession.canAddOutput(audioOutput) {
            captureSession.addOutput(audioOutput)
        }
        
        captureSession.startRunning()
    } catch {
        print("Error configuring microphone: \(error.localizedDescription)")
    }
}

// In your AVCaptureAudioDataOutputSampleBufferDelegate implementation:
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
    // Convert sample buffer to audio data, then extract left/right channel
    // For example, use AudioBufferList to access individual channels
}

Key Note

Even though AVAudioSessionOrientationLeft and AVAudioSessionOrientationRight haven’t been deprecated, they’re not designed for this use case. Apple’s API design prioritizes treating dual bottom mics as a stereo pair, so channel isolation is the supported way to get audio from a single one.

内容的提问来源于stack exchange,提问作者Forte Zhu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:57:25