Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting audio output to phone speaker and mic input to headphones

Is it possible to redirect audio output to the phone speaker and still use the microphone headphone input?

If i redirect the audio route to the phone speaker instead of the headphones it also redirects the mic. This makes sense but I can't seem to just be able to just redirect the mic input? Any ideas?

Here is the code I'm using to redirect audio to the speaker:

UInt32 doChangeDefaultRoute = true;        
propertySetError = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof(doChangeDefaultRoute), &doChangeDefaultRoute);
NSAssert(propertySetError == 0, @"Failed to set audio session property: OverrideCategoryDefaultToSpeaker");
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
like image 441
user744412 Avatar asked May 09 '11 02:05

user744412


People also ask

How do I use my phone speaker and headset at the same time?

Android users need to go to Bluetooth Settings and pair either Bluetooth headphones or speakers one by one. Once connected, tap the three-dot icon on the right and click on Advanced Settings. Toggle on the 'dual audio' option if not already turned on. This should enable users to connect to two devices at once.

How do I split audio between headphones and speakers?

Use an audio splitter or Bluetooth adapter A splitter offers a plug-and-play solution. Simply plug the splitter into your PC and plug the headphones into one port and the speakers into another.

How can you use earphones as both input and output of audio?

Right click Volume icon in System Tray at right end of task bar, Open Sounds Settings, in dropdown menus at top make sure Headphones are selected and Connected for both Playback and Recording Default Devices.

How do I change my microphone input to headphones?

Open Settings & Click on the “System” section and select the “Sound” section. Under the “Input” section, select “Choose your input device”, and then select the microphone or recording device you want to use.


1 Answers

This is possible, but it's picky about how you set it up.

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);

It's very important to use AVAudioSessionCategoryPlayAndRecord or the route will fail to go to the speaker. Once you've set the override route for the audio session, you can use an AVAudioPlayer instance and send some output to the speaker.

Hope that works for others like it did for me. The documentation on this is scattered, but the Skype app proves it's possible. Persevere, my friends! :)

Some Apple documentation here: http://developer.apple.com/library/ios/#documentation/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html

Do a search on the page for kAudioSessionProperty_OverrideAudioRoute

like image 191
jocull Avatar answered Sep 19 '22 18:09

jocull