简体   繁体   中英

Possible to record audio through microphone jack, play separate sound through speaker on iPad?

I have a device similar to the Square reader that plugs in to the audio jack of an iPad and feeds in very simple data. I'm using Novocaine to read the raw data, but I'm having a problem playing audio through the speaker simultaneously.

Is it possible to record input from the headphone jack while playing sound through the speaker? If I set kAudioSessionProperty_OverrideAudioRoute to kAudioSessionOverrideAudioRoute_Speaker , the route for the input is changed as well. From what I can tell, it's not possible to set the input and output routes independently.

Is it possible to drop down a level and use Remote IO units to accomplish this? Is there any higher-level API I can use? Does anyone have an example of this?

I was looking to do this for an app of mine and was unable to find a way to do it, and I'm working at the lowest level, with Core Audio units, specifically Remote IO units.

The relevant method would be overrideOutputAudioPort:. From the docs :

overrideOutputAudioPort:error: Temporarily changes the current audio route.

  • (BOOL)overrideOutputAudioPort:(AVAudioSessionPortOverride)portOverride error:(NSError **)outError Parameters portOverride The override option for output. For a list of constants, see “AVAudioSessionPortOverride”. outError On input, a pointer to an error object. If an error occurs, the pointer is set to an NSError object that describes the error. If you do not want error information, pass in nil. Return Value YES if the new routing option was set successfully, or NO if it was not.

Discussion Calling this method with the AVAudioSessionPortOverrideSpeaker option and the audio session's category is AVAudioSessionCategoryPlayAndRecord causes audio to use the built-in speaker and microphone regardless of other settings. This change will only be in effect until the current route changes or you call this method again with the AVAudioSessionPortOverrideNone option.

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