I've been able to connect AVAudioInputNode (which takes microphone input data) and connect it to the AVAudioEngine. I can hear the output from the (upper) speaker if I put my phone close enough to my ear. How can I route the audio output to the (bottom) speaker instead ? (Think of it as a loudspeaker..)
Asked
Active
Viewed 2,637 times
2 Answers
2
Get the sharedInstance
of your AVAudioSession
. Then call setCategory:withOptions:error
passing in the parameters below:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:Nil];

Nick
- 628
- 6
- 21
-
Hi Nick, thx for the reply. I've tried to setup the AudioSession, but I get gibberish environment noise from the (bottom) speaker and if I said something, there's no voice coming out from the speaker... – Jacky Coolheart Oct 14 '14 at 16:40
-
Then there's a problem elsewhere in your code. Post a new question specific to the 'gibberish' noise coming out of the lower speaker, post the relevant code and we can go from there. – Nick Oct 14 '14 at 21:10
-
Hi Nick, seems like you have had experience in audio related stuff. Can you take a look at my other related question ? Thx. http://stackoverflow.com/questions/26270127/ios8-avaudioengine-how-to-send-microphone-data-over-multipeer-connectivity – Jacky Coolheart Oct 17 '14 at 02:08
-
How do I send PCMBuffer over network ? I use MultiPeer to send, but I have no idea how to convert it back to AVAudioPCMBuffer in didReceiveData. Here's my sending code: `MCPeerID *remotePeerID = [self.sessionMC.connectedPeers objectAtIndex:0]; NSArray *peersArray = @[remotePeerID]; NSError *error = nil; NSData *data = [NSData dataWithBytes:buffer.floatChannelData length:buffer.frameLength]; [self.sessionMC sendData:data toPeers:peersArray withMode:MCSessionSendDataReliable error:&error]; if(error) {NSLog(@"error: %@", [error localizedDescription]);}` – Jacky Coolheart Oct 19 '14 at 16:07
1
Here is how I did it in swift
//In declarations
var audioSession:AVAudioSession = AVAudioSession.sharedInstance()
//In viewDidLoad
audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: AVAudioSessionCategoryOptions.DefaultToSpeaker, error: nil)

Horatio
- 1,695
- 1
- 18
- 27
-
Thank you! :) But I got `Ambiguous reference to member 'setCategory'`Error. For me it worked (Swift 2.2) by removing the error part: `try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: AVAudioSessionCategoryOptions.DefaultToSpeaker)` – Joey Sep 05 '16 at 21:59