Maverick
Maverick

Reputation: 3259

iOS Force Audio Output only to headset jack

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?

Upvotes: 2

Views: 2826

Answers (2)

Maverick
Maverick

Reputation: 3259

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")
}

Upvotes: 1

hotpaw2
hotpaw2

Reputation: 70673

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.

Upvotes: 1

Related Questions