Forcing iPhone Microphone as Audio Input

后端 未结 5 1386
深忆病人
深忆病人 2020-12-03 08:16

I am developing an iOS application (targetted specifically for iPhone, at the moment) that requires the application to record audio only from iPhone internal microph

5条回答
  •  一个人的身影
    2020-12-03 08:55

    I believe the answer to this question to be 'no'. I used an iPhone 4 and the new-to-iOS 4 AVFoundation to experiment, focussing on the AVCaptureDevice class.

    I added the following to an application:

    NSLog(@"%@", [AVCaptureDevice devices]);
    

    So that asks that all devices that can be used for capturing audio and/or video be listed. Without the headphones plugged in, I get:

    (
        "Back Camera",
        "Front Camera",
        "iPhone Microphone" 
    )
    

    With the headphones plugged in I get:

    (
        "Back Camera",
        "Front Camera",
        Headphones
    )
    

    So the iPhone microphone drops off the list of available AVCaptureDevices as soon as the headphones become available. To probe this further, I added a quick bit of code to grab the AVCaptureDevice instance for the available audio device and to print its unique ID. For both the device identifying itself as "iPhone Microphone" and the device identifying itself as "Headphones", I got:

    com.apple.avfoundation.avcapturedevice.built-in_audio:0
    

    It would seem to me to be obvious that two devices can't have the same unique ID, so clearly it's the same device changing its state. Although AVCaptureDevices have a lot of stuff for setting state, it's limited to visual things like focus, exposure, flash and white balance.

提交回复
热议问题