iOS Force Audio Output only to headset jack

2.7k views Asked by At

I want to direct iOS VoiceOver sound to headphone even if it's not plugged in.

In other words, while my app is open, VoiceOver sound (and other sounds played by me in app using AVSpeechUtterance etc.) should NEVER go to speakers, but should come out of headset, if connected.

Can anyone suggest something on this?

2

There are 2 answers

0
Maverick On BEST ANSWER

Apparently it's not possible to forcefully direct sound to headphone unless an accessory is plugged to headphone jack (which activates a physical switch to direct voice to headphone).

I've achieved my purpose using following code (in Swift) which directs VoiceOver and other sounds to phone speaker (from where we listen to phone calls) and silences loud speaker while my app is in foreground.

let session: AVAudioSession = AVAudioSession.sharedInstance()
do {
    try session.setCategory(AVAudioSessionCategoryPlayAndRecord)
    try session.overrideOutputAudioPort(AVAudioSessionPortOverride.None)
    try session.setActive(true)
} catch {
    print("Couldn't override output audio port")
}
1
hotpaw2 On

iOS devices will not power-up the headset jack for audio output unless a recognized (proper impedance, etc.) headset or headphone is currently plugged in to the jack.

VoiceOver audio will always go to the headset, if a valid one is plugged-in, and not over-ridden.