views:

11

answers:

0

Hey guys, I have a bit of an interesting problem and I'm not sure how to go about solving it. I need to take the audio from a connected bluetooth headset and pipe it directly to the speaker on the iPhone's device and vice-versa. Accessing the Bluetooth audio session is easy enough:

// Use a Play and Record Category, because we'll be both recording audio and playing back audio
NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error: &setCategoryError];

// Error handling, just logs for now
if (setCategoryError) {
    NSLog(@"Category Error: %@", setCategoryError);
}

// Configure the session to use the bluetooth system instead of the built-in mic
UInt32 allowBluetoothInput = 1;
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,sizeof (allowBluetoothInput), &allowBluetoothInput);

// Activate the configured session (must be done after category and any config items are set)
NSError *activationError = nil;
[[AVAudioSession sharedInstance] setActive:YES error:&activationError];

// Error handling, just logs for now
if(activationError){
    NSLog(@"Activation Error: %@", activationError);
}

But once this session takes over I can no longer send audio to the built-in speaker. Is there a way to do what I need? Also, I'm used to recording audio and saving it to disk. How might I take that audio and send it directly to the speaker without writing it to a file first?

Thanks!